Skip to content

HTTPS Termination #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
24664f1
HTTPS Termination
Jul 6, 2022
e33be3a
Add nolint for test certs
Jul 12, 2022
514c63f
Another nolint
Jul 12, 2022
79b1daa
Last nolint
Jul 12, 2022
23f91c8
Lint warning fixes
Jul 12, 2022
62fdc19
Add event loop config object
Jul 14, 2022
365abb3
Const block
Jul 14, 2022
209288d
Add listener file to state package
Jul 14, 2022
fa85921
Fix secret filepath
Jul 14, 2022
8da6df2
Remove ignored namespaces
Jul 14, 2022
374a6ec
Fix len comparison
Jul 14, 2022
d4bcc0a
Indent if/else/end block in template
Jul 14, 2022
e8a5194
rules -> rulesPerHost
Jul 14, 2022
643129b
secretCache -> secretStore
Jul 14, 2022
1f1bdbf
SecretMemoryManager -> SecretDiskMemoryManager
Jul 14, 2022
ed16702
store -> request
Jul 14, 2022
5a9c672
Do not use default server secret
Jul 14, 2022
57a81dd
Fix test httproute names
Jul 18, 2022
64b8222
Don't configure invalid listeners
Jul 18, 2022
4b6b9ad
collision -> collisions
Jul 18, 2022
bfb6c7b
validateHTTPSListener
Jul 18, 2022
8bfd551
Fix up secrets tests and rename WriteAllStoredSecrets to WriteAllRequ…
Jul 18, 2022
7c34024
Generate default http server
Jul 18, 2022
445974e
HTTPServer -> VirtualServer and HTTPSServers -> SSLServers
Jul 18, 2022
3d1d472
Fix missing semicolon
Jul 19, 2022
84adfd0
Change ns of gateway in example
Jul 19, 2022
623f125
Add gateways to each example
Jul 19, 2022
f2b6cbe
Standardize on implementation package and add test suite files
Jul 19, 2022
1405fc0
Fix linting error
Jul 19, 2022
97a4921
Fix some typos
Jul 19, 2022
02fde36
Add FileManager interface to unit test file i/o
Jul 21, 2022
6f8a3dc
Move listener tests into listener_test.go
Jul 21, 2022
a8e4a54
Remove namespace from example resources
Jul 21, 2022
08a84db
Update capacity
Jul 21, 2022
d05d2c1
Add fixme
Jul 21, 2022
67958f6
Add doc string
Jul 21, 2022
2909f0e
Fix typo
Jul 21, 2022
9eb07ec
Add fixme for concurrency question
Jul 21, 2022
37571b6
Move file i/o tests under secret disk memory manager describe
Jul 25, 2022
5070b28
Use impl in tests
Jul 25, 2022
57472ba
Rewrite error tests as table
Jul 25, 2022
530249e
Fix template spacing
Jul 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ You can deploy NGINX Kubernetes Gateway on an existing Kubernetes 1.16+ cluster.
NAME READY STATUS RESTARTS AGE
nginx-gateway-5d4f4c7db7-xk2kq 2/2 Running 0 112s
```
1. Create the Gateway resource:

```
kubectl apply -f deploy/manifests/gateway.yaml
```

## Expose NGINX Kubernetes Gateway

Expand Down
5 changes: 4 additions & 1 deletion deploy/manifests/nginx-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rules:
- ""
resources:
- services
- secrets
verbs:
- list
- watch
Expand Down Expand Up @@ -80,7 +81,7 @@ spec:
initContainers:
- image: busybox:1.34 # FIXME(pleshakov): use gateway container to init the Config with proper main config
name: nginx-config-initializer
command: [ 'sh', '-c', 'echo "load_module /usr/lib/nginx/modules/ngx_http_js_module.so; events {} pid /etc/nginx/nginx.pid; http { include /etc/nginx/conf.d/*.conf; js_import /usr/lib/nginx/modules/njs/httpmatches.js; server { default_type text/html; return 404; } }" > /etc/nginx/nginx.conf && mkdir /etc/nginx/conf.d && chown 1001:0 /etc/nginx/conf.d' ]
command: [ 'sh', '-c', 'echo "load_module /usr/lib/nginx/modules/ngx_http_js_module.so; events {} pid /etc/nginx/nginx.pid; http { include /etc/nginx/conf.d/*.conf; js_import /usr/lib/nginx/modules/njs/httpmatches.js; }" > /etc/nginx/nginx.conf && mkdir /etc/nginx/conf.d /etc/nginx/secrets && chown 1001:0 /etc/nginx/conf.d /etc/nginx/secrets' ]
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx
Expand All @@ -105,6 +106,8 @@ spec:
ports:
- name: http
containerPort: 80
- name: https
containerPort: 443
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx
Expand Down
4 changes: 4 additions & 0 deletions deploy/manifests/service/loadbalancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ spec:
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
app: nginx-gateway
6 changes: 6 additions & 0 deletions examples/advanced-routing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ The cafe application consists of four services: `coffee-v1-svc`, `coffee-v2-svc`

## 3. Configure Routing

1. Create the `Gateway`:

```
kubectl apply -f gateway.yaml
```

1. Create the `HTTPRoute` resources:

```
Expand Down
2 changes: 0 additions & 2 deletions examples/advanced-routing/cafe-routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
spec:
parentRefs:
- name: gateway
namespace: nginx-gateway
sectionName: http
hostnames:
- "cafe.example.com"
Expand Down Expand Up @@ -41,7 +40,6 @@ metadata:
spec:
parentRefs:
- name: gateway
namespace: nginx-gateway
sectionName: http
hostnames:
- "cafe.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
namespace: nginx-gateway
labels:
domain: k8s-gateway.nginx.org
spec:
Expand Down
6 changes: 6 additions & 0 deletions examples/cafe-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ In this example we deploy NGINX Kubernetes Gateway, a simple web application, an

