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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* **ClickHouse settings supporting live reload no longer require a restart** when matched by wildcard `configurationRestartPolicy` rules. Explicit restart rules still take precedence. by [@alex-zaitsev](https://github.com/alex-zaitsev) in [#2109](https://github.com/Altinity/clickhouse-operator/pull/2109)

* **Helm chart defaults now meet the restricted Pod Security Standard.** The operator pod runs as `nobody` (uid/gid 65534, set by number so the kubelet can verify `runAsNonRoot`) with the `RuntimeDefault` seccomp profile; both containers drop all capabilities, disallow privilege escalation and use a read-only root filesystem, since they only write the IPC token to its emptyDir. The CRD installation hook gets the same pod defaults plus no privilege escalation and no capabilities, so the chart installs in namespaces that enforce `restricted`. Set individual `podSecurityContext`, `operator.containerSecurityContext`, `metrics.containerSecurityContext` or `crdHook.*SecurityContext` keys to `null` to drop a default. by [@DrFaust92](https://github.com/DrFaust92) in [#2174](https://github.com/Altinity/clickhouse-operator/pull/2174)

### Fixed

* **Invalid StatefulSet specifications no longer delete running StatefulSets during recreation.** The operator validates the desired StatefulSet with a server-side dry run before deleting the existing one, preserving ClickHouse and Keeper workloads on validation errors. by [@atsarevskiy](https://github.com/atsarevskiy) in [#2071](https://github.com/Altinity/clickhouse-operator/pull/2071). Fixes [#1420](https://github.com/Altinity/clickhouse-operator/issues/1420)
Expand Down
10 changes: 5 additions & 5 deletions deploy/helm/clickhouse-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ crdHook:
| configs | object | check the `values.yaml` file for the config content (auto-generated from latest operator release) | clickhouse operator configs |
| crdHook.affinity | object | `{}` | affinity for CRD installation job |
| crdHook.annotations | object | `{}` | additional annotations for CRD installation job |
| crdHook.containerSecurityContext | object | `{}` | container security context for CRD installation job check `kubectl explain pod.spec.containers.securityContext` for details |
| crdHook.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}` | container security context for CRD installation job check `kubectl explain pod.spec.containers.securityContext` for details |
| crdHook.enabled | bool | `true` | enable automatic CRD installation/update via pre-install/pre-upgrade hooks when disabled, CRDs must be installed manually using kubectl apply |
| crdHook.image.pullPolicy | string | `"IfNotPresent"` | image pull policy for CRD installation job |
| crdHook.image.repository | string | `"registry.k8s.io/kubectl"` | image repository for CRD installation job |
| crdHook.image.tag | string | `"v1.36.3"` | image tag for CRD installation job. registry.k8s.io/kubectl publishes no `latest` tag, so this must name an explicit version |
| crdHook.imagePullSecrets | list | `[]` | image pull secrets for CRD installation job possible value format `[{"name":"your-secret-name"}]`, check `kubectl explain pod.spec.imagePullSecrets` for details |
| crdHook.nodeSelector | object | `{}` | node selector for CRD installation job |
| crdHook.podAnnotations | object | `{}` | additional annotations for CRD installation job pod template useful to opt out of service mesh injection, e.g. `sidecar.istio.io/inject: "false"` |
| crdHook.podSecurityContext | object | `{}` | pod-level security context for CRD installation job required by some admission policies (e.g. Kyverno `restrict-seccomp-strict`) check `kubectl explain pod.spec.securityContext` for details |
| crdHook.podSecurityContext | object | `{"runAsGroup":65534,"runAsNonRoot":true,"runAsUser":65534,"seccompProfile":{"type":"RuntimeDefault"}}` | pod-level security context for CRD installation job required by some admission policies (e.g. Kyverno `restrict-seccomp-strict`) check `kubectl explain pod.spec.securityContext` for details. The default meets the restricted Pod Security Standard, so the pre-install hook is not rejected in a namespace that enforces it. The kubectl image runs as root by default; it only talks to the API server, so it runs as uid/gid 65534 here. Set a key to `null` to drop that default. |
| crdHook.resources | object | `{}` | resource limits and requests for CRD installation job |
| crdHook.tolerations | list | `[]` | tolerations for CRD installation job |
| dashboards.additionalLabels | object | `{"grafana_dashboard":""}` | labels to add to a secret with dashboards |
Expand All @@ -104,7 +104,7 @@ crdHook:
| deployment.strategy.type | string | `"Recreate"` | |
| fullnameOverride | string | `""` | full name of the chart. |
| imagePullSecrets | list | `[]` | image pull secret for private images in clickhouse-operator pod possible value format `[{"name":"your-secret-name"}]`, check `kubectl explain pod.spec.imagePullSecrets` for details |
| metrics.containerSecurityContext | object | `{}` | |
| metrics.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"readOnlyRootFilesystem":true}` | security context of the metrics-exporter container, check `kubectl explain pod.spec.containers.securityContext` for details. The default meets the restricted Pod Security Standard. The container writes only to the IPC token emptyDir (/etc/clickhouse-operator-ipc), so the root filesystem is read-only. Set a key to `null` to drop that default. |
| metrics.enabled | bool | `true` | |
| metrics.env | list | `[]` | additional environment variables for the deployment of metrics-exporter containers possible format value `[{"name": "SAMPLE", "value": "text"}]` |
| metrics.image.pullPolicy | string | `"IfNotPresent"` | image pull policy |
Expand All @@ -118,7 +118,7 @@ crdHook:
| nameOverride | string | `""` | override name of the chart |
| namespaceOverride | string | `""` | |
| nodeSelector | object | `{}` | node for scheduler pod assignment, check `kubectl explain pod.spec.nodeSelector` for details |
| operator.containerSecurityContext | object | `{}` | |
| operator.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"readOnlyRootFilesystem":true}` | security context of the clickhouse-operator container, check `kubectl explain pod.spec.containers.securityContext` for details. The default meets the restricted Pod Security Standard. The container writes only to the IPC token emptyDir (/etc/clickhouse-operator-ipc), so the root filesystem is read-only. Set a key to `null` to drop that default. |
| operator.env | list | `[]` | additional environment variables for the clickhouse-operator container in deployment possible format value `[{"name": "SAMPLE", "value": "text"}]` |
| operator.image.pullPolicy | string | `"IfNotPresent"` | image pull policy |
| operator.image.registry | string | `""` | optional image registry prefix (e.g. 1234567890.dkr.ecr.us-east-1.amazonaws.com) |
Expand All @@ -131,7 +131,7 @@ crdHook:
| operator.resources | object | `{}` | custom resource configuration, check `kubectl explain pod.spec.containers.resources` for details |
| podAnnotations | object | check the `values.yaml` file | annotations to add to the clickhouse-operator pod, check `kubectl explain pod.spec.annotations` for details |
| podLabels | object | `{}` | labels to add to the clickhouse-operator pod |
| podSecurityContext | object | `{}` | |
| podSecurityContext | object | `{"runAsGroup":65534,"runAsNonRoot":true,"runAsUser":65534,"seccompProfile":{"type":"RuntimeDefault"}}` | operator deployment SecurityContext, check `kubectl explain pod.spec.securityContext` for details. The default meets the restricted Pod Security Standard. Both images run as `nobody` (uid and gid 65534); the user is set by number because the kubelet can only verify `runAsNonRoot` against a numeric user. Set a key to `null` to drop that default. |
| rbac.create | bool | `true` | specifies whether rbac resources should be created |
| rbac.namespaceScoped | bool | `false` | specifies whether to create roles and rolebindings at the cluster level or namespace level |
| secret.create | bool | `true` | create a secret with operator credentials |
Expand Down
60 changes: 42 additions & 18 deletions deploy/helm/clickhouse-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,23 @@ crdHook:
podAnnotations: {}
# crdHook.podSecurityContext -- pod-level security context for CRD installation job
# required by some admission policies (e.g. Kyverno `restrict-seccomp-strict`)
# check `kubectl explain pod.spec.securityContext` for details
podSecurityContext: {}
# runAsNonRoot: true
# runAsUser: 1000
# seccompProfile:
# type: RuntimeDefault
# check `kubectl explain pod.spec.securityContext` for details.
# The default meets the restricted Pod Security Standard, so the pre-install hook is not rejected in a namespace
# that enforces it. The kubectl image runs as root by default; it only talks to the API server, so it runs as
# uid/gid 65534 here. Set a key to `null` to drop that default.
podSecurityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
# crdHook.containerSecurityContext -- container security context for CRD installation job
# check `kubectl explain pod.spec.containers.securityContext` for details
containerSecurityContext: {}
# allowPrivilegeEscalation: false
# capabilities:
# drop:
# - ALL
# runAsNonRoot: true
# seccompProfile:
# type: RuntimeDefault
containerSecurityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
operator:
image:
# operator.image.registry -- optional image registry prefix (e.g. 1234567890.dkr.ecr.us-east-1.amazonaws.com)
Expand All @@ -70,7 +71,15 @@ operator:
tag: ""
# operator.image.pullPolicy -- image pull policy
pullPolicy: IfNotPresent
containerSecurityContext: {}
# operator.containerSecurityContext -- security context of the clickhouse-operator container, check `kubectl explain pod.spec.containers.securityContext` for details.
# The default meets the restricted Pod Security Standard. The container writes only to the IPC token emptyDir
# (/etc/clickhouse-operator-ipc), so the root filesystem is read-only. Set a key to `null` to drop that default.
containerSecurityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
# operator.resources -- custom resource configuration, check `kubectl explain pod.spec.containers.resources` for details
resources: {}
# limits:
Expand Down Expand Up @@ -119,7 +128,15 @@ metrics:
tag: ""
# metrics.image.pullPolicy -- image pull policy
pullPolicy: IfNotPresent
containerSecurityContext: {}
# metrics.containerSecurityContext -- security context of the metrics-exporter container, check `kubectl explain pod.spec.containers.securityContext` for details.
# The default meets the restricted Pod Security Standard. The container writes only to the IPC token emptyDir
# (/etc/clickhouse-operator-ipc), so the root filesystem is read-only. Set a key to `null` to drop that default.
containerSecurityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
# metrics.resources -- custom resource configuration
resources: {}
# limits:
Expand Down Expand Up @@ -203,8 +220,15 @@ nodeSelector: {}
tolerations: []
# affinity -- affinity for scheduler pod assignment, check `kubectl explain pod.spec.affinity` for details
affinity: {}
# podSecurityContext - operator deployment SecurityContext, check `kubectl explain pod.spec.securityContext` for details
podSecurityContext: {}
# podSecurityContext -- operator deployment SecurityContext, check `kubectl explain pod.spec.securityContext` for details.
# The default meets the restricted Pod Security Standard. Both images run as `nobody` (uid and gid 65534); the user is
# set by number because the kubelet can only verify `runAsNonRoot` against a numeric user. Set a key to `null` to drop that default.
podSecurityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
# topologySpreadConstraints - topologySpreadConstraints affinity for scheduler pod assignment, check `kubectl explain pod.spec.topologySpreadConstraints` for details
topologySpreadConstraints: []
serviceMonitor:
Expand Down
28 changes: 28 additions & 0 deletions dev/test_helm_chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,34 @@ else
report "checksum/files tracks a data change" no "checksum/files did not move when the mounted data changed"
fi

echo
echo "security context"
# The defaults meet the restricted Pod Security Standard. Both images run as `nobody`, a non-numeric
# user, so runAsNonRoot is only verifiable by the kubelet when runAsUser is set by number.
expect_contains "pod runs as non-root uid 65534 by default" "runAsUser: 65534"
expect_contains "pod uses the RuntimeDefault seccomp profile" "type: RuntimeDefault"
restricted_containers="$(render | grep -c "readOnlyRootFilesystem: true")"
if [[ "${restricted_containers}" == "2" ]]; then
report "both containers get the restricted container defaults" yes
else
report "both containers get the restricted container defaults" no "expected 2 containers with readOnlyRootFilesystem, got ${restricted_containers}"
fi
# A user with an image that needs another uid drops a single default by nulling it.
if render --set podSecurityContext.runAsUser=null | awk '/Deployment-clickhouse-operator.yaml/{f=1} /^---/{f=0} f' | grep -qF "runAsUser: 65534"; then
report "podSecurityContext.runAsUser=null drops the uid" no "operator Deployment still sets runAsUser: 65534"
else
report "podSecurityContext.runAsUser=null drops the uid" yes
fi
expect_renders "an empty podSecurityContext still renders" --set-json 'podSecurityContext={}'
# The CRD hook runs at pre-install in the release namespace, so a hook pod the namespace rejects
# fails the whole install. The kubectl image runs as root, so the non-root uid is set explicitly.
hook="$(render | awk '/crd-install-job.yaml/{f=1} f')"
if grep -qF "runAsUser: 65534" <<<"${hook}" && grep -qF "allowPrivilegeEscalation: false" <<<"${hook}"; then
report "crd-install hook gets the restricted defaults" yes
else
report "crd-install hook gets the restricted defaults" no "hook pod is missing runAsUser 65534 or allowPrivilegeEscalation false"
fi

echo
echo "crd-install hook"
# The hook runs at pre-install/pre-upgrade, so anything wrong here fails the whole release with
Expand Down
Loading
0