|
| 1 | +--- |
| 2 | +id: tcp-routes |
| 3 | +title: TCP Routes |
| 4 | +sidebar_label: 06. TCP Routes |
| 5 | +sidebar_position: 6 |
| 6 | +--- |
| 7 | + |
| 8 | +# Secure TCP and SSH Connections |
| 9 | + |
| 10 | +Now that you’ve built several routes, you'll learn how to proxy TCP and SSH connections with Pomerium Zero. |
| 11 | + |
| 12 | +:::note **Before You Start** |
| 13 | + |
| 14 | +Make sure you’ve completed the following tutorials: |
| 15 | + |
| 16 | +- [**Build a Simple Route**](/docs/courses/zero-fundamentals/build-routes) |
| 17 | +- [**Build a Simple Policy**](/docs/courses/zero-fundamentals/build-policies) |
| 18 | +- [**Single Sign-on with JWTs**](/docs/courses/zero-fundamentals/single-sign-on) |
| 19 | +- [**Build Advanced Policies**](/docs/courses/zero-fundamentals/advanced-policies) |
| 20 | +- [**Build Advanced Routes**](/docs/courses/zero-fundamentals/advanced-routes) |
| 21 | + |
| 22 | +Each tutorial builds on the same configuration files. In this guide, you'll proxy TCP connections to a Redis database and a remote OpenSSH server. |
| 23 | + |
| 24 | +::: |
| 25 | + |
| 26 | +## Background |
| 27 | + |
| 28 | +When replacing a traditional VPN, there are often non-HTTP based applications you still need to reach. Pomerium can provide the same type of protection to these services with [Pomerium CLI](/docs/deploy/clients/pomerium-cli), a client-side application to proxy TCP connections. |
| 29 | + |
| 30 | +In this guide, you'll proxy TCP connections to a Redis database and an OpenSSH server. |
| 31 | + |
| 32 | +Pomerium’s CLI client comes with a `tcp` command that you can use to secure this connection. |
| 33 | + |
| 34 | +## Prerequisites |
| 35 | + |
| 36 | +To complete this guide, you need: |
| 37 | + |
| 38 | +- [Pomerium CLI](/docs/deploy/clients/pomerium-cli) to proxy TCP connections between end-users and services behind Pomerium |
| 39 | + |
| 40 | +:::note |
| 41 | + |
| 42 | +This guide assumes you've installed the Pomerium CLI client to your system. |
| 43 | + |
| 44 | +::: |
| 45 | + |
| 46 | +## Test Pomerium CLI installation |
| 47 | + |
| 48 | +Test the installation: |
| 49 | + |
| 50 | +```shell-session |
| 51 | +$ pomerium-cli |
| 52 | +Usage: |
| 53 | + pomerium-cli [command] |
| 54 | +
|
| 55 | +Available Commands: |
| 56 | + cache commands for working with the cache |
| 57 | + completion Generate the autocompletion script for the specified shell |
| 58 | + help Help about any command |
| 59 | + k8s commands for the kubernetes credential plugin |
| 60 | + tcp creates a TCP tunnel through Pomerium |
| 61 | + version version |
| 62 | +
|
| 63 | +Flags: |
| 64 | + -h, --help help for pomerium-cli |
| 65 | + -v, --version version for pomerium-cli |
| 66 | +
|
| 67 | +Use "pomerium-cli [command] --help" for more information about a command. |
| 68 | +``` |
| 69 | + |
| 70 | +## Add Redis and OpenSSH services |
| 71 | + |
| 72 | +Add the Redis and OpenSSH server configurations to your Docker Compose file: |
| 73 | + |
| 74 | +```yaml |
| 75 | + redis: |
| 76 | + image: redis:latest |
| 77 | + networks: |
| 78 | + main: {} |
| 79 | + expose: |
| 80 | + - 6379 |
| 81 | + |
| 82 | + myssh: |
| 83 | + image: linuxserver/openssh-server:latest |
| 84 | + networks: |
| 85 | + main: {} |
| 86 | + expose: |
| 87 | + - 2222 |
| 88 | + environment: |
| 89 | + PASSWORD_ACCESS: "true" |
| 90 | + USER_PASSWORD: supersecret |
| 91 | + USER_NAME: user |
| 92 | +``` |
| 93 | +
|
| 94 | +## Add routes in Pomerium Zero |
| 95 | +
|
| 96 | +Create a Redis route: |
| 97 | +
|
| 98 | +1. Create a new route for your Redis database |
| 99 | +1. In **From**, select **tcp+https://** in the protocol dropdown menu |
| 100 | +1. Enter your external route and append `:6379` to it |
| 101 | + 1. For example, `redis.super-hero-7645.pomerium.app:6379` |
| 102 | +1. In **To**, enter `tcp://redis:6379` |
| 103 | +1. In **Policies**, select `Any Authenticated User` |
| 104 | + |
| 105 | +  |
| 106 | + |
| 107 | +Create an OpenSSH route: |
| 108 | + |
| 109 | +1. Create a new route for the OpenSSH server |
| 110 | +1. In **From**, select **tcp+https://** in the protocol dropdown menu |
| 111 | +1. Enter your external route and append `:22` to it |
| 112 | + 1. For example, `myssh.super-hero-7645.pomerium.app:22` |
| 113 | +1. In **To**, enter `tcp://myssh:2222` |
| 114 | + |
| 115 | +  |
| 116 | + |
| 117 | +Save your changes and apply them. |
| 118 | + |
| 119 | +## Connect to Redis |
| 120 | + |
| 121 | +In a terminal, run the following command: |
| 122 | + |
| 123 | +```shell-session |
| 124 | +$ pomerium-cli tcp redis.<CLUSTER_SUBDOMAIN>.pomerium.app:6379 --listen localhost:6379 |
| 125 | +``` |
| 126 | + |
| 127 | +If set up correctly, Pomerium will open your browser to authenticate you. This will establish a TCP connection. |
| 128 | + |
| 129 | +In a separate terminal window, run the following `redis-cli` command: |
| 130 | + |
| 131 | +```bash |
| 132 | +$ redis-cli info |
| 133 | +# Server |
| 134 | +redis_version:7.0.5 |
| 135 | +redis_git_sha1:00000000 |
| 136 | +redis_git_dirty:0 |
| 137 | +redis_build_id:d9291579292e26e3 |
| 138 | +redis_mode:standalone |
| 139 | +os:Linux 6.3.13-linuxkit aarch64 |
| 140 | +arch_bits:64 |
| 141 | +monotonic_clock:POSIX clock_gettime |
| 142 | +multiplexing_api:epoll |
| 143 | +atomicvar_api:c11-builtin |
| 144 | +gcc_version:10.2.1 |
| 145 | +process_id:1 |
| 146 | +process_supervised:no |
| 147 | +run_id:bc1b8bcd39f1e51d615f5739158e6ae964f7e724 |
| 148 | +tcp_port:6379 |
| 149 | +server_time_usec:1713989553900448 |
| 150 | +uptime_in_seconds:64 |
| 151 | +uptime_in_days:0 |
| 152 | +hz:10 |
| 153 | +configured_hz:10 |
| 154 | +lru_clock:2713521 |
| 155 | +executable:/data/redis-server |
| 156 | +config_file: |
| 157 | +io_threads_active:0 |
| 158 | +``` |
| 159 | + |
| 160 | +We truncated the Redis response above for the sake of brevity, but it demonstrates that you successfully proxied a TCP connection to the Redis service. |
| 161 | + |
| 162 | +## Connect to SSH server |
| 163 | + |
| 164 | +In a terminal, run the following command: |
| 165 | + |
| 166 | +```shell-session |
| 167 | +$ pomerium-cli tcp myssh.<CLUSTER_SUBDOMAIN>.pomerium.app:22 --listen :2222 |
| 168 | +``` |
| 169 | + |
| 170 | +If set up correctly, Pomerium will open your browser to authenticate you. This will establish a TCP connection. |
| 171 | + |
| 172 | +In a separate terminal window, run: |
| 173 | + |
| 174 | +```bash |
| 175 | +ssh user@myssh.<CLUSTER_SUBDOMAIN>.pomerium.app -p 2222 |
| 176 | +``` |
| 177 | + |
| 178 | +This will prompt the SSH server to request a password. The credentials are hardcoded in the Docker Compose file: |
| 179 | + |
| 180 | +- **USER_PASSWORD:** supersecret |
| 181 | +- **USER_NAME:** user |
| 182 | + |
| 183 | +After authenticating, you should see a greeting from OpenSSH, like: |
| 184 | + |
| 185 | +```shell-session |
| 186 | +$ user@myssh.<CLUSTER_SUBDOMAIN>.pomerium.app's password: |
| 187 | +Welcome to OpenSSH Server |
| 188 | +
|
| 189 | +f157ed9f7a38:~$ |
| 190 | +``` |
| 191 | + |
| 192 | +Awesome! You successfully configured two services that take advantage of Pomerium's TCP capabilities to proxy requests. |
| 193 | + |
| 194 | +## Up Next: Certificates |
| 195 | + |
| 196 | +Go to [Certificates](/docs/courses/zero-fundamentals/certificates) |
0 commit comments