cloudbees-sidecar-injector

by CloudBees

Helm chartv496.0.0+82f012f86ec9App 496.82f012f86ec9

Helm chart for sidecar injector webhook deployment

About this chart

Using self-signed certificates in Cloudbees CI

This optional component of Cloudbees CI allows using self-signed certificates or custom root CA without having to build custom images.

Prerequisites

Kubernetes 1.21 or later is required.

Installation

This procedure requires the ability to install helm charts.

Create a certificate bundle

Assuming you are working in the namespace where Cloudbees CI is installed, and the certificate you want to install is named mycertificate.pem.

For a self-signed certificate, add the certificate itself. If the certificate has been issued from a custom root CA, add the root CA itself.

  1. Copy reference files locally

    kubectl cp cjoc-0:etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ./ca-certificates.crt
    kubectl cp cjoc-0:etc/pki/ca-trust/extracted/java/cacerts ./cacerts
    
  2. Add root CA to system certificate bundle

    cat mycertificate.pem >> ca-certificates.crt
    
  3. Add root CA to java cacerts

    keytool -import -noprompt -keystore cacerts -file mycertificate.pem -storepass changeit -alias service-mycertificate;
    
  4. Create a configmap with the two files above

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

Setup injector

  1. Create a namespace to deploy the sidecar injector

    kubectl create namespace sidecar-injector
    
  2. Review chart values

    helm inspect values cloudbees/cloudbees-sidecar-injector
    

    In particular, pay attention to the caBundleCrt field if your kubernetes cluster has been set up to use a different signing cert than the root CA used for api server.

  3. Install the Cloudbees sidecar injector using helm. Inspect the possible values using

    helm install cloudbees/cloudbees-sidecar-injector --name cloudbees-sidecar-injector --namespace cloudbees-sidecar-injector
    

Configure namespace

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

    kubectl label namespace mynamespace sidecar-injector=enabled
    
  2. Check

    # kubectl get namespace -L sidecar-injector
    NAME          STATUS    AGE       SIDECAR-INJECTOR
    default       Active    18h
    mynamespace   Active    18h       enabled
    kube-public   Active    18h
    kube-system   Active    18h
    

Verify

  1. Deploy an app in Kubernetes cluster, take sleep app as an example

    kubectl run sleep --image curlimages/curl --command /bin/sleep infinity
    
  2. Verify injection has happened

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

Conclusion

You are now all set to use your custom CA. If you restart CJOC and running masters, they will pick up the new certificate bundle. When scheduling new build agents, they will also pick up the certificate bundle and allow connection to remote endpoints using your certificates.

FAQ

Disable injection for a specific pod

Annotate the pod com.cloudbees.sidecar-injector/inject: no

Injection doesn't work and pod has tls errors.

The sidecar-injector logs contains the following http: TLS handshake error from aaa.bbb.ccc.ddd:nnnnn: remote error: tls: bad certificate

This can happen if the API server TLS certificate differs from the cluster signing certificate. To fix this, you need to provide the cluster signing certificate as an input to the installation.

Create a values.yaml file as follow (replace the content by your own CA cert)

caBundleCrt: |-
  -----BEGIN CERTIFICATE-----
  MIICyDCCAbCgAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl
  cm5ldGVzMB4XDTE5MDcyOTA3MzQyMloXDTI5MDcyNjA3MzQyMlowFTETMBEGA1UE
  AxMKa3ViZXJuZXRlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALgQ
  fjIm8iVEpmX3tlcUzuH2BAQGzK0utC6S0hhqnK6zlQ9iGDAwDpAiwGB9VzcJSfK7
  fr3rx4zT9rWfVeot+ARQV/NPxSUpPlGK8WsRleg5wKyUdnE1xKZDly2l2Vpqlr0J
  GnMXb2A0roi685XZo6iQALLfo+rtWQ2y2JLXzGYYCB1sAUX3hM3qbYmIMReBIyMX
  YGUUdaMuWU1YazKy3eJ84Am7l9ZXlMm7infJlAFsM3BCKed9ZxO2KxTvhWv1qbUk
  Bj3GJrL2bJfQi3B6h0piiBDt6YeI3U8yU4EyxtMKQwQXs9T1zHloc6RmVGYYVAEl
  HquW/XIk4ebWTxYND6UCAwEAAaMjMCEwDgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB
  /wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBABsJvnyo14a8FR6y4JGSX1SXSmtS
  uRiWH6qo5Ou+4zIw0LIhDQTtaN44G86BzhvQFdeQzfvyrKXfuYUTOQz/iYPNFsO6
  FOcDg9EcA19n5tSGp8SniyDEe6EhBWa5A9UR2RPEg/8NZRoeZ/2G9SjUqoa/Erxn
  IPlZvNu+gMEK7etysUQ33s4fp+jD6p0pbWKgSQAiDRVHi3Khlhcn7DfM0ncrSQBs
  vgFPSEczjpl8LR6c0pLSdPUHgdK6pDLTYdtdytRNfJAVjAREYL4uSb8I5NKdkgEz
  BLvnDfdDoCeOZoaeLR68jCltNfdzT5/d1v086i7uRepGhQ5w7ehtPuZ+0U8=
  -----END CERTIFICATE-----

Then re-run the installation

helm del --purge cloudbees-sidecar-injector
helm install cloudbees/cloudbees-sidecar-injector --name cloudbees-sidecar-injector --namespace cloudbees-sidecar-injector -f values.yaml

Deploy cloudbees-sidecar-injector with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cloudbees-sidecar-injector on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartcloudbees-sidecar-injector is pinned at v496.0.0+82f012f86ec9 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply