Skip to content

Commit c5ef0b4

Browse files
feat: do not set caBundle from certificate by default, only with explicit setting
1 parent 6e96f8e commit c5ef0b4

21 files changed

Lines changed: 158 additions & 77 deletions

api/v1alpha1/clickhousecluster_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ func (s *ClickHouseClusterSpec) WithDefaults() {
158158
}
159159
}
160160

161-
if s.Settings.TLS.CABundle != nil && s.Settings.TLS.CABundle.Key == "" {
162-
s.Settings.TLS.CABundle.Key = "ca.crt"
163-
}
164-
165161
if s.DataVolumeClaimSpec != nil && len(s.DataVolumeClaimSpec.AccessModes) == 0 {
166162
s.DataVolumeClaimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{DefaultAccessMode}
167163
}

api/v1alpha1/common.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,27 @@ type ClusterTLSSpec struct {
324324
// +kubebuilder:default:=false
325325
// +optional
326326
Required bool `json:"required,omitempty"`
327-
// ServerCertSecretRef is a reference to a TLS Secret containing the server certificate.
327+
// ServerCertSecret is a reference to a TLS Secret containing the server certificate.
328328
// It is expected that the Secret has the same structure as certificates generated by cert-manager,
329329
// with the certificate and private key stored under "tls.crt" and "tls.key" keys respectively.
330330
// +optional
331331
ServerCertSecret *corev1.LocalObjectReference `json:"serverCertSecret,omitempty"`
332-
// CABundle is a reference to a TLS Secret containing the CA bundle.
333-
// If empty and ServerCertSecret is specified, the CA bundle from certificate will be used.
334-
// Otherwise, system trusted CA bundle will be used.
332+
// CABundle is a reference to a Secret key holding a CA bundle used to verify peer certificates.
333+
// If empty, the system trusted CA bundle is used.
335334
// Key is defaulted to "ca.crt" if not specified.
336335
// +optional
337-
CABundle *SecretKeySelector `json:"caBundle,omitempty"`
336+
CABundle *CABundleSelector `json:"caBundle,omitempty"`
337+
}
338+
339+
// CABundleSelector selects a key holding a CA bundle from a Secret in the cluster's namespace.
340+
type CABundleSelector struct {
341+
// The name of the secret in the cluster's namespace to select from.
342+
// +kubebuilder:validation:Required
343+
Name string `json:"name,omitempty"`
344+
// The key of the secret to select from. Must be a valid secret key.
345+
// +kubebuilder:default:="ca.crt"
346+
// +optional
347+
Key string `json:"key,omitempty"`
338348
}
339349

340350
// Validate validates the ClusterTLSSpec configuration.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
55
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
66
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=clickhouse-operator
8-
LABEL operators.operatorframework.io.bundle.channels.v1=stable
8+
LABEL operators.operatorframework.io.bundle.channels.v1=stable,fast
99
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
1010
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.42.2
1111
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1

config/crd/bases/clickhouse.com_clickhouseclusters.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6460,12 +6460,12 @@ spec:
64606460
properties:
64616461
caBundle:
64626462
description: |-
6463-
CABundle is a reference to a TLS Secret containing the CA bundle.
6464-
If empty and ServerCertSecret is specified, the CA bundle from certificate will be used.
6465-
Otherwise, system trusted CA bundle will be used.
6463+
CABundle is a reference to a Secret key holding a CA bundle used to verify peer certificates.
6464+
If empty, the system trusted CA bundle is used.
64666465
Key is defaulted to "ca.crt" if not specified.
64676466
properties:
64686467
key:
6468+
default: ca.crt
64696469
description: The key of the secret to select from. Must
64706470
be a valid secret key.
64716471
type: string
@@ -6474,7 +6474,6 @@ spec:
64746474
to select from.
64756475
type: string
64766476
required:
6477-
- key
64786477
- name
64796478
type: object
64806479
enabled:
@@ -6489,7 +6488,7 @@ spec:
64896488
type: boolean
64906489
serverCertSecret:
64916490
description: |-
6492-
ServerCertSecretRef is a reference to a TLS Secret containing the server certificate.
6491+
ServerCertSecret is a reference to a TLS Secret containing the server certificate.
64936492
It is expected that the Secret has the same structure as certificates generated by cert-manager,
64946493
with the certificate and private key stored under "tls.crt" and "tls.key" keys respectively.
64956494
properties:

