Using self-signed certificates in CloudBees CI on OpenShift


OpenShift 3.10 or later, with the MutatingAdmissionWebhook admission controller enabled.

To check whether the admission controller is enabled for your cluster, run the following command:

$ oc api-versions | grep

The result should be:

When using OpenShift 3.x, add them to the master-config.yaml file as follows:

        kind: DefaultAdmissionConfig
        apiVersion: v1
        disable: false
        kind: DefaultAdmissionConfig
        apiVersion: v1
        disable: false

Network requirements

The sidecar injector listens to HTTPS requests on port 443, and the firewall rules of that port must be configured accordingly:



Kubernetes Master(s)

Kubernetes Nodes


Allow incoming requests from sidecar-injector pod(s)



Kubernetes Nodes

Kubernetes Master(s)


Allow kubernetes master to communicate with sidecar-injector pod(s)

Installing self-signed certificates on OpenShift

This procedure requires a context with the cluster-admin privilege in order to create the MutatingWebhookConfiguration.

The following instructions assume that the working directory is the sidecar-injector subdirectory in the CloudBees CI archive.

Creating a certificate bundle

These instructions assume that you are working in the project where CloudBees CI is installed, and that the certificate you want to install is named mycertificate.pem.

If you are using a self-signed certificate, add the certificate itself. If you are using a certificate issued by a custom root CA, add the root CA itself.

  1. Copy reference files locally:

    $ oc cp cjoc-0:/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ./ca-certificates.crt
    $ oc cp cjoc-0:/etc/pki/ca-trust/extracted/java/cacerts ./cacerts

    On earlier versions, or when overriding the Docker image selection to use the Alpine base:

    $ oc cp cjoc-0:/etc/ssl/certs/ca-certificates.crt ./ca-certificates.crt
    $ oc cp cjoc-0:/etc/ssl/certs/java/cacerts ./cacerts
  2. Add the root CA to the system certificate bundle:

    $ cat mycertificate.pem >> ca-certificates.crt
  3. Add the root CA to the Java cacerts:

    $ keytool -import -noprompt -keystore cacerts -file mycertificate.pem -storepass changeit -alias service-mycertificate;
Make sure that mycertificate.pem contains only one certificate. keytool does not support importing multiple certificates from a single file.
  1. Create a configmap using the two files above:

    $ oc create configmap --from-file=ca-certificates.crt,cacerts ca-bundles

Setting up the injector

  1. Browse to the directory where the CloudBees CI archive has been unpacked, and navigate to the sidecar-injector sub-folder.

  2. Create a project to deploy the sidecar injector:

    $ oc new-project sidecar-injector
  3. Create a signed certificate/key pair and store it in an OpenShift secret that will be consumed by the sidecar deployment:

    $ ./ \
    --service sidecar-injector-webhook-svc \
    --secret sidecar-injector-webhook-certs \
    --namespace sidecar-injector
  4. Patch the MutatingWebhookConfiguration by configuring the caBundle with the correct value from the OpenShift cluster:

    $ cat sidecar-injector.yaml | \ > \
  5. Switch to the sidecar-injector project:

    $ oc project sidecar-injector
  6. Deploy resources:

    $ oc create -f sidecar-injector-ca-bundle.yaml
  7. Verify that the sidecar-inject-webhook pod is running:

    $ oc get pods
    NAME                                                  READY     STATUS    RESTARTS   AGE
    sidecar-injector-webhook-deployment-bbb689d69-882dd   1/1       Running   0          5m
    $ oc get deployment
    NAME                                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    sidecar-injector-webhook-deployment   1         1         1            1           5m

Configuring namespace

  1. Label the namespace where CloudBees CI is installed with sidecar-injector=enabled:

    $ oc label namespace mynamespace sidecar-injector=enabled
  2. Check the configuration:

    $ oc get namespace -L sidecar-injector
    default       Active    18h
    mynamespace   Active    18h       enabled
    kube-public   Active    18h
    kube-system   Active    18h

Verifying the namespace

  1. Switch to the CloudBees CI project:

    $ oc project mynamespace
  2. Deploy an app in the OpenShift cluster. For example, the sleep app:

    # cat <<EOF | oc create -f -
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: sleep
    replicas: 1
    	  app: sleep
    	- name: sleep
    	  image: tutum/curl
    	  command: ["/bin/sleep","infinity"]
  3. Verify that injection has occurred:

    $ oc get pods -o 'go-template={{range .items}}{{}}{{"\n"}}{{range $key,$value := .metadata.annotations}}* {{$key}}: {{$value}}{{"\n"}}{{end}}{{"\n"}}{{end}}'
          * com.cloudbees.sidecar-injector/status: injected


You can now use your custom CA across your cluster.

To apply the new certificate bundle, restart operations center and any running Managed Masters. When new build agents are scheduled, the certificate bundle is automatically applied and permits connection to remote endpoints using your certificates.

Advanced configuration

Disabling Injection on a specific pod

To disable implicit injection for a specific pod, annotate it with com.cloudbees.sidecar-injector/inject: no

Making injection explicit

By default, injection is implicit and applies to all pods created in the labelled namespace(s). However, you can alternately enable injection on only the pod(s) that explicitly require it.

To make injection explicit for a given pod:

  1. Edit the sidecar-injector-webhook-configmap configmap and specify requiresExplicitInjection: true.

  2. To enable injection on a specific pod, annotate the pod with com.cloudbees.sidecar-injector/inject: yes.