You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this guide, we will show how to specify the TLS configuration of the connection from the Gateway to a backend pod/s via the Service API object using a [BackendTLSPolicy](https://gateway-api.sigs.k8s.io/api-types/backendtlspolicy/).
9
+
In this guide, we will show how to specify the TLS configuration of the connection from the Gateway to a backend pod/s via the Service API object using a [BackendTLSPolicy](https://gateway-api.sigs.k8s.io/api-types/backendtlspolicy/). This covers the use-case where the service or backend owner is doing their own TLS and NGINX Gateway Fabric needs to know how to connect to this backend pod that has its own certificate over HTTPS.
10
10
11
11
## Prerequisites
12
12
13
-
-[Install]({{< relref "installation/" >}}) NGINX Gateway Fabric. Please note that the Gateway APIs from the experimental channel are required, and NGF must be deployed with the `- --experimental-features-enable` flag..
13
+
-[Install]({{< relref "installation/" >}}) NGINX Gateway Fabric. Please note that the Gateway APIs from the experimental channel are required, and NGF must be deployed with the `- --experimental-features-enable` flag.
14
14
-[Expose NGINX Gateway Fabric]({{< relref "installation/expose-nginx-gateway-fabric.md" >}}) and save the public IP address and port of NGINX Gateway Fabric into shell variables:
15
15
16
16
```text
@@ -106,7 +106,7 @@ data:
106
106
EOF
107
107
```
108
108
109
-
This will create the **secure-app** service and a deployment, as well as a Secret containing the certificate and key that will be used by the backend application to decrypt the HTTP traffic. Note that the application is configured to accept HTTPS traffic only. Run the following command to verify the resources were created:
109
+
This will create the **secure-app** service and a deployment, as well as a Secret containing the certificate and key that will be used by the backend application to decrypt the HTTPS traffic. Note that the application is configured to accept HTTPS traffic only. Run the following command to verify the resources were created:
110
110
111
111
```shell
112
112
kubectl get pods,svc
@@ -122,9 +122,76 @@ NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
First, we will create the Gateway resource with an HTTP listener:
128
+
129
+
```yaml
130
+
kubectl apply -f - <<EOF
131
+
apiVersion: gateway.networking.k8s.io/v1
132
+
kind: Gateway
133
+
metadata:
134
+
name: gateway
135
+
spec:
136
+
gatewayClassName: nginx
137
+
listeners:
138
+
- name: http
139
+
port: 80
140
+
protocol: HTTP
141
+
EOF
142
+
```
143
+
144
+
Next, we will create our HTTPRoute to route traffic to our secure-app backend:
145
+
146
+
```yaml
147
+
kubectl apply -f - <<EOF
148
+
apiVersion: gateway.networking.k8s.io/v1
149
+
kind: HTTPRoute
150
+
metadata:
151
+
name: secure-app
152
+
spec:
153
+
parentRefs:
154
+
- name: gateway
155
+
sectionName: http
156
+
hostnames:
157
+
- "secure-app.example.com"
158
+
rules:
159
+
- matches:
160
+
- path:
161
+
type: PathPrefix
162
+
value: /
163
+
backendRefs:
164
+
- name: secure-app
165
+
port: 8443
166
+
EOF
167
+
```
168
+
169
+
## Send Traffic without backend TLS configuration
170
+
171
+
Using the external IP address and port for NGINX Gateway Fabric, we can send traffic to our secure-app application. To show what happens if we send plain HTTP traffic from NGF to our `secure-app`, let's try sending a request before we create the backend TLS configuration.
172
+
173
+
{{< note >}}If you have a DNS record allocated for `secure-app.example.com`, you can send the request directly to that hostname, without needing to resolve.{{< /note >}}
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
182
+
<body>
183
+
<center><h1>400 Bad Request</h1></center>
184
+
<center>The plain HTTP request was sent to HTTPS port</center>
185
+
<hr><center>nginx/1.25.3</center>
186
+
</body>
187
+
</html>
188
+
```
189
+
190
+
We can see we a status 400 Bad Request message from NGINX.
191
+
125
192
## Create the Backend TLS configuration
126
193
127
-
Create the ConfigMap that holds the `ca.crt` entry for verifying our self-signed certificates:
194
+
To configure the backend TLS terminationm, first we will create the ConfigMap that holds the `ca.crt` entry for verifying our self-signed certificates:
128
195
129
196
```yaml
130
197
kubectl apply -f - <<EOF
@@ -158,7 +225,7 @@ data:
158
225
EOF
159
226
```
160
227
161
-
Create the Backend TLS Policy which targets our `secure-app` Service and refers to the ConfigMap created in the previous step:
228
+
Next, we create the Backend TLS Policy which targets our `secure-app` Service and refers to the ConfigMap created in the previous step:
162
229
163
230
```yaml
164
231
kubectl apply -f - <<EOF
@@ -181,55 +248,56 @@ spec:
181
248
EOF
182
249
```
183
250
184
-
## Configure Routing rules
185
-
186
-
First, we will create the Gateway resource with a HTTP listener:
251
+
To confirm the Polict was created and attached successfully, we can run a describe on the BackendTLSPolicy object:
187
252
188
-
```yaml
189
-
kubectl apply -f - <<EOF
190
-
apiVersion: gateway.networking.k8s.io/v1
191
-
kind: Gateway
192
-
metadata:
193
-
name: gateway
194
-
spec:
195
-
gatewayClassName: nginx
196
-
listeners:
197
-
- name: http
198
-
port: 80
199
-
protocol: HTTP
200
-
EOF
253
+
```shell
254
+
k describe backendtlspolicies.gateway.networking.k8s.io
201
255
```
202
256
203
-
Next, we will create our HTTPRoute to route traffic to our secure-app backend
204
-
205
-
```yaml
206
-
kubectl apply -f - <<EOF
207
-
apiVersion: gateway.networking.k8s.io/v1
208
-
kind: HTTPRoute
209
-
metadata:
210
-
name: secure-app
211
-
spec:
212
-
parentRefs:
213
-
- name: gateway
214
-
sectionName: http
215
-
hostnames:
216
-
- "secure-app.example.com"
217
-
rules:
218
-
- matches:
219
-
- path:
220
-
type: PathPrefix
221
-
value: /
222
-
backendRefs:
223
-
- name: secure-app
224
-
port: 8443
225
-
EOF
257
+
```text
258
+
Name: backend-tls
259
+
Namespace: default
260
+
Labels: <none>
261
+
Annotations: <none>
262
+
API Version: gateway.networking.k8s.io/v1alpha2
263
+
Kind: BackendTLSPolicy
264
+
Metadata:
265
+
Creation Timestamp: 2024-02-01T12:02:38Z
266
+
Generation: 1
267
+
Resource Version: 19380
268
+
UID: b3983a6e-92f1-4a98-b2af-64b317d74528
269
+
Spec:
270
+
Target Ref:
271
+
Group:
272
+
Kind: Service
273
+
Name: secure-app
274
+
Namespace: default
275
+
Tls:
276
+
Ca Cert Refs:
277
+
Group:
278
+
Kind: ConfigMap
279
+
Name: backend-cert
280
+
Hostname: secure-app.example.com
281
+
Status:
282
+
Ancestors:
283
+
Ancestor Ref:
284
+
Group: gateway.networking.k8s.io
285
+
Kind: Gateway
286
+
Name: gateway
287
+
Namespace: default
288
+
Conditions:
289
+
Last Transition Time: 2024-02-01T12:02:38Z
290
+
Message: BackendTLSPolicy is attached to the Gateway
Using the external IP address and port for NGINX Gateway Fabric, we can send traffic to our secure-app application.
231
-
232
-
{{< note >}}If you have a DNS record allocated for `secure-app.example.com`, you can send the request directly to that hostname, without needing to resolve.{{< /note >}}
0 commit comments