cloudbees-sidecar-injector
by CloudBees
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.
-
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 -
Add root CA to system certificate bundle
cat mycertificate.pem >> ca-certificates.crt -
Add root CA to java cacerts
keytool -import -noprompt -keystore cacerts -file mycertificate.pem -storepass changeit -alias service-mycertificate; -
Create a configmap with the two files above
kubectl create configmap --from-file=ca-certificates.crt,cacerts ca-bundles
Setup injector
-
Create a namespace to deploy the sidecar injector
kubectl create namespace sidecar-injector -
Review chart values
helm inspect values cloudbees/cloudbees-sidecar-injectorIn particular, pay attention to the
caBundleCrtfield if your kubernetes cluster has been set up to use a different signing cert than the root CA used for api server. -
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
-
Label the namespace where Cloudbees CI is installed with
sidecar-injector=enabledkubectl label namespace mynamespace sidecar-injector=enabled -
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
-
Deploy an app in Kubernetes cluster, take
sleepapp as an examplekubectl run sleep --image curlimages/curl --command /bin/sleep infinity -
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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcloudbees-sidecar-injector is pinned at v496.0.0+82f012f86ec9 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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