Configure a Kubernetes build farm to use self-signed certificates
CI build pods can interact with servers using self-signed certificates.
CI build infrastructure pods can interact with servers using self-signed certificates. This option is useful for organizations that prefer to use internal certificates instead of certificates generated by a public Certificate Authority (CA).
Custom certificates or self-signed certificates are only supported for linux nodes in a Kubernetes cluster. For Windows, directly mounting the certificate to the destination path will not work.
Enable self-signed certificates
Create a Kubernetes secret or config map with the required certificates in the same namespace used by the Harness Delegate. For example:
apiVersion: v1 kind: Secret metadata: name: addcerts namespace: harness-delegate-ng type: Opaque stringData: ca.bundle: | -----BEGIN CERTIFICATE----- XXXXXXXXXXXXXXXXXXXXXXXXXXX -----END CERTIFICATE------- -----BEGIN CERTIFICATE----- XXXXXXXXXXXXXXXXXXXXXXXXXXX -----END CERTIFICATE-------Mount the secret as a volume on the delegate pod and add a
volumeMountto your certificate files at/opt/harness-delegate/ca-bundle.In the delegate pod, do the following:
Provide a comma-separated list of paths in the build pod where you want the certs to be mounted.
Mount your certificate files to
/opt/harness-delegate/ca-bundle.
To mount the secret, go to the delegate
DeploymentYAML and updatevolumeMountsandvolumes. For an example, expand the section below.Both CI build pods and the SCM client on the delegate support this method.
Restart the delegate. Once it is up and running,
execinto the container and ensure that the volume exists at the mounted path and contains your certificates.
Enable self-signed certificates with a self-hosted image registry (advanced)
Create a Kubernetes secret or config map with the required certificates in the same namespace used by the Harness delegate. For example:
Mount the secret as a volume on the delegate pod.
In the delegate pod, do the following:
Add
DESTINATION_CA_PATHto the environment.Provide a comma-separated list of paths in the build pod where you want the certs to be mounted.
Mount your certificate files to
/opt/harness-delegate/ca-bundle.
To add
DESTINATION_CA_PATHand mount the secret, go to the delegateDeploymentYAML and updateenv,volumeMounts, andvolumes. For an example, expand the section below.Both CI build pods and the SCM client on the delegate support this method.
Make sure the destination path is not same as the default CA certificate path of the corresponding container image.
If you override the default certificate file, make sure the Kubernetes secret or config map (from step one) includes all certificates required by the pipelines that will use this build infrastructure.
If you're storing your certificates in a local registry and need to run Docker-in-Docker, specify the local certificate path on the delegate.
For example, if your self-signed certs are stored at
https://my-registry.local.org:799and you log in withdocker login my-registry.local.org:799, then you add the path to yourDESTINATION_CA_PATHenvironment like this:Restart the delegate. Once it's up and running,
execinto the container and ensure that the volume exists at the mounted path and contains your certificates.
Secret Name Creation for Certificate Bundles in Build Pods
When a customer mounts a certificate bundle in their build pods, the bundle is created as a secret and mounted in the pod.
The secret names follow a specific format: Podname-filename-hash.
For Example:- Pod Name: harnessci-buildpod-9rwcbkl6 Secret Name: harnessci-buildpod-9rwcbkl6-custom-cr-pem-0-pem-1667255857 Here, custom-cr-pem is the pem file name and 1667255857 is the random hash that is generated during secret creation.
The name is sanitized to comply with Kubernetes naming conventions. If the total length exceeds 63 characters, it is trimmed from the end to ensure compliance.
Using Dockerfile builds with self-signed certificates (BuildKit-specific)
When using the Build and Push to Docker step (or any step that performs Dockerfile builds using BuildKit), mounting CA certificates to the Delegate is not enough. BuildKit must be explicitly configured to trust your private registry's certificate.
This workaround is only required for Build and Push to Docker steps using Docker BuildKit. Steps using Kaniko, like most default Kubernetes builds in Harness, do not require this additional configuration if the certificate is already mounted using DESTINATION_CA_PATH.
To make BuildKit trust your self-signed registry certs, you need to:
Dynamically prepare the BuildKit config and cert path in a
Runstep.Share the cert and config path using
sharedPathsand environment variables.Concatenate multiple PEM files (if applicable) into a single CA bundle used by both Docker and BuildKit.
Step-by-step example
Run step to prepare certs and BuildKit config
Here is an example Run step that uses CA certs already mounted into the Delegate and build pod (e.g., via volume mounts to /harness-shared-certs-path), prepares the BuildKit config file, and builds a Dockerfile
Build step using the config
This ensures that BuildKit inside your pipeline trusts the self-signed certificate used by your private registry.
Troubleshoot Kubernetes cluster build infrastructures
Go to the CI Knowledge Base for questions and issues related to Kubernetes cluster build infrastructures, including use of self-signed certificates, such as:
Last updated
Was this helpful?