config/crd/bases/clickhouse.com_keeperclusters.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6110,12 +6110,12 @@ spec:
61106110
properties:
61116111
caBundle:
61126112
description: |-
6113-
CABundle is a reference to a TLS Secret containing the CA bundle.
6114-
If empty and ServerCertSecret is specified, the CA bundle from certificate will be used.
6115-
Otherwise, system trusted CA bundle will be used.
6113+
CABundle is a reference to a Secret key holding a CA bundle used to verify peer certificates.
6114+
If empty, the system trusted CA bundle is used.
61166115
Key is defaulted to "ca.crt" if not specified.
61176116
properties:
61186117
key:
6118+
default: ca.crt
61196119
description: The key of the secret to select from. Must
61206120
be a valid secret key.
61216121
type: string
@@ -6124,7 +6124,6 @@ spec:
61246124
to select from.
61256125
type: string
61266126
required:
6127-
- key
61286127
- name
61296128
type: object
61306129
enabled:
@@ -6139,7 +6138,7 @@ spec:
61396138
type: boolean
61406139
serverCertSecret:
61416140
description: |-
6142-
ServerCertSecretRef is a reference to a TLS Secret containing the server certificate.
6141+
ServerCertSecret is a reference to a TLS Secret containing the server certificate.
61436142
It is expected that the Secret has the same structure as certificates generated by cert-manager,
61446143
with the certificate and private key stored under "tls.crt" and "tls.key" keys respectively.
61456144
properties:

config/manifests/bases/clickhouse-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ spec:
137137
every replica.
138138
displayName: Stateful Set Revision
139139
path: statefulSetRevision
140-
- description: CurrentRevision indicates latest requested KeeperCluster spec
140+
- description: UpdateRevision indicates latest requested KeeperCluster spec
141141
revision.
142142
displayName: Update Revision
143143
path: updateRevision
@@ -146,6 +146,7 @@ spec:
146146
path: version
147147
- description: |-
148148
VersionProbeRevision is the image hash of the last successful version probe.
149+
149150
Deprecated: Keeper version probe Jobs are not used; this field is retained for backward compatibility.
150151
displayName: Version Probe Revision
151152
path: versionProbeRevision

dist/chart/templates/crd/clickhouseclusters.clickhouse.com.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6463,12 +6463,12 @@ spec:
64636463
properties:
64646464
caBundle:
64656465
description: |-
6466-
CABundle is a reference to a TLS Secret containing the CA bundle.
6467-
If empty and ServerCertSecret is specified, the CA bundle from certificate will be used.
6468-
Otherwise, system trusted CA bundle will be used.
6466+
CABundle is a reference to a Secret key holding a CA bundle used to verify peer certificates.
6467+
If empty, the system trusted CA bundle is used.
64696468
Key is defaulted to "ca.crt" if not specified.
64706469
properties:
64716470
key:
6471+
default: ca.crt
64726472
description: The key of the secret to select from. Must
64736473
be a valid secret key.
64746474
type: string
@@ -6477,7 +6477,6 @@ spec:
64776477
to select from.
64786478
type: string
64796479
required:
6480-
- key
64816480
- name
64826481
type: object
64836482
enabled:
@@ -6492,7 +6491,7 @@ spec:
64926491
type: boolean
64936492
serverCertSecret:
64946493
description: |-
6495-
ServerCertSecretRef is a reference to a TLS Secret containing the server certificate.
6494+
ServerCertSecret is a reference to a TLS Secret containing the server certificate.
64966495
It is expected that the Secret has the same structure as certificates generated by cert-manager,
64976496
with the certificate and private key stored under "tls.crt" and "tls.key" keys respectively.
64986497
properties:

dist/chart/templates/crd/keeperclusters.clickhouse.com.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6113,12 +6113,12 @@ spec:
61136113
properties:
61146114
caBundle:
61156115
description: |-
6116-
CABundle is a reference to a TLS Secret containing the CA bundle.
6117-
If empty and ServerCertSecret is specified, the CA bundle from certificate will be used.
6118-
Otherwise, system trusted CA bundle will be used.
6116+
CABundle is a reference to a Secret key holding a CA bundle used to verify peer certificates.
6117+
If empty, the system trusted CA bundle is used.
61196118
Key is defaulted to "ca.crt" if not specified.
61206119
properties:
61216120
key:
6121+
default: ca.crt
61226122
description: The key of the secret to select from. Must
61236123
be a valid secret key.
61246124
type: string
@@ -6127,7 +6127,6 @@ spec:
61276127
to select from.
61286128
type: string
61296129
required:
6130-
- key
61316130
- name
61326131
type: object
61336132
enabled:
@@ -6142,7 +6141,7 @@ spec:
61426141
type: boolean
61436142
serverCertSecret:
61446143
description: |-
6145-
ServerCertSecretRef is a reference to a TLS Secret containing the server certificate.
6144+
ServerCertSecret is a reference to a TLS Secret containing the server certificate.
61466145
It is expected that the Secret has the same structure as certificates generated by cert-manager,
61476146
with the certificate and private key stored under "tls.crt" and "tls.key" keys respectively.
61486147
properties:

docs/guides/tls.mdx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ rotate that Secret, but any tool that writes a Secret in the expected format wor
2929
## How the operator expects certificates {#secret-format}
3030

3131
TLS is enabled by pointing `spec.settings.tls.serverCertSecret` at a Secret that
32-
contains three keys:
32+
contains the server keypair:
3333

