|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * /serverless/security/serverless-config-tls.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="serverless-enabling-tls-local-services_{context}"] |
| 7 | += Enabling TLS authentication for cluster local services |
| 8 | + |
| 9 | +For cluster local services, the Kourier local gateway `kourier-internal` is used. If you want to use TLS traffic against the Kourier local gateway, you must configure your own server certificates in the local gateway. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* You have installed the {ServerlessOperatorName} and Knative Serving. |
| 14 | +* You have administrator permissions. |
| 15 | +* You have installed the OpenShift (`oc`) CLI. |
| 16 | +
|
| 17 | +.Procedure |
| 18 | + |
| 19 | +. Deploy server certificates in the `knative-serving-ingress` namespace: |
| 20 | ++ |
| 21 | +[source,terminal] |
| 22 | +---- |
| 23 | +$ export san="knative" |
| 24 | +---- |
| 25 | ++ |
| 26 | +[NOTE] |
| 27 | +==== |
| 28 | +Subject Alternative Name (SAN) validation is required so that these certificates can serve the request to `<app_name>.<namespace>.svc.cluster.local`. |
| 29 | +==== |
| 30 | + |
| 31 | +. Generate a root key and certificate: |
| 32 | ++ |
| 33 | +[source,terminal] |
| 34 | +---- |
| 35 | +$ openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 \ |
| 36 | + -subj '/O=Example/CN=Example' \ |
| 37 | + -keyout ca.key \ |
| 38 | + -out ca.crt |
| 39 | +---- |
| 40 | + |
| 41 | +. Generate a server key that uses SAN validation: |
| 42 | ++ |
| 43 | +[source,terminal] |
| 44 | +---- |
| 45 | +$ openssl req -out tls.csr -newkey rsa:2048 -nodes -keyout tls.key \ |
| 46 | + -subj "/CN=Example/O=Example" \ |
| 47 | + -addext "subjectAltName = DNS:$san" |
| 48 | +---- |
| 49 | + |
| 50 | +. Create server certificates: |
| 51 | ++ |
| 52 | +[source,terminal] |
| 53 | +---- |
| 54 | +$ openssl x509 -req -extfile <(printf "subjectAltName=DNS:$san") \ |
| 55 | + -days 365 -in tls.csr \ |
| 56 | + -CA ca.crt -CAkey ca.key -CAcreateserial -out tls.crt |
| 57 | +---- |
| 58 | + |
| 59 | +. Configure a secret for the Kourier local gateway: |
| 60 | +.. Deploy a secret in `knative-serving-ingress` namespace from the certificates created by the previous steps: |
| 61 | ++ |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +$ oc create -n knative-serving-ingress secret tls server-certs \ |
| 65 | + --key=tls.key \ |
| 66 | + --cert=tls.crt --dry-run=client -o yaml | oc apply -f - |
| 67 | +---- |
| 68 | + |
| 69 | +.. Update the `KnativeServing` custom resource (CR) spec to use the secret that was created by the Kourier gateway: |
| 70 | ++ |
| 71 | +.Example KnativeServing CR |
| 72 | +[source,yaml] |
| 73 | +---- |
| 74 | +... |
| 75 | +spec: |
| 76 | + config: |
| 77 | + kourier: |
| 78 | + cluster-cert-secret: server-certs |
| 79 | +... |
| 80 | +---- |
| 81 | + |
| 82 | +The Kourier controller sets the certificate without restarting the service, so that you do not need to restart the pod. |
| 83 | + |
| 84 | +You can access the Kourier internal service with TLS through port `443` by mounting and using the `ca.crt` from the client. |
0 commit comments