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

Open
DrFaust92 wants to merge 1 commit into
Altinity:0.28.0from
DrFaust92:helm-restricted-security-context
Open

DrFaust92 wants to merge 1 commit 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.
  • 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.namespace 8000 s.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

This branch has not been deployed

No deployments
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.

1 participant

0