-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLIP-1826: Add user provided certificates to the default Java truststore #663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -519,3 +519,53 @@ readinessProbe: | |
!!!warning "`startupProbe` and `livenessProbe`" | ||
|
||
Both `startupProbe` and `livenessProbe` are disabled by default. Make sure you go through the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/){.external} before enabling such probes. Misconfiguration can result in unwanted container restarts and failed "cold" starts. | ||
|
||
## :material-certificate: Self Signed Certificates | ||
|
||
Accessing applications or websites that are encrypted with SSL using certificates not signed by a public authority will result in a connection error. The stacktrace will contain the following: | ||
|
||
```shell | ||
caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target | ||
``` | ||
|
||
To fix the issue, self signed certificates need to be added to Java truststore. First off, you need to create a [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/){.external} containing base64-encoded certificate(s). Here's an example [kubectl command](https://kubernetes.io/docs/tasks/configmap-secret/managing-secret-using-kubectl/#use-source-files){.external} to create a secret from 2 local files: | ||
|
||
```shell | ||
kubectl create secret generic dev-certificates \ | ||
--from-file=stg.crt=./stg.crt \ | ||
--from-file=dev.crt=./dev.crt -n $namespace | ||
``` | ||
|
||
The resulting secret will have the following data: | ||
|
||
```yaml | ||
data: | ||
stg.crt: base64encodedstgcrt | ||
dev.crt: base64encodeddevcrt | ||
``` | ||
|
||
!!!info "You can have as many keys (certificates) in the secret as required. All keys will be mounted as files to `/tmp/crt` in the container and imported into Java truststore. In the example above, certificates will be mounted as `/tmp/crt/stg.crt` and `/tmp/crt/dev.crt`. File extension in the secret keys does not matter as long as the file is a valid certificate." | ||
|
||
Once done, provide the secret name in Helm values: | ||
|
||
```yaml | ||
jira: | ||
additionalCertificates: | ||
secretName: dev-certificates | ||
``` | ||
|
||
Helm chart will add additional `volumeMounts` and `volumes` to the pod(s), as well as an extra init container that will: | ||
|
||
* copy the default Java cacerts to a runtime volume shared between the init container and the main container at `/var/ssl` | ||
* run [keytool -import](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html){.external} to import all certificates in `/tmp/crt` mounted from `dev-certificates` secret to `/var/ssl/cacerts` | ||
|
||
`-Djavax.net.ssl.trustStore=/var/ssl/cacerts` system property will be automatically added to `JVM_SUPPORT_RECOMMENDED_ARGS` environment variable. | ||
|
||
If necessary, it is possible to override the default `keytool -import` command: | ||
|
||
```yaml | ||
jira: | ||
additionalCertificates: | ||
secretName: dev-certificates | ||
customCmd: keytool -import ... | ||
``` | ||
Comment on lines
+522
to
+571
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bianchi2 Im just wondering if it makes more sense for this to go under the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good idea! I'll raise another PR with docs changes as this one has been merged. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,10 @@ on Tomcat's logs directory. THis ensures that Tomcat+Bamboo logs get captured in | |
{{- if .Values.volumes.sharedHome.subPath }} | ||
subPath: {{ .Values.volumes.sharedHome.subPath | quote }} | ||
{{- end }} | ||
{{- if .Values.bamboo.additionalCertificates.secretName }} | ||
- name: keystore | ||
mountPath: /var/ssl | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
|
@@ -205,6 +209,13 @@ For each additional plugin declared, generate a volume mount that injects that l | |
{{- with .Values.volumes.additional }} | ||
{{- toYaml . | nindent 0 }} | ||
{{- end }} | ||
{{- if .Values.bamboo.additionalCertificates.secretName }} | ||
- name: keystore | ||
emptyDir: {} | ||
- name: certs | ||
secret: | ||
secretName: {{ .Values.bamboo.additionalCertificates.secretName }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "bamboo.volumes.localHome" -}} | ||
|
@@ -307,3 +318,11 @@ Define additional hosts here to allow template overrides when used as a sub char | |
{{- toYaml . }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "bamboo.addCrtToKeystoreCmd" }} | ||
{{- if .Values.bamboo.additionalCertificates.customCmd}} | ||
{{ .Values.bamboo.additionalCertificates.customCmd}} | ||
{{- else }} | ||
set -e; for crt in /tmp/crt/*.*; do echo "Adding $crt to keystore"; keytool -import -cacerts -storepass changeit -noprompt -alias $(echo $(basename $crt)) -file $crt; done; cp $JAVA_HOME/lib/security/cacerts /var/ssl/cacerts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when customer has or wants to define different passkey than the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We assume that the official image is used. In case of a custom truststore, it should be already mounted as a secret. So, if a user already mounts a custom truststore, importing new certs happens outside helm then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right and if customer wants to do something specific in this command, they can always redefine the |
||
{{- end }} | ||
{{- end }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,18 @@ spec: | |
command: ["sh", "-c", {{ include "bamboo.sharedHome.permissionFix.command" . | quote }}] | ||
{{- end }} | ||
{{- include "common.jmx.initContainer" . | nindent 8 }} | ||
{{- if .Values.bamboo.additionalCertificates.secretName }} | ||
- name: import-certs | ||
image: {{ include "bamboo.image" . | quote }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we are running this image because we want to run the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question :) In fact, it does not really matter if we use temurin image for keytool init container. This won't save us any time since product image needs to be pulled anyways. It's a matter of which phase takes longer - init or containers start. If we pull product image in the init phase, container runtime will have it available when the product container starts. No gains/benefits with either of the approaches, imho. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for confirming this. I was thinking that because we pull the image anyway, it is faster on the pull time but for a very short period we take more resources than we need but as the execution is super quick, it is negligible. Last thing, if this fails, does it stop container execution, and how will customers get to the error logs (are they sufficient to understand why it failed?) |
||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
volumeMounts: | ||
- name: keystore | ||
mountPath: /var/ssl | ||
- name: certs | ||
mountPath: /tmp/crt | ||
command: ["/bin/bash"] | ||
args: ["-c", {{ include "bamboo.addCrtToKeystoreCmd" . }}] | ||
{{- end }} | ||
containers: | ||
- name: {{ if .Values.bamboo.useHelmReleaseNameAsContainerName}}{{ include "common.names.fullname" . }}{{ else }}{{ .Chart.Name }}{{ end }} | ||
image: {{ include "bamboo.image" . | quote }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.