## 3. Configure Routing

1. Create the `Gateway`:

```
kubectl apply -f gateway.yaml
```

1. Create the `HTTPRoute` resources:

```
Expand Down
3 changes: 0 additions & 3 deletions examples/cafe-example/cafe-routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
spec:
parentRefs:
- name: gateway
namespace: nginx-gateway
sectionName: http
hostnames:
- "cafe.example.com"
Expand All @@ -21,7 +20,6 @@ metadata:
spec:
parentRefs:
- name: gateway
namespace: nginx-gateway
sectionName: http
hostnames:
- "cafe.example.com"
Expand All @@ -41,7 +39,6 @@ metadata:
spec:
parentRefs:
- name: gateway
namespace: nginx-gateway
sectionName: http
hostnames:
- "cafe.example.com"
Expand Down
12 changes: 12 additions & 0 deletions examples/cafe-example/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
labels:
domain: k8s-gateway.nginx.org
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
90 changes: 90 additions & 0 deletions examples/https-termination/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# HTTPS Termination Example

In this example we expand on the simple [cafe-example](../cafe-example) by adding HTTPS termination to our routes.

## Running the Example

## 1. Deploy NGINX Kubernetes Gateway

1. Follow the [installation instructions](https://github.com/nginxinc/nginx-kubernetes-gateway/blob/main/README.md#run-nginx-gateway) to deploy NGINX Gateway.

1. Save the public IP address of NGINX Kubernetes Gateway into a shell variable:

```
GW_IP=XXX.YYY.ZZZ.III
```

1. Save the HTTPS port of NGINX Kubernetes Gateway:

```
GW_HTTPS_PORT=port
```

## 2. Deploy the Cafe Application

1. Create the coffee and the tea deployments and services:

```
kubectl apply -f cafe.yaml
```

1. Check that the Pods are running in the `default` namespace:

```
kubectl -n default get pods
NAME READY STATUS RESTARTS AGE
coffee-6f4b79b975-2sb28 1/1 Running 0 12s
tea-6fb46d899f-fm7zr 1/1 Running 0 12s
```

## 3. Configure HTTPS Termination and Routing

1. Create a secret with a TLS certificate and key:
```
kubectl apply -f cafe-secret.yaml
```

The TLS certificate and key in this secret are used to terminate the TLS connections for the cafe application.
**Important**: This certificate and key are for demo purposes only.

1. Create the `Gateway` resource:
```
kubectl apply -f gateway.yaml
```

This [gateway](./gateway.yaml) configures an `https` listener is to terminate TLS connections using the `cafe-secret` we created in the step 1.

1. Create the `HTTPRoute` resources:
```
kubectl apply -f cafe-routes.yaml
```

To configure HTTPS termination for our cafe application, we will bind the `https` listener to our `HTTPRoutes` in [cafe-routes.yaml](./cafe-routes.yaml) using the [`parentRef`](https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io%2fv1alpha2.ParentReference) field:

```yaml
parentRefs:
- name: gateway
namespace: default
sectionName: https
```

## 4. Test the Application

To access the application, we will use `curl` to send requests to the `coffee` and `tea` services.
Since our certificate is self-signed, we'll use curl's `--insecure` option to turn off certificate verification.

To get coffee:

```
curl --resolve cafe.example.com:$GW_HTTPS_PORT:$GW_IP https://cafe.example.com:$GW_HTTPS_PORT/coffee --insecure
Server address: 10.12.0.18:80
Server name: coffee-7586895968-r26zn
```

To get tea:

```
curl --resolve cafe.example.com:$GW_HTTPS_PORT:$GW_IP https://cafe.example.com:$GW_HTTPS_PORT/tea --insecure
Server address: 10.12.0.19:80
Server name: tea-7cd44fcb4d-xfw2x
```
37 changes: 37 additions & 0 deletions examples/https-termination/cafe-routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: coffee
spec:
parentRefs:
- name: gateway
sectionName: https
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /coffee
backendRefs:
- name: coffee
port: 80
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: tea
spec:
parentRefs:
- name: gateway
sectionName: https
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /tea
backendRefs:
- name: tea
port: 80
8 changes: 8 additions & 0 deletions examples/https-termination/cafe-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: cafe-secret
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNzakNDQVpvQ0NRQzdCdVdXdWRtRkNEQU5CZ2txaGtpRzl3MEJBUXNGQURBYk1Sa3dGd1lEVlFRRERCQmoKWVdabExtVjRZVzF3YkdVdVkyOXRNQjRYRFRJeU1EY3hOREl4TlRJek9Wb1hEVEl6TURjeE5ESXhOVEl6T1ZvdwpHekVaTUJjR0ExVUVBd3dRWTJGbVpTNWxlR0Z0Y0d4bExtTnZiVENDQVNJd0RRWUpLb1pJaHZjTkFRRUJCUUFECmdnRVBBRENDQVFvQ2dnRUJBTHFZMnRHNFc5aStFYzJhdnV4Q2prb2tnUUx1ek10U1Rnc1RNaEhuK3ZRUmxIam8KVzFLRnMvQVdlS25UUStyTWVKVWNseis4M3QwRGtyRThwUisxR2NKSE50WlNMb0NEYUlRN0Nhck5nY1daS0o4Qgo1WDNnVS9YeVJHZjI2c1REd2xzU3NkSEQ1U2U3K2Vab3NPcTdHTVF3K25HR2NVZ0VtL1Q1UEMvY05PWE0zZWxGClRPL051MStoMzROVG9BbDNQdTF2QlpMcDNQVERtQ0thaEROV0NWbUJQUWpNNFI4VERsbFhhMHQ5Z1o1MTRSRzUKWHlZWTNtdzZpUzIrR1dYVXllMjFuWVV4UEhZbDV4RHY0c0FXaGRXbElweHlZQlNCRURjczN6QlI2bFF1OWkxZAp0R1k4dGJ3blVmcUVUR3NZdWxzc05qcU95V1VEcFdJelhibHhJZVVDQXdFQUFUQU5CZ2txaGtpRzl3MEJBUXNGCkFBT0NBUUVBcjkrZWJ0U1dzSnhLTGtLZlRkek1ISFhOd2Y5ZXFVbHNtTXZmMGdBdWVKTUpUR215dG1i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RkgKcmppb21TUm1YNmxhaDk0SjRHU0lFZ0drNGw1SHhxZ3JGRDZ2UDd4NGRjUktJWFpLZ0w2dVJSSUpBb0dCQU1CVApaL2p5WStRNTBLdEtEZHUrYU9ORW4zaGxUN3hrNXRKN3NBek5rbWdGMU10RXlQUk9Xd1pQVGFJbWpRbk9qbHdpCldCZ2JGcXg0M2ZlQ1Z4ZXJ6V3ZEM0txaWJVbWpCTkNMTGtYeGh3ZEVteFQwVit2NzZGYzgwaTNNYVdSNnZZR08KditwVVovL0F6UXdJcWZ6dlVmV2ZxdStrMHlhVXhQOGNlcFBIRyt0bEFvR0FmQUtVVWhqeFU0Ym5vVzVwVUhKegpwWWZXZXZ5TW54NWZyT2VsSmRmNzlvNGMvMHhVSjh1eFBFWDFkRmNrZW96dHNpaVFTNkN6MENRY09XVWxtSkRwCnVrdERvVzM3VmNSQU1BVjY3NlgxQVZlM0UwNm5aL2g2Tkd4Z28rT042Q3pwL0lkMkJPUm9IMFAxa2RjY1NLT3kKMUtFZlNnb1B0c1N1eEpBZXdUZmxDMXc9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
65 changes: 65 additions & 0 deletions examples/https-termination/cafe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: coffee
spec:
replicas: 1
selector:
matchLabels:
app: coffee
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: coffee
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: coffee
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: coffee
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tea
spec:
replicas: 1
selector:
matchLabels:
app: tea
template:
metadata:
labels:
app: tea
spec:
containers:
- name: tea
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tea
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: tea
18 changes: 18 additions & 0 deletions examples/https-termination/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
labels:
domain: k8s-gateway.nginx.org
spec:
gatewayClassName: nginx
listeners:
- name: https
port: 443
protocol: HTTPS
tls:
mode: Terminate
certificateRefs:
- kind: Secret
name: cafe-secret
namespace: default
Loading