|
| 1 | +# TLS Passthrough Support |
| 2 | + |
| 3 | +[Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/guides/tls/) lays out the general guidelines on how to configure TLS passthrough. Here are examples on how to use them against AWS Gateway Api controller and VPC Lattice. |
| 4 | + |
| 5 | +## Install Gateway API TLSRoute CRD |
| 6 | + |
| 7 | +The TLSRoute CRD is already included in the helm chart and deployment.yaml, if you are using these 2 methods to install the controller no extra steps needed. |
| 8 | +If you want to install the TLSRoute CRD manually by yourself: |
| 9 | +``` |
| 10 | +# Install CRD |
| 11 | +kubectl apply -f config/crds/bases/gateway.networking.k8s.io_tlsroutes.yaml |
| 12 | +# Verfiy TLSRoute CRD |
| 13 | +kubectl get crd tlsroutes.gateway.networking.k8s.io |
| 14 | +NAME CREATED AT |
| 15 | +tlsroutes.gateway.networking.k8s.io 2024-03-07T23:16:22Z |
| 16 | +``` |
| 17 | + |
| 18 | +## Setup TLS Passthrough Connectivity in a single cluster |
| 19 | + |
| 20 | +### 1. Configure TLS Passthrough Listener on Gateway |
| 21 | + |
| 22 | +``` |
| 23 | +kubectl apply -f files/examples/my-gateway-tls-passthrough.yaml |
| 24 | +``` |
| 25 | + |
| 26 | +``` |
| 27 | +# tls listener config snips: |
| 28 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 29 | +kind: Gateway |
| 30 | +metadata: |
| 31 | + name: my-hotel-tls-passthrough |
| 32 | +spec: |
| 33 | + gatewayClassName: amazon-vpc-lattice |
| 34 | + listeners: |
| 35 | + ... |
| 36 | + - name: tls |
| 37 | + protocol: TLS |
| 38 | + port: 443 |
| 39 | + tls: |
| 40 | + mode: Passthrough |
| 41 | + ... |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. Configure TLSRoute |
| 45 | + |
| 46 | +``` |
| 47 | +# Suppose in the below example, we use the "parking" service as the client pod to test the TLS passthrough traffic. |
| 48 | +kubectl apply -f files/examples/parking.yaml |
| 49 | +
|
| 50 | +# Configure nginx backend service (This nginx image includes a self-signed certificate) |
| 51 | +kubectl apply -f files/example/nginx-server-tls-passthrough.yaml |
| 52 | +
|
| 53 | +# configure nginx tls route |
| 54 | +kubectl apply -f files/examples/tlsroute-nginx.yaml |
| 55 | +
|
| 56 | +``` |
| 57 | + |
| 58 | +### 3. Verify the controller has reconciled nginx-tls route |
| 59 | + |
| 60 | +Make sure the TLSRoute has the `application-networking.k8s.aws/lattice-assigned-domain-name` annotation and status `Accepted: True` |
| 61 | +``` |
| 62 | +kubectl get tlsroute nginx-tls -o yaml |
| 63 | +apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 64 | +kind: TLSRoute |
| 65 | +metadata: |
| 66 | + annotations: |
| 67 | + application-networking.k8s.aws/lattice-assigned-domain-name: nginx-tls-default-0af995120af2711bc.7d67968.vpc-lattice-svcs.us-west-2.on.aws |
| 68 | + ... |
| 69 | + name: nginx-tls |
| 70 | + namespace: default |
| 71 | + ... |
| 72 | + |
| 73 | +status: |
| 74 | + parents: |
| 75 | + - conditions: |
| 76 | + - lastTransitionTime: ..... |
| 77 | + message: "" |
| 78 | + observedGeneration: 1 |
| 79 | + reason: Accepted |
| 80 | + status: "True" |
| 81 | + type: Accepted |
| 82 | + - lastTransitionTime: ..... |
| 83 | + message: "" |
| 84 | + observedGeneration: 1 |
| 85 | + reason: ResolvedRefs |
| 86 | + status: "True" |
| 87 | + type: ResolvedRefs |
| 88 | + controllerName: application-networking.k8s.aws/gateway-api-controller |
| 89 | +
|
| 90 | +``` |
| 91 | + |
| 92 | +### 4. Verify TLS Passthrough Traffic |
| 93 | + |
| 94 | +``` |
| 95 | +kubectl get deployment nginx-tls |
| 96 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 97 | +nginx-tls 2/2 2 2 1d |
| 98 | +
|
| 99 | +# Use the specified TLSRoute hostname to send traffic to the beackend nginx service |
| 100 | +kubectl exec deployments/parking -- curl -kv https://nginx-test.my-test.com --resolve nginx-test.my-test.com:443:169.254.171.0 |
| 101 | +
|
| 102 | +* Trying 169.254.171.0:443... |
| 103 | +* Connected to nginx-test.my-test.com (169.254.171.0) port 443 (#0) |
| 104 | +.... |
| 105 | +* TLSv1.2 (OUT), TLS header, Certificate Status (22): |
| 106 | +* TLSv1.2 (OUT), TLS handshake, Client hello (1): |
| 107 | +* TLSv1.2 (IN), TLS handshake, Server hello (2): |
| 108 | +* TLSv1.2 (IN), TLS handshake, Certificate (11): |
| 109 | +* TLSv1.2 (IN), TLS handshake, Server key exchange (12): |
| 110 | +* TLSv1.2 (IN), TLS handshake, Server finished (14): |
| 111 | +* TLSv1.2 (OUT), TLS handshake, Client key exchange (16): |
| 112 | +* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): |
| 113 | +* TLSv1.2 (OUT), TLS handshake, Finished (20): |
| 114 | +* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): |
| 115 | +* TLSv1.2 (IN), TLS handshake, Finished (20): <---------- TLS Handshake from client pod to the backend `nginx-tls` pod successfully, no tls termination in the middle |
| 116 | +* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 |
| 117 | +* ALPN, server accepted to use h2 |
| 118 | +.... |
| 119 | +<body> |
| 120 | +<h1>Welcome to nginx!</h1> |
| 121 | +<p>If you see this page, the nginx web server is successfully installed and |
| 122 | +working. Further configuration is required.</p> |
| 123 | +.... |
| 124 | +
|
| 125 | +``` |
| 126 | + |
| 127 | +## Setup TLS Passthrough Connectivity spanning multiple clusters |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +### 1. In this example we still use the "parking" Kubernetes service as the client pod to test the cross cluster TLS passthrough traffic. |
| 133 | +``` |
| 134 | +kubectl apply -f files/examples/parking.yaml |
| 135 | +``` |
| 136 | + |
| 137 | +### 2. In cluster-1, create `tls-rate1` Kubernetes Service: |
| 138 | +``` |
| 139 | +kubectl apply -f files/examples/tls-rate1.yaml |
| 140 | +``` |
| 141 | + |
| 142 | +### 3. Configure ServiceExport with TargetGroupPolicy `protocol:TCP` in cluster-2 |
| 143 | + |
| 144 | +``` |
| 145 | +# Create tls-rate2 Kubernetes Service in cluster-2 |
| 146 | +kubectl apply -f files/examples/tls-rate2.yaml |
| 147 | +# Create serviceexport in cluster-2 |
| 148 | +kubectl apply -f files/examples/tls-rate2-export.yaml |
| 149 | +# Create targetgroup policy to configure TCP protocol for tls-rate2 in cluster-2 |
| 150 | +kubectl apply -f files/examples/tls-rate2-targetgrouppolicy.yaml |
| 151 | +``` |
| 152 | + |
| 153 | +``` |
| 154 | +# Snips of serviceexport config |
| 155 | +apiVersion: application-networking.k8s.aws/v1alpha1 |
| 156 | +kind: ServiceExport |
| 157 | +metadata: |
| 158 | + name: tls-rate-2 |
| 159 | + annotations: |
| 160 | + application-networking.k8s.aws/federation: "amazon-vpc-lattice" |
| 161 | +# Snips of targetgroup policy config |
| 162 | +apiVersion: application-networking.k8s.aws/v1alpha1 |
| 163 | +kind: TargetGroupPolicy |
| 164 | +metadata: |
| 165 | + name: tls-rate2 |
| 166 | +spec: |
| 167 | + targetRef: |
| 168 | + group: "application-networking.k8s.aws" |
| 169 | + kind: ServiceExport |
| 170 | + name: tls-rate2 |
| 171 | + protocol: TCP |
| 172 | +``` |
| 173 | + |
| 174 | +### 4. Configure ServiceImport in cluster1 |
| 175 | + |
| 176 | +``` |
| 177 | +kubectl apply -f files/examples/tls-rate2-import.yaml |
| 178 | +``` |
| 179 | + |
| 180 | +### 5. Configure TLSRoute for blue/green deployment |
| 181 | + |
| 182 | +``` |
| 183 | +kubectl apply -f files/examples/rate-tlsroute-bluegreen.yaml |
| 184 | +
|
| 185 | +# snips of TLSRoute span multiple Kubernetes Clusters |
| 186 | +apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 187 | +kind: TLSRoute |
| 188 | +metadata: |
| 189 | + name: tls-rate |
| 190 | +spec: |
| 191 | + hostnames: |
| 192 | + - tls-rate.my-test.com |
| 193 | + parentRefs: |
| 194 | + - name: my-hotel-tls |
| 195 | + sectionName: tls |
| 196 | + rules: |
| 197 | + - backendRefs: |
| 198 | + - name: tls-rate1 <---------- to Kubernetes Cluster-1 |
| 199 | + kind: Service |
| 200 | + port: 443 |
| 201 | + weight: 10 |
| 202 | + - name: tls-rate2 <---------- to Kubernetes Cluster-2 |
| 203 | + kind: ServiceImport |
| 204 | + port: 443 |
| 205 | + weight: 90 |
| 206 | +``` |
| 207 | +### 6. Verify cross-cluster TLS passthrough traffic |
| 208 | + |
| 209 | +Expected to receive the weighted traffic route to tls-rate1 service(10%) and tls-rate2 service(90%), if you curl the `tls-rate.my-test.com` from the client pod multiple times: |
| 210 | +``` |
| 211 | +kubectl exec deploy/parking -- sh -c 'for ((i=1; i<=30; i++)); do curl -k https://tls-rate.my-test.com --resolve tls-rate.my-test.com:443:169.254.171.0 2>/dev/null; done' |
| 212 | +
|
| 213 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod <----> k8s service in cluster-2 |
| 214 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 215 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 216 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 217 | +Requsting to TLS Pod(tls-rate1-98cc7fd87a-642zw): tls-rate1 handler pod <----> k8s service in cluster-1 |
| 218 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 219 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 220 | +Requsting to TLS Pod(tls-rate2-7f8b9cc97b-fgqk6): tls-rate2 handler pod |
| 221 | +Requsting to TLS Pod(tls-rate1-98cc7fd87a-642zw): tls-rate1 handler pod |
| 222 | +``` |
0 commit comments