|
| 1 | +--- |
| 2 | +title: Control Plane and Data Plane Authentication |
| 3 | +weight: 300 |
| 4 | +toc: true |
| 5 | +type: how-to |
| 6 | +product: NGF |
| 7 | +docs: DOCS-0000 |
| 8 | +--- |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +By default, NGINX Gateway Fabric installs self-signed certificates to secure the connection between the NGINX Gateway Fabric control plane and the NGINX data plane Pods. These certificates are created by a `cert-generator` Job when NGINX Gateway Fabric is first installed. However, because these certificates are self-signed and will expire after 3 years, it is recommended to use a solution such as [cert-manager](https://cert-manager.io) to create and manage these certificates in a production environment. |
| 13 | + |
| 14 | +This guide will step through how to install and use `cert-manager` to secure this connection. **This should be done _before_ you install NGINX Gateway Fabric.** |
| 15 | + |
| 16 | +## Before you begin |
| 17 | + |
| 18 | +You need: |
| 19 | + |
| 20 | +- Administrator access to a Kubernetes cluster. |
| 21 | +- [Helm](https://helm.sh) and [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) must be installed locally. |
| 22 | + |
| 23 | +## Install cert-manager |
| 24 | + |
| 25 | +- Add the Helm repository. |
| 26 | + |
| 27 | + ```shell |
| 28 | + helm repo add jetstack https://charts.jetstack.io |
| 29 | + helm repo update |
| 30 | + ``` |
| 31 | + |
| 32 | +- Install cert-manager: |
| 33 | + |
| 34 | + ```shell |
| 35 | + helm install \ |
| 36 | + cert-manager jetstack/cert-manager \ |
| 37 | + --namespace cert-manager \ |
| 38 | + --create-namespace \ |
| 39 | + --set config.apiVersion="controller.config.cert-manager.io/v1alpha1" \ |
| 40 | + --set config.kind="ControllerConfiguration" \ |
| 41 | + --set config.enableGatewayAPI=true \ |
| 42 | + --set crds.enabled=true |
| 43 | + ``` |
| 44 | + |
| 45 | + This also enables Gateway API features for cert-manager, which can be useful for [securing your workload traffic]({{< ref "/ngf/how-to/traffic-security/integrating-cert-manager.md" >}}). |
| 46 | + |
| 47 | +## Create CA Issuer |
| 48 | + |
| 49 | +The first step is to create the CA Issuer. |
| 50 | + |
| 51 | +{{< note >}} This example uses a self-signed Issuer, which should not be used in production environments. For production environments, you should use a real [CA issuer](https://cert-manager.io/docs/configuration/ca/). {{< /note >}} |
| 52 | + |
| 53 | +Create the namespace: |
| 54 | + |
| 55 | +```shell |
| 56 | +kubectl create namespace nginx-gateway |
| 57 | +``` |
| 58 | + |
| 59 | +```yaml |
| 60 | +kubectl apply -f - <<EOF |
| 61 | +apiVersion: cert-manager.io/v1 |
| 62 | +kind: Issuer |
| 63 | +metadata: |
| 64 | + name: selfsigned-issuer |
| 65 | + namespace: nginx-gateway |
| 66 | +spec: |
| 67 | + selfSigned: {} |
| 68 | +--- |
| 69 | +apiVersion: cert-manager.io/v1 |
| 70 | +kind: Certificate |
| 71 | +metadata: |
| 72 | + name: nginx-gateway-ca |
| 73 | + namespace: nginx-gateway |
| 74 | +spec: |
| 75 | + isCA: true |
| 76 | + commonName: nginx-gateway |
| 77 | + secretName: nginx-gateway-ca |
| 78 | + privateKey: |
| 79 | + algorithm: RSA |
| 80 | + size: 2048 |
| 81 | + issuerRef: |
| 82 | + name: selfsigned-issuer |
| 83 | + kind: Issuer |
| 84 | + group: cert-manager.io |
| 85 | +--- |
| 86 | +apiVersion: cert-manager.io/v1 |
| 87 | +kind: Issuer |
| 88 | +metadata: |
| 89 | + name: nginx-gateway-issuer |
| 90 | + namespace: nginx-gateway |
| 91 | +spec: |
| 92 | + ca: |
| 93 | + secretName: nginx-gateway-ca |
| 94 | +EOF |
| 95 | +``` |
| 96 | + |
| 97 | +## Create Server and Client Certificates |
| 98 | + |
| 99 | +Now we can create the Certificate resources for the NGINX Gateway Fabric control plane (server) and the NGINX agent (client). |
| 100 | + |
| 101 | +The `dnsName` field in the server Certificate represents the name that the NGINX Gateway Fabric control plane service will have once you install it. This name depends on your method of installation. |
| 102 | + |
| 103 | +{{<tabs name="ngf-name">}} |
| 104 | + |
| 105 | +{{%tab name="Helm"%}} |
| 106 | + |
| 107 | +The full service name is of the format: `<helm-release-name>-nginx-gateway-fabric.<namespace>.svc`. |
| 108 | + |
| 109 | +The default helm release name used in our installation docs is `ngf`, and the default namespace is `nginx-gateway`, so the `dnsName` should be `ngf-nginx-gateway-fabric.nginx-gateway.svc`. |
| 110 | + |
| 111 | +{{% /tab %}} |
| 112 | + |
| 113 | +{{%tab name="Manifests"%}} |
| 114 | + |
| 115 | +The full service name is of the format: `<service-name>.<namespace>.svc`. |
| 116 | + |
| 117 | +By default, the base service name is `nginx-gateway`, and the namespace is `nginx-gateway`, so the `dnsName` should be `nginx-gateway.nginx-gateway.svc`. |
| 118 | + |
| 119 | +{{% /tab %}} |
| 120 | + |
| 121 | +{{</tabs>}} |
| 122 | + |
| 123 | +```yaml |
| 124 | +kubectl apply -f - <<EOF |
| 125 | +apiVersion: cert-manager.io/v1 |
| 126 | +kind: Certificate |
| 127 | +metadata: |
| 128 | + name: nginx-gateway |
| 129 | + namespace: nginx-gateway |
| 130 | +spec: |
| 131 | + secretName: server-tls |
| 132 | + usages: |
| 133 | + - digital signature |
| 134 | + - key encipherment |
| 135 | + dnsNames: |
| 136 | + - ngf-nginx-gateway-fabric.nginx-gateway.svc # this value may need to be updated |
| 137 | + issuerRef: |
| 138 | + name: nginx-gateway-issuer |
| 139 | +EOF |
| 140 | +``` |
| 141 | + |
| 142 | +```yaml |
| 143 | +kubectl apply -f - <<EOF |
| 144 | +apiVersion: cert-manager.io/v1 |
| 145 | +kind: Certificate |
| 146 | +metadata: |
| 147 | + name: nginx |
| 148 | + namespace: nginx-gateway |
| 149 | +spec: |
| 150 | + secretName: agent-tls |
| 151 | + usages: |
| 152 | + - "digital signature" |
| 153 | + - "key encipherment" |
| 154 | + dnsNames: |
| 155 | + - "*.cluster.local" |
| 156 | + issuerRef: |
| 157 | + name: nginx-gateway-issuer |
| 158 | +EOF |
| 159 | +``` |
| 160 | + |
| 161 | +Since the TLS Secrets are mounted into each Pod that uses them, the NGINX agent (client) Secret is duplicated by the NGINX Gateway Fabric control plane into whichever namespace NGINX is deployed into. All updates to the source Secret are propagated to the duplicate Secrets. |
| 162 | + |
| 163 | +The name of the agent Secret is provided to the NGINX Gateway Fabric control plane via the command-line. `agent-tls` is the default name, but if you wish to use a different name, you can provide it when installing NGINX Gateway Fabric: |
| 164 | + |
| 165 | +{{<tabs name="tls-secret-names">}} |
| 166 | + |
| 167 | +{{%tab name="Helm"%}} |
| 168 | + |
| 169 | +Specify the Secret name using the `certGenerator.agentTLSSecretName` helm value. |
| 170 | + |
| 171 | +{{% /tab %}} |
| 172 | + |
| 173 | +{{%tab name="Manifests"%}} |
| 174 | + |
| 175 | +Specify the Secret name using the `agent-tls-secret` command-line argument. |
| 176 | + |
| 177 | +{{% /tab %}} |
| 178 | + |
| 179 | +{{</tabs>}} |
| 180 | + |
| 181 | +## Final steps |
| 182 | + |
| 183 | +You should see the Secrets created in the `nginx-gateway` namespace: |
| 184 | + |
| 185 | +```shell |
| 186 | +kubectl -n nginx-gateway get secrets |
| 187 | +``` |
| 188 | + |
| 189 | +```text |
| 190 | +agent-tls kubernetes.io/tls 3 3s |
| 191 | +nginx-gateway-ca kubernetes.io/tls 3 15s |
| 192 | +server-tls kubernetes.io/tls 3 8s |
| 193 | +``` |
| 194 | + |
| 195 | +**You can now [install NGINX Gateway Fabric]({{< ref "/ngf/installation/installing-ngf" >}}).** |
0 commit comments