About using signed certificates with secrets
To secure communication to your service, you can configure Red Hat OpenShift Container Platform to generate a signed serving certificate/key pair that you can add into a secret in a project.
A service serving certificate secret is intended to support complex middleware applications that need out-of-the-box certificates. It has the same settings as the server certificates generated by the administrator tooling for nodes and masters.
Pod spec configured for a service serving certificates secret.apiVersion: v1
kind: Service
metadata:
name: registry
annotations:
service.beta.openshift.io/serving-cert-secret-name: registry-cert
# ...
Replace registry-cert with a name for the certificate
Other pods can trust cluster-created certificates (which are only signed for internal DNS names), by using the CA bundle in the /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt file that is automatically mounted in their pod.
The signature algorithm for this feature is x509.SHA256WithRSA. To manually
rotate, delete the generated secret. A new certificate is created.
Generating signed certificates for use with secrets
You can use a signed serving certificate/key pair with a pod by adding
the service.beta.openshift.io/serving-cert-secret-name annotation to the service, then add the secret to the pod.
Use the following procedure to create a service serving certificate secret.
-
Edit the
Podspec for your service. -
Add the
service.beta.openshift.io/serving-cert-secret-nameannotation with the name you want to use for your secret.kind: Service apiVersion: v1 metadata: name: my-service annotations: service.beta.openshift.io/serving-cert-secret-name: my-certspec: selector: app: MyApp ports: - protocol: TCP port: 80 targetPort: 9376
Replace
my-certwith the name for the secret. The certificate and key are in PEM format, stored intls.crtandtls.keyrespectively. -
Create the service:
$ oc create -f <file-name>.yaml -
View the secret to make sure it was created:
-
View a list of all secrets:
$ oc get secretsExample outputNAME TYPE DATA AGE my-cert kubernetes.io/tls 2 9m -
View details on your secret:
$ oc describe secret my-certExample outputName: my-cert Namespace: openshift-console Labels: <none> Annotations: service.beta.openshift.io/expiry: 2023-03-08T23:22:40Z service.beta.openshift.io/originating-service-name: my-service service.beta.openshift.io/originating-service-uid: 640f0ec3-afc2-4380-bf31-a8c784846a11 service.beta.openshift.io/expiry: 2023-03-08T23:22:40Z Type: kubernetes.io/tls Data ==== tls.key: 1679 bytes tls.crt: 2595 bytes
-
-
Edit your
Podspec with that secret.apiVersion: v1 kind: Pod metadata: name: my-service-pod spec: securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault containers: - name: mypod image: redis volumeMounts: - name: my-container mountPath: "/etc/my-path" securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] volumes: - name: my-volume secret: secretName: my-cert items: - key: username path: my-group/my-username mode: 511When it is available, your pod will run. The certificate will be good for the internal service DNS name,
<service.name>.<service.namespace>.svc.The certificate/key pair is automatically replaced when it gets close to expiration. View the expiration date in the
service.beta.openshift.io/expiryannotation on the secret, which is in RFC3339 format.In most cases, the service DNS name
<service.name>.<service.namespace>.svcis not externally routable. The primary use of<service.name>.<service.namespace>.svcis for intracluster or intraservice communication, and with re-encrypt routes.