34-
| Secret key | Contents |
35-
|------------|----------------------------------|
36-
| `tls.crt` | PEM-encoded server certificate |
37-
| `tls.key` | PEM-encoded private key |
38-
| `ca.crt` | PEM-encoded CA certificate chain |
34+
| Secret key | Contents | Required |
35+
|------------|--------------------------------|----------|
36+
| `tls.crt` | PEM-encoded server certificate | Yes |
37+
| `tls.key` | PEM-encoded private key | Yes |
3938

4039
This is exactly the layout cert-manager writes for a `Certificate` resource, so no
41-
conversion is needed. The operator mounts these into each pod at
42-
`/etc/clickhouse-server/tls/` and wires them into ClickHouse's `openSSL` configuration.
40+
conversion is needed. The operator mounts the keypair into each pod at
41+
`/etc/clickhouse-server/tls/` and wires it into ClickHouse's `openSSL` configuration.
4342

4443
<Note>
4544
`serverCertSecret` is **mandatory** when `tls.enabled: true`. The validating
@@ -232,13 +231,15 @@ spec:
232231

233232
Keeper exposes its secure client port on `2281`. Once Keeper has TLS enabled, **the
234233
ClickHouse cluster connects to it over TLS automatically** — no extra setting on the
235-
ClickHouseCluster side. ClickHouse verifies the Keeper certificate using its own
236-
`ca.crt` bundle when it has TLS enabled, otherwise the system default CA bundle.
234+
ClickHouseCluster side. ClickHouse verifies the Keeper certificate against the system
235+
trust store, plus any [`caBundle`](#custom-ca) you configure.
237236

238237
## Custom CA bundle {#custom-ca}
239238

240-
If ClickHouse must trust a CA different from the one in its server certificate (for
241-
example, Keeper signed by a separate CA), supply a `caBundle`:
239+
By default ClickHouse verifies the peers it connects to (other replicas, Keeper, HTTPS
240+
dictionary sources, S3, …) against the **system trust store**. To **additionally** trust
241+
a private CA — a self-signed or internal CA whose root is not in the system store —
242+
supply a `caBundle`:
242243

243244
```yaml
244245
spec:
@@ -252,8 +253,11 @@ spec:
252253
key: ca.crt
253254
```
254255

255-
The operator mounts this bundle and points the client-side `openSSL` verification at
256-
it instead of the certificate's own `ca.crt`.
256+
The operator mounts this bundle and adds it to the `openSSL` client trust store
257+
(`caConfig`). The system trust store stays in effect — your private CA is trusted **in
258+
addition to** the public roots, so connections to public endpoints keep working. For a
259+
self-signed setup, point `caBundle` at the `ca.crt` key of the same Secret cert-manager
260+
wrote (as in the `cluster_with_ssl` example).
257261

258262
## Customizing the TLS settings {#custom-tls-settings}
259263

@@ -296,15 +300,15 @@ kubectl -n <namespace> get svc <cluster-name>-clickhouse-headless \
296300

297301
```bash
298302
kubectl -n <namespace> exec <pod> -- ls /etc/clickhouse-server/tls/
299-
# ca-bundle.crt clickhouse-server.crt clickhouse-server.key
303+
# clickhouse-server.crt clickhouse-server.key (plus custom-ca.crt when caBundle is set)
300304
```
301305

302-
| Symptom | Likely cause |
303-
|---|---|
304-
| Pods fail to start / volume mount error after enabling TLS | The referenced Secret is missing or lacks `tls.crt`/`tls.key`/`ca.crt`. The operator does not validate the Secret's contents — missing keys surface as a pod volume-mount failure, not a dedicated status condition. Inspect the pod with `kubectl describe pod`. |
305-
| Webhook rejects the cluster | `required: true` set without `enabled: true`, or `enabled: true` without `serverCertSecret`. |
306-
| Client `certificate verify failed` | Client is not trusting the CA. Pass the `ca.crt` from the Secret, or check the `dnsNames` on the certificate cover the host you connect to. |
307-
| A plaintext client suddenly can't connect | `required: true` removed ports `9000`/`8123`. Switch the client to `9440`/`8443`, or set `required: false` to keep insecure ports open during migration. |
306+
| Symptom | Likely cause |
307+
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
308+
| Pods fail to start / volume mount error after enabling TLS | The referenced Secret is missing or lacks `tls.crt`/`tls.key` (or, when `caBundle` is set, the Secret/key it references). The operator does not validate the Secret's contents — missing keys surface as a pod volume-mount failure, not a dedicated status condition. Inspect the pod with `kubectl describe pod`. |
309+
| Webhook rejects the cluster | `required: true` set without `enabled: true`, or `enabled: true` without `serverCertSecret`. |
310+
| Client `certificate verify failed` | Client is not trusting the CA. Pass the `ca.crt` from the Secret, or check the `dnsNames` on the certificate cover the host you connect to. |
311+
| A plaintext client suddenly can't connect | `required: true` removed ports `9000`/`8123`. Switch the client to `9440`/`8443`, or set `required: false` to keep insecure ports open during migration. |
308312

309313
## See also {#see-also}
310314

0 commit comments

Comments
 (0)