8000 helm: default to the restricted Pod Security Standard by DrFaust92 · Pull Request #2174 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content

helm: default to the restricted Pod Security Standard - #2174

Merged
alex-zaitsev merged 2 commits into
Altinity:0.28.0from
DrFaust92:helm-restricted-security-context
Dec 3, 2026
Merged

alex-zaitsev merged 2 commits into
Altinity:0.28.0from
DrFaust92:helm-restricted-security-context

Conversation

@DrFaust92
Copy link
Copy Markdown

The chart renders empty pod and container security contexts for the operator Deployment and for the CRD installation hook, so it cannot be installed in a namespace that enforces the restricted Pod Security Standard. The pre-install hook pod is rejected and the release fails:

Error creating: pods "...-crd-install-..." is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false ...
Error: INSTALLATION FAILED: failed pre-install: resource Job/.../...-crd-install not ready. status: InProgress, message: Job in progress

This sets restricted defaults in values.yaml (the generator script leaves these keys alone, so dev/generate_helm_chart.sh doesn't need changes):

podSecurityContext:
  runAsNonRoot: true
  runAsUser: 65534
  runAsGroup: 65534
  seccompProfile:
    type: RuntimeDefault
operator:
  containerSecurityContext:
    allowPrivilegeEscalation: false
    capabilities:
      drop: [ALL]
    readOnlyRootFilesystem: true
metrics:
  containerSecurityContext:   # same as operator
crdHook:
  podSecurityContext:         # same as podSecurityContext
  containerSecurityContext:
    allowPrivilegeEscalation: false
    capabilities:
      drop: [ALL]
  • Both altinity/clickhouse-operator:0.28.0 and altinity/metrics-exporter:0.28.0 run as USER nobody (uid/gid 65534 in their /etc/passwd). That user is not numeric, so with runAsNonRoot alone the kubelet cannot verify it and refuses to start the container; runAsUser: 65534 keeps the same user and makes it verifiable.
  • The only file either binary writes is the IPC token (pkg/chop/ipc_token.go, default /etc/clickhouse-operator-ipc/token), which lives on the existing clickhouse-operator-ipc emptyDir, so the root filesystem can be read-only. If logtostderr is turned off in the operator configuration, glog writes log files and needs a writable volume.
  • registry.k8s.io/kubectl runs as root by default; the hook only talks to the API server, so it runs as 65534 too. This changes the opt-in defaults added in Add security context for crdHook to enable security policy compliance #1950 / feat(helm): add podSecurityContext and podAnnotations to crdHook Job #2009, because with the hook enabled by default the chart otherwise can't install under restricted at all.
  • The operator keeps its service account token (it needs the API), and I left the probes opt-in: neither binary has a health endpoint, and the exporter's /metrics queries every ClickHouse host on each scrape.
  • Each default can be dropped by setting that key to null.

dev/test_helm_chart.sh gets a "security context" section (6 checks: the pod and container defaults, the hook defaults, dropping runAsUser with null, and an empty podSecurityContext), and README.md is regenerated with helm-docs. A CHANGELOG entry is added under 0.28.0 → Changed.

Testing

  • dev/test_helm_chart.sh: PASSED 30 checks, including the README drift check. Against the 0.28.0 chart, the three default checks in the new section fail.
  • helm lint --strict passes.
  • 8000
  • kind (Kubernetes v1.37.0), operator namespace labelled pod-security.kubernetes.io/enforce=restricted:
    • chart from 0.28.0: the hook Job can't create its pod and helm install fails with the error above.
    • this branch: the hook runs as 65534 and applies the 7 CRDs, the operator pod is 2/2 Running. With watch.namespaces.include: [".*"], a one-replica ClickHouseInstallation in another namespace reaches Completed; the metrics-exporter serves chi_clickhouse_metric_* series for it and the operator serves clickhouse_operator_* metrics. The helm upgrade (pre-upgrade hook) also passes admission.
    • security.ipc.mode: Secure: the operator logs IPC: Secure mode — provisioned token at /etc/clickhouse-operator-ipc/token with the read-only root filesystem, and the exporter keeps serving ClickHouse metrics through /chi.

This PR was prepared with an AI assistant (Claude Code) and reviewed by me.

🤖 Generated with Claude Code

The operator Deployment and the CRD installation hook rendered empty pod and
container security contexts, so the chart could not be installed in a
namespace that enforces the restricted Pod Security Standard: the
pre-install hook pod is rejected and the release fails.

- podSecurityContext: runAsNonRoot with uid/gid 65534 (both images run as
  `nobody`, a non-numeric USER the kubelet cannot verify without a numeric
  runAsUser) and the RuntimeDefault seccomp profile.
- operator and metrics-exporter containers: no privilege escalation, all
  capabilities dropped, read-only root filesystem (the only write is the IPC
  token to its emptyDir).
- crdHook: the same pod defaults (the kubectl image runs as root by default
  but only talks to the API server), no privilege escalation, all
  capabilities dropped.

dev/test_helm_chart.sh covers the defaults and dropping one with null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: drfaust92 <ilia.lazebnik@gmail.com>
@DrFaust92
DrFaust92 force-pushed the helm-restricted-security-context branch from 793aa26 to e3812b6 Compare November 25, 2026 22:38
@alex-zaitsev
alex-zaitsev self-requested a review December 2, 2026 09:40
@alex-zaitsev
Copy link
Copy Markdown
Member

@DrFaust92 , thank you for the PR. It does introduce potentially breaking changes to the Helm chart defaults, so I recommend marking it BACKWARD INCOMPATIBLE in the changelog.

One potential problem: hard-coded UID 65534 can prevent installation on OpenShift. OpenShift's standard restricted-v2 Security Context Constraint generally requires a UID from the namespace's allocated range. 65534 is usually outside that range, so OpenShift can reject both the pre-install Job and the operator Pod. Red Hat specifically documents how explicit UIDs outside the permitted range fail admission. While operator is typically deployed via OLM on OpenShift, it is still a concern. Maybe add a specific note to docs, so OpenShift users could override it.

Another issue is that PR sets readOnlyRootFilesystem: true for both operator containers. Unlike allowPrivilegeEscalation: false, dropping capabilities, and non-root execution, a read-only root filesystem is not required by the Kubernetes Restricted Pod Security Standard. This matters because the PR itself acknowledges that disabling logtostderr can require a writable log directory.

…enShift

Drop readOnlyRootFilesystem from the container defaults: restricted does not
require it, and a user who turns off logtostderr needs a writable log dir.
Document nulling runAsUser/runAsGroup on OpenShift, where restricted-v2 assigns
the uid from the namespace range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: drfaust92 <ilia.lazebnik@gmail.com>
@DrFaust92
Copy link
Copy Markdown
Author

@alex-zaitsev thanks, done in 553b45e. The changelog entry is marked BACKWARD INCOMPATIBLE and says how to run on OpenShift: set runAsUser/runAsGroup to null in podSecurityContext and crdHook.podSecurityContext so restricted-v2 assigns the uid. The values docs say the same. I also dropped readOnlyRootFilesystem from both containers, since restricted does not require it. Happy to put it back if you would rather keep it.

@alex-zaitsev
alex-zaitsev merged commit 33981c0 into Altinity:0.28.0 Dec 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0