feat(chart): make pod and sidecar securityContext configurable - #538
feat(chart): make pod and sidecar securityContext configurable#538yugstar wants to merge 2 commits into
Conversation
The csi-driver-spiffe DaemonSet hardcoded the pod-level and per-container securityContext, including privileged: true and runAsUser: 0 on the cert-manager-csi-driver-spiffe container. Operators with Pod Security Standards or compliance requirements could not adjust the security posture without forking the chart. Move the securityContext blocks into values.yaml: - podSecurityContext (pod-level) - securityContext (cert-manager-csi-driver-spiffe) - nodeDriverRegistrarSecurityContext (node-driver-registrar) - livenessProbeSecurityContext (liveness-probe) Each default reproduces the previously hardcoded value exactly, so the rendered DaemonSet is unchanged. The cert-manager-csi-driver-spiffe container keeps privileged: true by default because it mounts pods-mount-dir with mountPropagation: Bidirectional, which Kubernetes only permits for privileged containers. Operators may now opt into a hardened context at their own discretion. This mirrors the same change made to the sibling csi-driver chart in cert-manager/csi-driver#672, keeping the two CSI charts consistent. Regenerated values.schema.json and README.md, and added helm-unittest coverage for the defaults and overrides. Signed-off-by: Aman Raj <aman.yug@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @yugstar. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
There was a problem hiding this comment.
⚠️ Not ready to approve
securityContext: null is explicitly tested/supported by the template but is rejected by the current values.schema.json type definition.
Pull request overview
This PR makes the csi-driver-spiffe Helm chart’s DaemonSet pod- and container-level securityContext configurable via values.yaml, replacing previously hardcoded security context blocks while keeping default rendered manifests semantically unchanged.
Changes:
- Adds new values for pod and per-container security contexts (
podSecurityContext,securityContext,nodeDriverRegistrarSecurityContext,livenessProbeSecurityContext) with defaults matching prior hardcoded settings. - Updates the DaemonSet template to render security contexts from
.Values.*(and omit them when values are unset/null). - Adds helm-unittest coverage and regenerates schema/docs to reflect new values.
File summaries
| File | Description |
|---|---|
| deploy/charts/csi-driver-spiffe/values.yaml | Introduces new securityContext-related values with defaults matching prior template behavior. |
| deploy/charts/csi-driver-spiffe/values.schema.json | Adds schema entries for new values (but currently rejects securityContext: null). |
| deploy/charts/csi-driver-spiffe/tests/securitycontext_test.yaml | Adds tests to ensure defaults are preserved and overrides/null behavior works. |
| deploy/charts/csi-driver-spiffe/templates/daemonset.yaml | Switches hardcoded securityContext blocks to value-driven rendering via with + toYaml. |
| deploy/charts/csi-driver-spiffe/README.md | Documents the new values and their defaults. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 1
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "runAsUser": 0 | ||
| }, | ||
| "description": "Container security context for the cert-manager-csi-driver-spiffe container.\n\nNOTE: privileged is required by default because this container mounts pods-mount-dir with mountPropagation: Bidirectional, which Kubernetes only permits for privileged containers. Setting privileged: false without also changing the mount propagation will prevent the driver pods from starting. See https://kubernetes.io/docs/concepts/storage/volumes/#mount-propagation", | ||
| "type": "object" |
There was a problem hiding this comment.
Thanks for the review. securityContext: null is actually accepted today — Helm treats an explicit null on an optional value as "unset", so the key is dropped during value coalescing before schema validation. helm template -f with securityContext: null renders fine and omits the block, while genuinely invalid types are still rejected (a string gives at '/securityContext': got string, want object).
I also tried the suggested ["object", "null"]. The schema is generated from values.yaml by helm-tool, and # +docs:type=object,null makes it emit no type at all — which would over-permissively accept invalid values like a bare string. So the current type: object is the stricter/correct option and the null case already works. Happy to revisit if you'd prefer a different approach.
|
Hi @yugstar — thank you for the work on this. Before reviewing the chart changes in detail, I spent some time empirically testing whether the driver actually functions with The short version: every variant I could construct with I also looked for legitimate operator use cases for the other knobs in this PR (podSecurityContext, the sidecar fields, per-container
I think the right outcome is to close this PR and instead address #583 with either (1) documentation in the chart README explaining why Happy to be shown wrong if you have an operator scenario in mind that the table in the issue comment does not cover — I would rather find a working unprivileged path than close this PR if one exists. Edit — walking back the secondary point above I overstated the case when I said I "could not find a legitimate operator use case" for
So the narrower recommendation: keep Apologies for the overshoot in the previous comment. |
Following @wallrj-cyberark's empirical testing in cert-manager/csi-driver#583, the cert-manager-csi-driver-spiffe container must run privileged: it mounts pods-mount-dir with mountPropagation: Bidirectional, which Kubernetes only permits for privileged containers. Exposing its securityContext let operators set privileged: false to satisfy a scanner and silently break the driver, so keep it hardcoded with an explanatory comment. Keep the pod-level securityContext and the two sidecar securityContext knobs (node-driver-registrar, liveness-probe), which are legitimate operator customisation points matching the cert-manager/trust-manager#836 precedent. Signed-off-by: Aman Raj <aman.yug@gmail.com>
|
Thank you for taking the time to test this end to end. The writeup in #583 is really helpful and convincing. I have updated both this PR and the companion cert-manager/csi-driver#672 to match your recommendation. What changed:
The values schema, README and helm unittests were regenerated and trimmed accordingly. Happy to also document the privileged requirement in the chart README if you would prefer that over the template comment. |
What
Makes the csi-driver-spiffe DaemonSet's pod- and container-level
securityContextconfigurable throughvalues.yaml, instead of hardcoding it in the template.New values (each defaults to the value that was previously hardcoded):
podSecurityContextsecurityContextcert-manager-csi-driver-spiffenodeDriverRegistrarSecurityContextnode-driver-registrarlivenessProbeSecurityContextliveness-probeWhy
templates/daemonset.yamlhardcodesprivileged: trueandrunAsUser: 0on the main container (andrunAsUser: 0on both sidecars), with no.Values.*overrides. Operators subject to Pod Security Standards (Baseline/Restricted) or security-scanning policies cannot adjust the posture without forking the chart.This is the companion to cert-manager/csi-driver#672 — it applies the identical change to the sibling CSI chart, using the same value names and layout so the two charts stay consistent. It also mirrors the convention already used in the main
cert-managerchart (securityContext/containerSecurityContext).What changes by default
Nothing. Every new value defaults to the exact value that was previously hardcoded, so
helm templateoutput is semantically identical (verified by parsing the before/after manifests and asserting deep-equality, plus a helm-unittest golden suite). Mounting is unaffected: thepods-mount-dirmount and itsmountPropagation: "Bidirectional"are untouched, and the main container keepsprivileged: trueby default — Kubernetes only permits Bidirectional mount propagation on privileged containers, so dropping it outright would stop the driver pods from starting.What becomes possible (opt-in)
Testing
helm templatebefore/after manifests are semantically identical (default render unchanged).make verify-helm-unittest— newtests/securitycontext_test.yaml(defaults preserved + opt-in overrides + null-clears-block); full suite 31/31.make verify-helm-values,verify-helm-lint,verify-helm-kubeconform,verify-pod-security-standardsall pass.values.schema.jsonandREADME.mdregenerated viamake generate-helm-schema generate-helm-docs.Open question
I reused the value names from cert-manager/csi-driver#672 for cross-chart consistency. If maintainers prefer a different layout, happy to adjust — the default render is identical either way.