Skip to content

Commit 02b247e

Browse files
committed
Add documentation for TLS configuration of NLK- better titles
- tweaks - Add Under Development notice - prefer References section over inline links to external documentation
1 parent a24b64d commit 02b247e

12 files changed

+882
-0
lines changed

docs/tls/CA-MTLS.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Mutual TLS with Certificate Authority (CA) certificates
2+
3+
This mode allows NLK to verify it is connecting to the correct NGINX Plus instance, allows NGINX Plus to verify it is connecting to the correct NLK, and encrypts the data between NLK and NGINX Plus.
4+
5+
## Overview
6+
7+
Mutual TLS is used to encrypt the traffic between NLK and NGINX Plus, to ensure NLK verifies the NGINX Plus server, and to ensure NGINX Plus verifies NLK.
8+
9+
## Certificates
10+
11+
To configure this mode, the following certificates are required:
12+
13+
- Server Certificate
14+
- Client Certificate
15+
16+
See the following sections for instructions on how to create these certificates.
17+
18+
### Certificate Authority (CA)
19+
20+
Provided by the user.
21+
22+
### Server Certificate (NGINX Plus)
23+
24+
Use your own certificate authority (CA) to generate a server certificate and key.
25+
26+
### Client Certificate (NLK)
27+
28+
Use your own certificate authority (CA) to generate a client certificate and key.
29+
30+
## Kubernetes Secrets
31+
32+
NLK accesses the necessary certificates for each mode from Kubernetes Secrets. For this mode, the following Kubernetes Secret(s) are required:
33+
- Client Certificate
34+
35+
To create the Kubernetes Secret containing the CA certificate, refer to the [Kubernetes Secrets](./KUBERNETES-SECRETS.md) guide;
36+
the name and location of the certificate(s) created above should be used. The name of the Secret will be needed for the ConfigMap (discussed below).
37+
38+
## ConfigMap
39+
40+
41+
NLK is configured via a ConfigMap. The ConfigMap is named `nlk-config` and is located in the `nlk` namespace.
42+
43+
Depending on which mode is chosen, certain fields will need to be updated in the NLK ConfigMap.
44+
45+
For this mode, the `mode` and `clientCertificate` fields need to be included. The `mode` field should be set to `ca-mtls`
46+
and the `clientCertificate` field should be set to the name of the Kubernetes Secret containing the Client certificate created above.
47+
48+
The following is an example of a ConfigMap for this mode (be sure to update the `nginx-hosts` field with the correct NGINX Plus API endpoints):
49+
50+
```yaml
51+
apiVersion: v1
52+
kind: ConfigMap
53+
metadata:
54+
name: nlk-config
55+
namespace: nlk
56+
data:
57+
nginx-hosts: "http://10.1.1.4:9000/api,http://10.1.1.5:9000/api"
58+
mode: "ca-mtls"
59+
clientCertificate: "nlk-tls-client-secret"
60+
```
61+
62+
## Deployment
63+
64+
Save the above ConfigMap definition to a file named `ca-mtls-configmap.yaml`, then deploy the ConfigMap using the following command:
65+
66+
```bash
67+
kubectl apply -f docs/tls/ca-mtls-configmap.yaml
68+
```
69+
70+
## Configuring NGINX Plus
71+
72+
Refer to the [NGINX Plus Configuration](./NGINX-PLUS-CONFIGURATION.md) guide for instructions on configuring NGINX Plus to use the certificates created above.
73+
74+
The steps in both the ["One-way TLS"](./NGINX-PLUS-CONFIGURATION.md#one-way-tls) section and the ["Mutual TLS"](./NGINX-PLUS-CONFIGURATION.md#mutual-tls) section are required for this mode.
75+
76+
## Verification
77+
78+
To verify the ConfigMap was deployed correctly, run the following command:
79+
80+
```bash
81+
kubectl get configmap -n nlk nlk-config -o yaml
82+
```
83+
84+
The output should match the ConfigMap above.
85+
86+
To verify NLK is running, follow the instructions in either the [TCP](../tcp/tcp-installation-guide.md) or [HTTP](../http/http-installation-guide.md) guides.
87+

docs/tls/CA-TLS.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# One-way TLS with Certificate Authority (CA) certificates
2+
3+
This mode allows NLK to verify it is connecting to the correct NGINX Plus instance, and encrypts the data between NLK and NGINX Plus.
4+
5+
## Overview
6+
7+
One-way TLS is used to encrypt the traffic between NLK and NGINX Plus, and to ensure NLK verifies the NGINX Plus server;
8+
however, the NGINX Plus server _does not_ validate NLK.
9+
10+
## Certificates
11+
12+
To configure this mode, the following certificates are required:
13+
14+
- Server Certificate
15+
16+
See the following sections for instructions on how to create these certificates.
17+
18+
### Certificate Authority (CA)
19+
20+
Provided by the user.
21+
22+
### Server Certificate (NGINX Plus)
23+
24+
Use your certificate authority (CA) to generate a server certificate and key.
25+
26+
## Kubernetes Secrets
27+
28+
No Kubernetes Secrets are required for this mode.
29+
30+
## ConfigMap
31+
32+
NLK is configured via a ConfigMap. The ConfigMap is named `nlk-config` and is located in the `nlk` namespace.
33+
34+
Depending on which mode is chosen, certain fields will need to be updated in the NLK ConfigMap.
35+
36+
For this mode, only the `mode` fields needs to be included. The `mode` field should be set to `ca-tls`.
37+
38+
The following is an example of a ConfigMap for this mode (be sure to update the `nginx-hosts` field with the correct NGINX Plus API endpoints):
39+
40+
41+
```yaml
42+
apiVersion: v1
43+
kind: ConfigMap
44+
metadata:
45+
name: nlk-config
46+
namespace: nlk
47+
data:
48+
nginx-hosts: "http://10.1.1.4:9000/api,http://10.1.1.5:9000/api"
49+
mode: "ca-tls"
50+
```
51+
52+
## Deployment
53+
54+
Save the above ConfigMap definition to a file named `ca-tls-configmap.yaml`, then deploy the ConfigMap using the following command:
55+
56+
```bash
57+
kubectl apply -f docs/tls/ca-tls-configmap.yaml
58+
```
59+
60+
## Configuring NGINX Plus
61+
62+
Refer to the [NGINX Plus Configuration](./NGINX-PLUS-CONFIGURATION.md) guide for instructions on configuring NGINX Plus to use the certificates created above.
63+
64+
Only the steps in the ["One-way TLS"](./NGINX-PLUS-CONFIGURATION.md#one-way-tls) section are required for this mode.
65+
Use the certificate and key from your CA to configure NGINX Plus.
66+
67+
## Verification
68+
69+
To verify the ConfigMap was deployed correctly, run the following command:
70+
71+
```bash
72+
kubectl get configmap -n nlk nlk-config -o yaml
73+
```
74+
75+
The output should match the ConfigMap above.
76+
77+
To verify NLK is running, follow the instructions in either the [TCP](../tcp/tcp-installation-guide.md) or [HTTP](../http/http-installation-guide.md) guides.

docs/tls/CERTIFICATE-AUTHORITY.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generate a Certificate Authority (CA)
2+
3+
When using self-signed certificates, the first step is to generate the Certificate Authority (CA).
4+
5+
The following commands will generate the CA certificate and key:
6+
7+
```bash
8+
openssl req -newkey rsa:2048 -nodes -x509 -out ca.crt -keyout ca.key
9+
```
10+
11+
You will be prompted to enter the Distinguished Name (DN) information for the CA.
12+
13+
Alternatively, you can provide the DN information in a file, an example is shown below:
14+
15+
```bash
16+
[ req ]
17+
distinguished_name = dn
18+
prompt = no
19+
req_extensions = req_ext
20+
21+
[ req_ext ]
22+
basicConstraints = CA:TRUE
23+
keyUsage = critical, keyCertSign, cRLSign
24+
25+
[ dn ]
26+
C=[COUNTRY]
27+
ST=[STATE]
28+
L=[LOCALITY]
29+
O=[ORGANIZATION]
30+
OU=[ORGANIZATION_UNIT]
31+
```
32+
33+
Create a file using the above as a template and update the values in the `[ dn ]` section; then use following command to generate the CA certificate and key:
34+
35+
```bash
36+
openssl req -newkey rsa:2048 -nodes -x509 -config ca.cnf -out ca.crt -keyout ca.key
37+
```
38+
39+
The output of the above command will be the CA certificate (`ca.crt`) and key (`ca.key`).
40+
41+
## References
42+
43+
- [Distinguished Name reference](http://certificate.fyicenter.com/2098_OpenSSL_req_-distinguished_name_Configuration_Section.html)
44+

docs/tls/CLIENT-CERTIFICATE.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Generate a client certificate
2+
3+
When using self-signed certificates in the `ss-mtls` mode, a certificate needs to be generated for NLK.
4+
5+
The certificate has the same basic field as the CA certificate, with the addition of `clientAuth` in the `extendedKeyUsage` field:
6+
7+
```bash
8+
[ req ]
9+
distinguished_name = dn
10+
prompt = no
11+
12+
[ dn ]
13+
C=[COUNTRY]
14+
ST=[STATE]
15+
L=[LOCALITY]
16+
O=[ORGANIZATION]
17+
OU=[ORGANIZATION_UNIT]
18+
19+
[ client ]
20+
extendedKeyUsage = clientAuth
21+
```
22+
23+
Create a file using the above as a template and update the values in the `[ dn ]` section; then use following command to generate the certificate request and key:
24+
25+
```bash
26+
openssl genrsa -out client.key 2048
27+
openssl req -new -key client.key -config client.cnf -out client.csr
28+
```
29+
30+
The output of the above commands will be the client certificate request (`client.csr`) and key (`client.key`).
31+
32+
##### Sign the client certificate
33+
34+
```bash
35+
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -sha256 -extfile client.cnf -extensions client
36+
```
37+
38+
The output of the above command will be the client certificate (`client.crt`).
39+
40+
#### Verify the Client Certificate has the correct extendedKeyUsage
41+
42+
```bash
43+
openssl x509 -in client.crt -noout -purpose | grep 'SSL client :'
44+
```
45+
46+
Look for `SSL client : Yes` in the output.
47+
48+
## References
49+
50+
- [Distinguished Name reference](http://certificate.fyicenter.com/2098_OpenSSL_req_-distinguished_name_Configuration_Section.html)

docs/tls/DOCUMENT-HIERARCHY.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
```mermaid
2+
graph LR
3+
README[README.md]
4+
SS-TLS[SS-TLS.md]
5+
SS-MTLS[SS-MTLS.md]
6+
CA-TLS[CA-TLS.md]
7+
CA-MTLS[CA-MTLS.md]
8+
NO-TLS[NO-TLS.md]
9+
CERTIFICATE-AUTHORITY[CERTIFICATE-AUTHORITY.md]
10+
CLIENT-CERTIFICATE[CLIENT-CERTIFICATE.md]
11+
SERVER-CERTIFICATE[SERVER-CERTIFICATE.md]
12+
KUBERNETES-SECRETS[KUBERNETES-SECRETS.md]
13+
NGINX-PLUS-CONFIGURATION[NGINX-PLUS-CONFIGURATION.md]
14+
KUBERNETES-SECRETS[KUBERNETES-SECRETS.md]
15+
16+
subgraph "README.md"
17+
README
18+
end
19+
20+
subgraph "NO-TLS links"
21+
README --> NO-TLS
22+
end
23+
24+
subgraph "SS-TLS links"
25+
README --> SS-TLS
26+
SS-TLS --> CERTIFICATE-AUTHORITY
27+
SS-TLS --> SERVER-CERTIFICATE
28+
SS-TLS --> KUBERNETES-SECRETS
29+
SS-TLS --> NGINX-PLUS-CONFIGURATION
30+
end
31+
32+
subgraph "SS-MTLS links"
33+
README --> SS-MTLS
34+
SS-MTLS --> CERTIFICATE-AUTHORITY
35+
SS-MTLS --> SERVER-CERTIFICATE
36+
SS-MTLS --> CLIENT-CERTIFICATE
37+
SS-MTLS --> KUBERNETES-SECRETS
38+
SS-MTLS --> NGINX-PLUS-CONFIGURATION
39+
end
40+
41+
subgraph "CA-TLS links"
42+
README --> CA-TLS
43+
CA-TLS --> NGINX-PLUS-CONFIGURATION
44+
end
45+
46+
subgraph "CA-MTLS links"
47+
README --> CA-MTLS
48+
CA-MTLS --> KUBERNETES-SECRETS
49+
CA-MTLS --> NGINX-PLUS-CONFIGURATION
50+
end
51+
```

docs/tls/KUBERNETES-SECRETS.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Kubernetes Secrets
2+
3+
## Overview
4+
5+
Kubernetes Secrets are used to provide the required certificates to NLK. There are two ways to create the Secrets:
6+
- Using `kubectl`
7+
- Using yaml files
8+
9+
The filenames for the certificates created previously are required for both methods. The examples below assume the certificates were generated in `/tmp`
10+
and follow the naming conventions in the documentation.
11+
12+
## Using `kubectl`
13+
14+
The easiest way to create the secret is by using `kubectl`:
15+
16+
```bash
17+
kubectl create secret tls -n nlk nlk-tls-{ca,server,client}-secret --cert=/tmp/{ca,server,client}.crt --key=/tmp/{ca,server,client}.key
18+
```
19+
20+
## Using yaml files
21+
22+
The Secrets can also be created using yaml files. The following is an example of a yaml file for the Client Secret (note that the `data` values are truncated):
23+
24+
```yaml
25+
apiVersion: v1
26+
data:
27+
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVCVEN...
28+
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2Z0l...
29+
kind: Secret
30+
metadata:
31+
name: nlk-tls-client-secret
32+
type: kubernetes.io/tls
33+
```
34+
35+
Note: While it is possible to generate the values for `tls.crt` and `tls.key` manually, the above yaml can be generated using the following command:
36+
37+
```bash
38+
kubectl create secret tls -n nlk nlk-tls-{ca,server,client}-secret --cert=/tmp/{ca,server,client}.crt --key=/tmp/{ca,server,client}.key --dry-run=client -o yaml > {ca,server,client}-secret.yaml
39+
```
40+
41+
**Warning: it is important that these files do not make their way into a public repository or other storage location where they can be accessed by unauthorized users.**
42+
43+
44+
Once the yaml files are generated they can be applied using `kubectl`:
45+
46+
```bash
47+
kubectl apply -f {ca,server,client}-secret.yaml
48+
```
49+
50+
# Verification
51+
52+
The Secrets can be verified using `kubectl`:
53+
54+
```bash
55+
kubectl describe secret -n nlk nlk-tls-{ca,server,client}-secret
56+
```
57+
58+
The output should look similar to the example above.
59+
60+
To see the actual values of the certificates, the following command can be used:
61+
62+
```bash
63+
kubectl get secret -n nlk nlk-tls-ca-secret -o json | jq -r '.data["tls.crt"], .data["tls.key"]' | base64 -d
64+
```
65+
66+
Note that this requires `jq` to be installed.
67+
68+
## References
69+
70+
- [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/)
71+
- [kubectl dry run flags](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-dry-run-em-)

0 commit comments

Comments
 (0)