-
Notifications
You must be signed in to change notification settings - Fork 108
/
enabling-tcp-routing.html.md.erb
295 lines (210 loc) · 13.4 KB
/
enabling-tcp-routing.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
---
title: Enabling and configuring TCP routing in Cloud Foundry
owner: CF for VMs Networking
---
<%# Reset page title based on platform type %>
<% if vars.platform_code != 'CF' %>
<% set_title("Enabling and configuring TCP routing in", vars.app_runtime_abbr) %>
<% end %>
You can enable TCP routing in <%= vars.app_runtime_abbr %>. Learn about TCP routing and go through the steps of enabling and configuring it.
## <a id="overview"></a> TCP routing overview
You can use TCP routing to run apps that serve requests on non-HTTP TCP protocols.
You can use TCP routing to comply with regulatory requirements to stop TLS as close
to apps as possible so that packets are not decrypted before reaching the app level.
## <a id="architecture"></a> TCP routing architecture
The following diagram shows the layers of network address translation that occur in <%= vars.app_runtime_first %>
in support of TCP routing.
![Route Ports](./images/route_ports.png)
The following example workflow ships with route ports, back end ports, and app ports:
1. You create a TCP route for your app based on a TCP domain and a route port, and
map this route to one or more apps. See [Create a Route](../devguide/deploy-apps/routes-domains.html#create-route) in _Configuring Routes and Domains_.
1. Clients make requests to the route. DNS resolves the domain name to the load balancer.
1. The load balancer listens on the port and forwards requests for the domain to the TCP
routers. The load balancer must listen on a range of ports to support multiple TCP route
creation. Additionally, <%= vars.app_runtime_abbr %> must be configured with this range,
so that the platform knows which ports can be reserved when you create TCP routes.
1. The TCP router can be dynamically configured to listen on the port when the route is mapped
to an app. The domain the request was originally sent to is no longer relevant to the routing
of the request to the app. The TCP router keeps a dynamically updated record of the back
ends for each route port. The back ends represent instances of an app mapped to the route.
The TCP router chooses a back end using a round-robin load balancing algorithm for each new
TCP connection from a client. Because the TCP router is protocol-agnostic, it does not recognize
individual requests, only TCP connections. All client requests transit the same connection
to the selected back end until the client or back end closes the connection. Each subsequent
connection initiates the selection of a back end.
1. Because containers each have their own private network, the TCP router does not have direct
access to app containers. When a container is created for an app instance, a port on the Diego
Cell VM is randomly chosen and iptables are configured to forward requests for this port to
the internal interface on the app container. The TCP router then receives a mapping of the
route port to the Diego Cell IP and port.
1. By default, the Diego Cell only routes requests to port `8080`, the app port, on the app
container internal interface. The app port is the port on which apps must listen. Developers
can use the Cloud Controller API to update the ports an app can receive requests on.
For more
information, see [Configuring Apps to Listen on Custom Ports (Beta)](../devguide/custom-ports.html).
## <a id="prerequisites"></a> Prerequisites for activating TCP routing
<%= vars.mutual_tls_tcp %>
Before you activate TCP routing, you must set up networking requirements.
To set up networking
requirements:
1. Choose a domain from which you can create TCP routes for your apps. For
example, create a domain which is similar to your app domain but prefixed by the TCP subdomain,
such as `tcp.APP-DOMAIN.com`, where `APP-DOMAIN` is the name of your app domain.
1. Configure DNS to resolve this domain name to the IP address of a highly available load
balancer that can forward traffic for the domain to the TCP routers. For more information,
see [Domains](../devguide/deploy-apps/routes-domains.html#domains) in _Configuring Routes
and Domains_. If you are operating an environment that does not require high availability,
configure DNS to resolve the TCP domain name you have chosen directly to a single instance
of the TCP router.
1. (Optional) Choose IP addresses for the TCP routers and configure your load balancer to
forward requests for the domain you chose in the first step above to these addresses. Skip
this step if you have configured DNS to resolve the TCP domain name to an instance of the
TCP router. <%= vars.tcp_iaas %>
1. (Optional) Decide how many TCP routes you want to support. For each TCP route, you must
reserve a port. Configure your load balancer to forward the range of ports to the TCP routers.
Skip this step if you have configured DNS to resolve the TCP domain name to an instance of
the TCP router. For more information about configuring port reservations, see [Modify TCP
Port Reservations](#modify-ports).
<% if vars.platform_code != "CF" %>
1. <%= partial "/pcf/core/tcp_port_review" %>
<% else %>
1. <%= partial "../adminguide/tcp_modify_ports" %>
<% end %>
<% if vars.platform_code != "CF" %>
## <a id="config-tcp"></a> Enable TCP routing
<%= partial "/pcf/core/configure-tcp-routing" %>
<% else %>
### <a id="tls-tcp-routes"></a> TLS for TCP Routing
Starting with [cf-deployment v43.0.0](https://github.com/cloudfoundry/cf-deployment),
<%= vars.app_runtime_abbr %> defaults to enabling TLS for TCP routes and disabling unproxied ports for app containers. This has two primary benefits:
- Traffic is encrypted between TCP Routers and applications, like how it is encrypted between Gorouter and applications.
- Only the Gorouter and TCP Router can connect directly to app containers via the underlay network, which prevents unauthorized access to the applications.
#### Disabling TLS for TCP Routing
To disable TLS for TCP routing without causing TLS route downtime, you must follow a two-stage procedure:
1. Re-enable unproxied ports on all Diego cells by completing a BOSH deploy using the following ops files, as appropriate for your environment:
1. [operations/disable-tls-tcp-routing-stage-1-unproxied-ports.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/disable-tls-tcp-routing-stage-1-unproxied-ports.yml)
1. [operations/disable-tls-tcp-routing-isolation-segment-stage-1-unproxied-ports.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/disable-tls-tcp-routing-isolation-segment-stage-1-unproxied-ports.yml)
1. [operations/experimental/disable-tls-tcp-routing-windows-stage-1-unproxied-ports.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/experimental/disable-tls-tcp-routing-windows-stage-1-unproxied-ports.yml)
1. Disable TLS for TCP Routing by completing a second BOSH deploy adding the following ops files to the above ops files, as appropriate for your environment:
1. [operations/disable-tls-tcp-routing-stage-2-tcp-router-and-route-emitter.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/disable-tls-tcp-routing-stage-2-tcp-router-and-route-emitter.yml)
1. [operations/disable-tls-tcp-routing-isolation-segment-stage-2-route-emitter.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/disable-tls-tcp-routing-isolation-segment-stage-2-route-emitter.yml)
1. [operations/experimental/disable-tls-tcp-routing-windows-stage-2-route-emitter.yml](https://github.com/cloudfoundry/cf-deployment/tree/main/operations/experimental/disable-tls-tcp-routing-windows-stage-2-route-emitter.yml)
<% end %>
## <a id="post-deploy"></a> Configure TCP routing after deploying <%= vars.app_runtime_abbr %>
After you activate TCP routing and deploy <%= vars.app_runtime_abbr %>, you must add the TCP
shared domain and configure org quotas that allow you to create TCP routes. To do this,
you must use the Cloud Foundry Command Line Interface (cf CLI) and have an admin user account.
For more information about the cf CLI, see [Using the Cloud Foundry Command Line Interface
(cf CLI)](../cf-cli/index.html).
### <a id="configure-domain"></a> Configure <%= vars.app_runtime_abbr %> with your TCP Domain
After you deploy <%= vars.app_runtime_abbr %>, you must configure <%= vars.app_runtime_abbr %>
with the domain that you configured in [Prerequisites for Enabling TCP Routing](#prerequisites).
This is the domain from which developers create TCP routes.
To configure <%= vars.app_runtime_abbr %> with your TCP domain:
1. To list your router groups, run:
```console
cf router-groups
```
You must see `default-tcp` as a response.
1. Create a shared domain and associate it with the `default-tcp` router group by running:
```console
cf create-shared-domain tcp.APP-DOMAIN.com --router-group default-tcp
```
Where `APP-DOMAIN` is the name of your app domain.
1. Verify that `TCP` appears under `type` next to your TCP domain by running:
```console
cf domains
```
### <a id="configure-quota"></a> Configure a quota for TCP routes
Because TCP route ports are a limited resource in some environments, quotas are configured
to allow creation of zero TCP routes by default. After you deploy <%= vars.app_runtime_abbr %>,
you can increase the maximum number of TCP routes for all orgs or for particular orgs and
spaces. Because you reserve a route port for each TCP route, you manage the quota for route
ports using the `--reserved-route-ports` cf CLI command option.
For more information, see
[Creating and Modifying Quota Plans](quota-plans.html).
You can configure quotas for TCP routes in the following ways:
* If you have a default quota that applies to all orgs, you can update it to configure the
number of route ports that can be reserved by each org by running:
```
cf update-org-quota QUOTA --reserved-route-ports NUMBER-OF-ROUTE-PORTS
```
Where:
<ul>
<li><code>QUOTA</code> is the maximum number of TCP routes you want to allocate to all orgs.</li>
<li><code>NUMBER-OF-ROUTE-PORTS</code> is the number of route ports you want to allow each org to reserve.</li>
</ul>
* To create a new quota that governs the number of route ports that can be created in a
particular org:
1. Target the org for which you want to create the quota by running:
```
cf target -o ORG-NAME
```
Where `ORG-NAME` is the name of the org for which you want to create the quota.
1. Run:
```
create-org-quota QUOTA --reserved-route-ports NUMBER-OF-ROUTE-PORTS
```
Where:
<ul>
<li><code>QUOTA</code> is the maximum number of TCP routes you want to allocate to particular orgs.</li>
<li><code>NUMBER-OF-ROUTE-PORTS</code> is the number of route ports you want to allow each org to
reserve.</li>
</ul>
* To create a new quota that governs the number of route ports that can be created in a
particular space:
1. Target the space to create the quota by running:
```
cf target -s SPACE-NAME
```
Where `SPACE-NAME` is the name of the space for which you want to create the quota.
1. Run:
```
cf create-space-quota QUOTA --reserved-route-ports NUMBER-OF-ROUTE-PORTS
```
Where:
<ul>
<li><code>QUOTA</code> is the maximum number of TCP routes you want to allocate to a particular space.</li>
<li><code>NUMBER-OF-ROUTE-PORTS</code> is the number of route ports you want to allow the space to reserve.</li>
</ul>
## <a id="create-tcp-route"></a> Create a TCP route
For information about creating a TCP route, see [Create a TCP Route with a Port](../devguide/deploy-apps/routes-domains.html#create-route-with-port) in _Configuring Routes
and Domains_.
## <a id="modify-ports"></a> Modify TCP port reservations
After deploying <%= vars.app_runtime_abbr %>, you can modify the range of ports available
for TCP routes using `cf curl` commands, as demonstrated with the following commands. The
commands require you to have an admin user account with the `routing.router_groups.read`
and `routing.router_groups.write` scopes.
1. In a terminal window, view the `reservable_ports` by running:
```
cf curl /routing/v1/router_groups
```
Record the `guid` from the output.
1. To configure a new port, run:
```
cf curl /routing/v1/router_groups/GUID
```
Where `GUID` is the GUID you recorded in the previous step.
<br>
<br>
To configure multiple ports, enter a comma-separated list of ports or port ranges by
running:
```
cf curl \
-X PUT -d '{"reservable_ports":"PORTS-OR-PORT-RANGES"}' \
/routing/v1/router_groups/f7392031-a488-4890-8835-c4a038a3bded
```
Where `PORTS-OR-PORT-RANGES` is a comma-separated list of ports or port ranges. For
example, `"reservable_ports":"1024-1199,1234-1248,1312"`.
<p class="note important">
Do not enter <code>reservable_ports</code> that conflict
with other TCP router instances or ephemeral port ranges. <%= vars.company_name %> recommends
using port ranges within <code>1024-2047</code> and <code>18000-32767</code> on default
installations. Check which ports are available on the TCP router VMs to verify that no
additional ports are in use. For more information, see <a href="https://github.com/cloudfoundry/routing-release/issues/184">
TCP router fails to configure routes when there is a port conflict with a local process</a> in the Routing Release repository on GitHub.
</p>
<% if vars.platform_code != "CF" %>
## <a id="disable-tcp"></a> Deactivate TCP routing
<%= partial "/pcf/core/disable-tcp-routing-procedure" %>
<% end %>