Repository navigation
feat(access): present a client certificate on HTTPS connections to ClickHouse - #2171
khrisrichardson wants to merge 1 commit into
Conversation
|
It doesn't look like this can actually be used with the Altinity-shipped Helm chart. They don't have any way to inject additional volumes and mounts. This probably requires a pre-req PR to add It doesn't add support for backup I think this can be made to support backup Job s without needing #2141, and it's probably better that way. I suggest changing the interface for this PR so it can support a cert/key pair in a kube An LLM review of this PR had the following additional comments: LLM review findingsI've read the issue and the PR's Go changes, and I'm about to write the review. I haven't run anything. The tests, e2e and the verbosity default below are unverified. My local Review of PR 2171 (part 1 of #2163)What it does: It adds Does it fix #2163? Only the mTLS-handshake half, which the issue's own "Impact" section names as the main point. The PR is explicit about this. It leaves four items open:
That scoping matches what was agreed in the issue thread. Main concerns
Smaller points
VerdictThe approach is correct and the scope is sensible. I'd ask for these before merge:
I'd also suggest simplifying the loader (item 2), but that's optional if the maintainers are happy with the tests. The agent also complained
but I don't really agree with this; verifying the server and the server verifying the client are different things. ... and some LLM commentary on the backup / Job support LLM commentary on Backup support#2141 is about letting users customise the backup Job and Pod: a
If you'd rather keep this PR small, items 1 and 6 are the minimum. Item 1 is the one that is costly to change later. A public config shape of file paths only would need a second field for the Secret. |
…ickHouse Add clickhouse.access.clientCertFile and clickhouse.access.clientKeyFile. When both are set, the operator (and the metrics exporter) presents that certificate on every HTTPS connection to ClickHouse, so servers running with verificationMode=strict accept it. The operator user still authenticates with its password over the mutually-authenticated connection. - Both or neither: a lone path is logged at config load and every HTTPS connection fails, the same as missing files, rather than connecting without a certificate. The files are not read at load. - The pair is read with tls.LoadX509KeyPair on every new TLS handshake through GetClientCertificate, so any rotation (an in-place rewrite, or a kubelet ..data symlink swap) is used without a restart. The cost is one read and parse per handshake; the operator's connections are pooled, so handshakes are rare. - A pair that fails to load, including a certificate whose key does not match it or files that have gone missing, keeps the last good one, so deleting the files does not withdraw a certificate in use; revoking it is the server's decision. The failure is logged as a warning at default verbosity, once per distinct failure. Before the first good load the handshake fails rather than going out without a certificate. - A client certificate counts as a TLS knob for the tls_config registry key, so it never shares the legacy registration. The paths enter the key quoted, so a path containing the separator cannot collide. Keys, DSNs and TLS configs are unchanged when the fields are unset. - verify polarity is unchanged: setting a client certificate changes nothing else, so pair mTLS with an explicit verify: Strict. - The client certificate is operator-wide: a CHI's security.tls cannot set or override it. Backup Jobs do not present it yet (Altinity#2141). - CRD, config.yaml, install bundles and the Helm chart regenerated; docs updated, including the fallback above, the two limits above, and that a subPath mount never receives updates. - e2e test_010089 (TestFlows): a strict server with and without the client certificate, and rotation to an untrusted certificate and back with the same operator pod. Passes on a local minikube (v1.39.0, Kubernetes v1.37.0, docker driver) in 6m22s. Refs Altinity#2163 Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
ae2d6ca to
9d60d66
Compare
|
Thanks for the careful review, and for passing the LLM notes along. On Helm: as the description notes, the chart can't mount a volume into the operator or exporter today, so this PR can only be used with a patched Deployment. I agree a separate PR is cleaner. Proposed order:
Does that order work for you? If you'd rather have the Secret ref before #2141, I can look at that instead. Changes pushed to this PR:
On server verification: agreed, that's separate. It stays tied to Disclosure: drafted with AI assistance; I reviewed the code and text before submitting. |
|
@khrisrichardson I think (2) can be done now, as I don't believe the |
|
Agreed, (2) doesn't need #2141. Reading the backup code, the certificate actually belongs on the clickhouse-backup sidecar rather than the Jobs, since the Jobs only call its REST API. I'll open it as a separate PR on top of this one, so this one stays reviewable. |
…extraInitContainers Let the chart add volumes, volume mounts and containers to the operator pod, for example to provide the client certificate that clickhouse.access.clientCertFile/clientKeyFile point to (Altinity#2171): from a Secret, or written by a sidecar such as spiffe-helper. extraInitContainers allows a native sidecar (restartPolicy: Always, Kubernetes 1.33+), which starts before the operator. The clickhouse-operator and metrics-exporter each read their own copy of the operator configuration, so each gets its own mounts. All five default to empty and render nothing. Refs Altinity#2163, Altinity#2171 Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
|
Could a maintainer approve the workflow runs for this PR? As a first-time contributor here, CI is waiting on approval and hasn't run yet. |
…extraInitContainers Let the chart add volumes, volume mounts and containers to the operator pod, for example to provide the client certificate that clickhouse.access.clientCertFile/clientKeyFile point to (Altinity#2171): from a Secret, or written by a sidecar such as spiffe-helper. extraInitContainers allows a native sidecar (restartPolicy: Always, Kubernetes 1.33+), which starts before the operator. The clickhouse-operator and metrics-exporter each read their own copy of the operator configuration, so each gets its own mounts. All five default to empty and render nothing. Refs Altinity#2163, Altinity#2171 Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
Part 1 of #2163: the operator can present a client certificate to ClickHouse.
What
New
clickhouse.access.clientCertFileandclickhouse.access.clientKeyFile. When both are set, the operator and the metrics exporter present that certificate on every HTTPS connection, so a server withverificationMode: strictaccepts them. The operator user still authenticates with its password.How
tls.LoadX509KeyPairat each new TLS handshake (GetClientCertificate), keeping the last good certificate if a read fails. Any rotation, including a kubelet..dataswap or an in-place rewrite, is used without a restart.verifyis unchanged: pair mTLS withverify: Strict.Tests
test_010089, with and without the certificate, rotated to an untrusted one and back on the same pod. It passed on a local minikube against this commit.Possible follow-ups
extraVolumes/extraVolumeMounts, or aclientCertSecretRef, whichever you prefer.Disclosure: drafted with AI assistance; I reviewed the code and text before submitting.
🤖 Generated with Claude Code