Skip to content

Commit

Permalink
[bitnami/cassandra] Make TLS existingSecrets more configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Balzer <[email protected]>
  • Loading branch information
tbalzer committed Aug 7, 2024
1 parent 85cd823 commit 7230aa0
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 29 deletions.
8 changes: 6 additions & 2 deletions bitnami/cassandra/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 11.3.12 (2024-07-31)
## 11.4.0 (2024-08-07)

* [bitnami/cassandra] Improve Ginkgo test ([#28603](https://github.com/bitnami/charts/pull/28603))
* [bitnami/cassandra] Making TLS existingSecrets more configurable ([#28746](https://github.com/bitnami/charts/pull/28746))

## <small>11.3.12 (2024-07-31)</small>

* [bitnami/cassandra] Improve Ginkgo test ([bcf704a](bcf704adf1f2140df4ca8e6c2f60cbeabeca1711))

## <small>11.3.11 (2024-07-25)</small>

Expand Down
2 changes: 1 addition & 1 deletion bitnami/cassandra/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ maintainers:
name: cassandra
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/cassandra
version: 11.3.12
version: 11.4.0
52 changes: 38 additions & 14 deletions bitnami/cassandra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ tls.certificatesSecret=my-certs
tls.passwordsSecret=my-stores-password
```

The default secret configuration can be overridden as well to allow for integration with e.g. cert-manager and trust-manager:

```text
tls.internodeEncryption=all
tls.clientEncryption=true
tls.existingSecret=my-existing-cassandra-certificate
tls.existingTrustSecret=my-existing-cassandra-trust-bundle
tls.passwordsSecret=my-stores-password
tls.secretKeys.keystore=keystore.p12
tls.secretKeys.truststore=truststore.p12
```

Optionally also the keys used to identify the keystore and truststore passwords within the `passwordsSecret` can be configured:

```text
tls.secretKeys.keystorePassword=password-keystore
tls.secretKeys.truststorePassword=password-truststore
```

### Initialize the database

The [Apache Cassandra](https://github.com/bitnami/containers/tree/main/bitnami/cassandra) image supports the use of custom scripts to initialize a fresh instance. This may be done by creating a Kubernetes ConfigMap that includes the necessary `.sh` or `.cql` scripts and passing this ConfigMap to the chart via the `initDBConfigMap` parameter.
Expand Down Expand Up @@ -380,19 +399,24 @@ As the image run as non-root by default, it is necessary to adjust the ownership

### TLS/SSL parameters

| Name | Description | Value |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `tls.internodeEncryption` | Set internode encryption | `none` |
| `tls.clientEncryption` | Set client-server encryption | `false` |
| `tls.autoGenerated` | Generate automatically self-signed TLS certificates. Currently only supports PEM certificates | `false` |
| `tls.existingSecret` | Existing secret that contains Cassandra Keystore and truststore | `""` |
| `tls.passwordsSecret` | Secret containing the Keystore and Truststore passwords if needed | `""` |
| `tls.keystorePassword` | Password for the keystore, if needed. | `""` |
| `tls.truststorePassword` | Password for the truststore, if needed. | `""` |
| `tls.resourcesPreset` | Set container resources according to one common preset (allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge). This is ignored if tls.resources is set (tls.resources is recommended for production). | `nano` |
| `tls.resources` | Set container requests and limits for different resources like CPU or memory (essential for production workloads) | `{}` |
| `tls.certificatesSecret` | Secret with the TLS certificates. | `""` |
| `tls.tlsEncryptionSecretName` | Secret with the encryption of the TLS certificates | `""` |
| Name | Description | Value |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `tls.internodeEncryption` | Set internode encryption | `none` |
| `tls.clientEncryption` | Set client-server encryption | `false` |
| `tls.autoGenerated` | Generate automatically self-signed TLS certificates. Currently only supports PEM certificates | `false` |
| `tls.existingSecret` | Existing secret that contains Cassandra Keystore and optionally truststore if `tls.existingTrustSecret` is not set | `""` |
| `tls.existingTrustSecret` | Existing secret that contains Cassandra truststore | `""` |
| `tls.passwordsSecret` | Secret containing the Keystore and Truststore passwords if needed | `""` |
| `tls.keystorePassword` | Password for the keystore, if needed. | `""` |
| `tls.truststorePassword` | Password for the truststore, if needed. | `""` |
| `tls.resourcesPreset` | Set container resources according to one common preset (allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge). This is ignored if tls.resources is set (tls.resources is recommended for production). | `nano` |
| `tls.resources` | Set container requests and limits for different resources like CPU or memory (essential for production workloads) | `{}` |
| `tls.certificatesSecret` | Secret with the TLS certificates. | `""` |
| `tls.tlsEncryptionSecretName` | Secret with the encryption of the TLS certificates | `""` |
| `tls.secretKeys.keystore` | Key within `tls.existingSecret` that contains the keystore file | `keystore` |
| `tls.secretKeys.keystorePassword` | Key within `tls.passwordsSecret` that contains the keystore secret | `keystore-password` |
| `tls.secretKeys.truststore` | Key within `tls.existingSecret` or `tls.existingTrustSecret` (if set) that contains the truststore file | `truststore` |
| `tls.secretKeys.truststorePassword` | Key within `tls.passwordsSecret` that contains the truststore secret | `truststore-password` |

The above parameters map to the env variables defined in [bitnami/cassandra](https://github.com/bitnami/containers/tree/main/bitnami/cassandra). For more information please refer to the [bitnami/cassandra](https://github.com/bitnami/containers/tree/main/bitnami/cassandra) image documentation.

Expand Down Expand Up @@ -523,4 +547,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
20 changes: 16 additions & 4 deletions bitnami/cassandra/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,28 @@ Calculate New Heap Size based on the given values
{{- end -}}

{{/*
Return the Cassandra TLS credentials secret
Return the Cassandra TLS keystore secret
*/}}
{{- define "cassandra.tlsSecretName" -}}
{{- define "cassandra.keystoreSecretName" -}}
{{- $secretName := coalesce .Values.tls.existingSecret .Values.tls.tlsEncryptionSecretName -}}
{{- if $secretName -}}
{{- printf "%s" (tpl $secretName $) -}}
{{- else -}}
{{- printf "%s-crt" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{/*
Return the Cassandra TLS truststore secret
*/}}
{{- define "cassandra.truststoreSecretName" -}}
{{- $secretName := coalesce .Values.tls.existingTrustSecret .Values.tls.existingSecret .Values.tls.tlsEncryptionSecretName -}}
{{- if $secretName -}}
{{- printf "%s" (tpl $secretName $) -}}
{{- else -}}
{{- printf "%s-crt" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Return true if a TLS credentials secret object should be created
Expand Down Expand Up @@ -279,15 +291,15 @@ otherwise it generates a random value.
{{- if .Values.tls.keystorePassword }}
{{- .Values.tls.keystorePassword }}
{{- else }}
{{- include "getValueFromSecret" (dict "Namespace" (include "common.names.namespace" .) "Name" (printf "%s-%s" (include "common.names.fullname" .) "tls-pass" | trunc 63 | trimSuffix "-") "Length" 10 "Key" "keystore-password") -}}
{{- include "getValueFromSecret" (dict "Namespace" (include "common.names.namespace" .) "Name" (printf "%s-%s" (include "common.names.fullname" .) "tls-pass" | trunc 63 | trimSuffix "-") "Length" 10 "Key" .Values.tls.secretKeys.keystorePassword) -}}
{{- end }}
{{- end -}}

{{- define "cassandra.truststore.password" -}}
{{- if .Values.tls.truststorePassword }}
{{- .Values.tls.truststorePassword }}
{{- else }}
{{- include "getValueFromSecret" (dict "Namespace" (include "common.names.namespace" .) "Name" (printf "%s-%s" (include "common.names.fullname" .) "tls-pass" | trunc 63 | trimSuffix "-") "Length" 10 "Key" "truststore-password") -}}
{{- include "getValueFromSecret" (dict "Namespace" (include "common.names.namespace" .) "Name" (printf "%s-%s" (include "common.names.fullname" .) "tls-pass" | trunc 63 | trimSuffix "-") "Length" 10 "Key" .Values.tls.secretKeys.truststorePassword) -}}
{{- end }}
{{- end -}}

Expand Down
4 changes: 2 additions & 2 deletions bitnami/cassandra/templates/cassandra-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ metadata:
type: Opaque
data:
{{- if or .Values.tls.keystorePassword .Values.tls.autoGenerated }}
keystore-password: {{ include "cassandra.keystore.password" . | b64enc | quote }}
{{ .Values.tls.secretKeys.keystorePassword }}: {{ include "cassandra.keystore.password" . | b64enc | quote }}
{{- end }}
{{- if or .Values.tls.truststorePassword .Values.tls.autoGenerated }}
truststore-password: {{ include "cassandra.truststore.password" . | b64enc | quote }}
{{ .Values.tls.secretKeys.truststorePassword }}: {{ include "cassandra.truststore.password" . | b64enc | quote }}
{{- end }}
{{- end }}
27 changes: 22 additions & 5 deletions bitnami/cassandra/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ spec:
valueFrom:
secretKeyRef:
name: {{ (include "cassandra.tlsPasswordsSecret" .) }}
key: truststore-password
key: {{ .Values.tls.secretKeys.truststorePassword }}
{{- end }}
{{- if or .Values.tls.passwordsSecret .Values.tls.tlsEncryptionSecretName .Values.tls.keystorePassword .Values.tls.autoGenerated }}
- name: CASSANDRA_KEYSTORE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ (include "cassandra.tlsPasswordsSecret" .) }}
key: keystore-password
key: {{ .Values.tls.secretKeys.keystorePassword }}
{{- end }}
{{- if .Values.tls.resources }}
resources: {{- toYaml .Values.tls.resources | nindent 12 }}
Expand Down Expand Up @@ -295,14 +295,14 @@ spec:
valueFrom:
secretKeyRef:
name: {{ (include "cassandra.tlsPasswordsSecret" .) }}
key: truststore-password
key: {{ .Values.tls.secretKeys.truststorePassword }}
{{- end }}
{{- if or .Values.tls.passwordsSecret .Values.tls.tlsEncryptionSecretName .Values.tls.keystorePassword .Values.tls.autoGenerated }}
- name: CASSANDRA_KEYSTORE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ (include "cassandra.tlsPasswordsSecret" .) }}
key: keystore-password
key: {{ .Values.tls.secretKeys.keystorePassword }}
{{- end }}
- name: CASSANDRA_RACK
value: {{ .Values.cluster.rack }}
Expand Down Expand Up @@ -552,9 +552,26 @@ spec:
name: {{ include "cassandra.metricsConfConfigMap" . }}
{{- if (include "cassandra.tlsEncryption" . ) }}
- name: certs
{{- if (include "cassandra.createTlsSecret" . ) }}
secret:
secretName: {{ include "cassandra.tlsSecretName" . }}
secretName: {{ include "cassandra.keystoreSecretName" . }}
defaultMode: 256
{{- else }}
projected:
sources:
- secret:
name: {{ include "cassandra.truststoreSecretName" . }}
items:
- key: {{ .Values.tls.secretKeys.truststore }}
path: truststore
mode: 256
- secret:
name: {{ include "cassandra.keystoreSecretName" . }}
items:
- key: {{ .Values.tls.secretKeys.keystore }}
path: keystore
mode: 256
{{- end }}
- name: certs-shared
emptyDir:
sizeLimit: 500Mi
Expand Down
13 changes: 12 additions & 1 deletion bitnami/cassandra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ metrics:
## @param tls.internodeEncryption Set internode encryption
## @param tls.clientEncryption Set client-server encryption
## @param tls.autoGenerated Generate automatically self-signed TLS certificates. Currently only supports PEM certificates
## @param tls.existingSecret Existing secret that contains Cassandra Keystore and truststore
## @param tls.existingSecret Existing secret that contains Cassandra Keystore and optionally truststore if `tls.existingTrustSecret` is not set
## @param tls.existingTrustSecret Existing secret that contains Cassandra truststore
## @param tls.passwordsSecret Secret containing the Keystore and Truststore passwords if needed
## @param tls.keystorePassword Password for the keystore, if needed.
## @param tls.truststorePassword Password for the truststore, if needed.
Expand All @@ -940,18 +941,28 @@ metrics:
## @param tls.resources Set container requests and limits for different resources like CPU or memory (essential for production workloads)
## @param tls.certificatesSecret Secret with the TLS certificates.
## @param tls.tlsEncryptionSecretName Secret with the encryption of the TLS certificates
## @param tls.secretKeys.keystore Key within `tls.existingSecret` that contains the keystore file
## @param tls.secretKeys.keystorePassword Key within `tls.passwordsSecret` that contains the keystore secret
## @param tls.secretKeys.truststore Key within `tls.existingSecret` or `tls.existingTrustSecret` (if set) that contains the truststore file
## @param tls.secretKeys.truststorePassword Key within `tls.passwordsSecret` that contains the truststore secret
##
tls:
internodeEncryption: none
clientEncryption: false
autoGenerated: false
existingSecret: ""
existingTrustSecret: ""
passwordsSecret: ""
keystorePassword: ""
truststorePassword: ""
certificatesSecret: ""
tlsEncryptionSecretName: ""
resourcesPreset: "nano"
secretKeys:
keystore: "keystore"
keystorePassword: "keystore-password"
truststore: "truststore"
truststorePassword: "truststore-password"
## We usually recommend not to specify default resources and to leave this as a conscious
## choice for the user. This also increases chances charts run on environments with little
## resources, such as Minikube. If you do want to specify resources, uncomment the following
Expand Down

0 comments on commit 7230aa0

Please sign in to comment.