Zero-trust environments assume that every interaction begins in an untrusted state. Users can access only files or objects that are specifically allowed; communication must be encrypted; and client applications must verify the authenticity of servers.
By default, OpenShift encrypts network traffic between nodes and the control plane, and prevents external entities from reading internal traffic. This encryption provides stronger security than default Kubernetes, which does not automatically encrypt internal traffic. Although the control plane traffic is encrypted, applications in OpenShift do not necessarily verify the authenticity of other applications or encrypt application traffic.
Zero-trust environments require that a trusted certificate authority (CA) signs the certificates that are used to encrypt traffic. By referencing the CA certificate, an application can cryptographically verify the authenticity of another application with a signed certificate.
OpenShift provides the service-ca controller to generate and sign service certificates for internal traffic.
The service-ca controller creates a secret that it populates with a signed certificate and key.
A deployment can mount this secret as a volume to use the signed certificate.
Additionally, client applications need to trust the service-ca controller CA.
To generate a certificate and key pair, apply the service.beta.openshift.io/serving-cert-secret-name= annotation to a service.
The your-secretservice-ca controller creates the secret in the same namespace if it does not exist, and populates it with a signed certificate and key pair for the service.your-secret
[user@host ~]$oc annotate servicehello\service.beta.openshift.io/serving-cert-secret-name=
hello-secretservice/hello annotated
The | |
The secret that contains the certificate and key pair is named |
After OpenShift generates the secret, you must mount the secret in the application deployment. The location to place the certificate and key is application-dependent. The following YAML patch is for an NGINX deployment:
spec:
template:
spec:
containers:
- name: hello
volumeMounts:
- name: hello-volume
mountPath: /etc/pki/nginx/
volumes:
- name: hello-volume
secret:
defaultMode: 420
secretName: hello-secret
items:
- key: tls.crt
path: server.crt
- key: tls.key
path: private/server.key 
Defining the volume as | |
The application-specific mount path. | |
The read-write permissions that the application recommends. | |
The secret that the earlier annotation defined. | |
The secret has | |
The application-specific destinations for the certificate and key. |
After mounting the secret to the application container, the application can use the signed certificate for TLS traffic.
For a client service application to verify the validity of a certificate, the application needs the CA bundle that signed that certificate.
The service-ca controller injects the CA bundle when you apply the service.beta.openshift.io/inject-cabundle=true annotation to an object.
You can apply the annotation to configuration maps, API services, custom resource definitions (CRD), mutating webhooks, and validating webhooks.
Apply the service.beta.openshift.io/inject-cabundle=true annotation to a configuration map to inject the CA bundle into the data: { service-ca.crt } field.
The service-ca controller replaces all data in the selected configuration map with the CA bundle.
You must therefore use a dedicated configuration map to prevent overwriting existing data.
[user@host ~]$ oc annotate configmap ca-bundle \
service.beta.openshift.io/inject-cabundle=true
configmap/ca-bundle annotatedApplying the annotation to an API service injects the CA bundle into the spec.caBundle field.
Applying the annotation to a CRD injects the CA bundle into the spec.conversion.webhook.clientConfig.caBundle field.
Applying the annotation to a mutating webhook or validating webhook injects the CA bundle into the clientConfig.caBundle field.
The service CA certificate is valid for 26 months by default and is automatically rotated after 13 months. After rotation is a 13-month grace period where the original CA certificate is still valid. During this grace period, each pod that is configured to trust the original CA certificate must be restarted in some way. A service restart automatically injects the new CA bundle.
You can also manually rotate the certificate for the service CA and for generated service certificates.
To rotate a generated service certificate, delete the existing secret, and the service-ca controller automatically generates a new one.
[user@host ~]$ oc delete secret certificate-secret
secret/certificate-secret deletedTo manually rotate the service CA certificate, delete the signing-key secret in the openshift-service-ca namespace.
[user@host ~]$ oc delete secret/signing-key -n openshift-service-ca
secret/signing-key deletedThis process immediately invalidates the former service CA certificate. You must restart all pods that use it, for TLS to function.
Other options can handle TLS encryption inside an OpenShift cluster, such as a service mesh or the certmanager operator.
You can use the certmanager operator to delegate the certificate signing process to a trusted external service, and also to renew a certificate.
You can also use Red Hat OpenShift Service Mesh for encrypted service-to-service communication and for other advanced features. Service mesh is an advanced topic and is not covered in the course.
You can modify objects in OpenShift in a repeatable way with the oc patch command.
The oc patch command updates or adds fields in an existing object from a provided JSON or YAML snippet or file.
A software developer might distribute a patch file or snippet to fix problems before a full update is available.
To patch an object from a snippet, use the oc patch command with the -p option and the snippet.
The following example updates the hello deployment to have a CPU resource request of 100m with a JSON snippet:
[user@host ~]$ oc patch deployment hello -p \
'{"spec":{"template":{"spec":{"resources":{"requests":{"cpu": "100m"}}}}}}'
deployment/hello patchedTo patch an object from a patch file, use the oc patch command with the --patch-file option and the location of the patch file.
The following example updates the hello deployment to include the content of the ~/volume-mount.yaml patch file:
[user@host ~]$ oc patch deployment hello --patch-file ~/volume-mount.yaml
deployment.apps/hello patchedThe contents of the patch file describe mounting a persistent volume claim as a volume:
spec:
template:
spec:
containers:
- name: hello
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html/
volumes:
- name: www
persistentVolumeClaim:
claimName: nginx-wwwThis patch results in the following manifest for the hello deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: hello ...output omitted... spec: ...output omitted... template: ...output omitted... spec: containers: ...output omitted... name: server ...output omitted... volumeMounts: -mountPath: /usr/share/nginx/html/ name: www- mountPath: /etc/nginx/conf.d/ name: tls-conf ...output omitted... volumes: - configMap: defaultMode: 420 name: tls-conf name: tls-conf -persistentVolumeClaim: claimName: nginx-www name: www...output omitted...
The patch applies to the hello deployment regardless of whether the www volume mount exists.
The oc patch command modifies existing fields in the object that are specified in the patch.
If the beginning state of the hello deployment already contains data as follows, then the end result is the same as if the fields do not exist:
apiVersion: apps/v1 kind: Deployment metadata: name: hello ...output omitted... spec: ...output omitted... template: ...output omitted... spec: containers: ...output omitted... name: server ...output omitted... volumeMounts: - mountPath:/usr/share/nginx/www/name: www - mountPath: /etc/nginx/conf.d/ name: tls-conf ...output omitted... volumes: - configMap: defaultMode: 420 name: tls-conf name: tls-conf - persistentVolumeClaim: claimName:
deprecated-wwwname: www ...output omitted...
For more information about service certificates, refer to the Securing Service Traffic Using Service Serving Certificate Secrets section in the Configuring Certificates chapter in the Red Hat OpenShift Container Platform 4.14 Security and Compliance documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/security_and_compliance#add-service-serving
For more information about service mesh, refer to the About OpenShift Service Mesh section in the Service Mesh 2.x chapter in the Red Hat OpenShift Container Platform 4.14 Service Mesh documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/service_mesh#ossm-about
For more information about the cert-manager operator, refer to the cert-manager Operator for Red Hat OpenShift chapter in the Red Hat OpenShift Container Platform 4.14 Security and Compliance documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/security_and_compliance#cert-manager-operator-for-red-hat-openshift
For more information about the oc patch command, refer to the oc patch section in the OpenShift CLI Developer Command Reference chapter in the Red Hat OpenShift Container Platform 4.14 CLI Tools documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/cli_tools/index#oc-patch