Skip to content

Add securityContexts.disableDefaults flag for OpenShift SCC compatibility#70238

Open
Aaryan123456679 wants to merge 6 commits into
apache:mainfrom
Aaryan123456679:fix/helm-securitycontext-openshift-41630
Open

Add securityContexts.disableDefaults flag for OpenShift SCC compatibility#70238
Aaryan123456679 wants to merge 6 commits into
apache:mainfrom
Aaryan123456679:fix/helm-securitycontext-openshift-41630

Conversation

@Aaryan123456679

Copy link
Copy Markdown
Contributor

OpenShift assigns runAsUser/fsGroup automatically via SCC and rejects pods that hard-code them, so users need to null these out in the rendered pod securityContext. The Helm chart's values.schema.json typed securityContexts.pod.runAsUser/runAsGroup/fsGroup as non-nullable integers (via the vendored io.k8s.api.core.v1.PodSecurityContext definition), so setting them to null failed schema validation before the templates ever rendered — the templates themselves already pass through explicit nulls correctly.

This introduces a new AirflowPodSecurityContext schema definition (not io.k8s.*-prefixed, so it survives vendor_k8s_json_schema.py regeneration) that allows null for these three fields, and points all 16 securityContexts.pod $refs at it instead of the vendored definition.

closes: #41630

Test plan

  • Added test_main_pod_setting_runasuser_fsgroup_null verifying runAsUser/fsGroup render as None when explicitly nulled
  • breeze testing helm-tests --test-type security — 188 passed
  • breeze testing helm-tests --use-xdist (full suite) — 2061 passed
  • Verified via helm template that the schema now accepts the null override and the rendered manifest's spec.template.spec.securityContext reflects the explicit nulls

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)

Generated-by: Claude Code (Sonnet 5) following the guidelines

Comment thread chart/values.schema.json Outdated
@Aaryan123456679
Aaryan123456679 force-pushed the fix/helm-securitycontext-openshift-41630 branch from 7052119 to 9557fef Compare July 22, 2026 18:26

@Miretpl Miretpl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would see it more like adding a flag which would make all of the default options not added. Currently, in most cases (if not in all), if securityContexts.* is empty, in the helper function logic we are adding some values. I think they should not be added there, and if we want to have some default values in the chart for them, they should be in the values.yaml file (version 2.0).

In this PR, I would add a flag for not adding these default values in the helper function when, e.g. securityContexts.pod is {} (default in values.yaml file). This would be, IMHO, much more intuitive for the users; in the end will require less logic to handle and maintain and should be cleaner too.

WDYT?

…exts

OpenShift assigns runAsUser/fsGroup automatically via SCC and rejects
pods that hard-code them, so users need to null these out in the
rendered pod securityContext. The vendored PodSecurityContext schema
required these fields to be integers, so setting them to null failed
Helm's values.schema.json validation before the templates ever
rendered (the templates already pass through explicit nulls
correctly).

Introduces a new AirflowPodSecurityContext schema definition (not
io.k8s.*-prefixed, so it survives vendor_k8s_json_schema.py
regeneration) that allows null for runAsUser/runAsGroup/fsGroup, and
points all 16 securityContexts.pod $refs at it instead of the vendored
definition.

closes: apache#41630
Named after the GitHub issue instead of the actual PR number, which
the check-newsfragment-pr-number CI check expects.
…isableDefaults flag

Explicit null in securityContexts.pod/containers was fragile and made every
call site guess whether to render a key at all. A dedicated flag is more
explicit about intent and lets the chart omit the default runAsUser/fsGroup
(and related) values entirely on platforms like OpenShift where the cluster's
SCC assigns them automatically and rejects hard-coded values.
The OpenShift SCC guidance still described the earlier null-based
workaround, which no longer omits the rendered securityContext keys.
@Aaryan123456679
Aaryan123456679 force-pushed the fix/helm-securitycontext-openshift-41630 branch from 9557fef to bc9eaf8 Compare July 24, 2026 05:50
@Aaryan123456679

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion — that's a cleaner approach. I've reworked the PR accordingly:

  • Added a securityContexts.disableDefaults flag (default false). When set, the chart no longer fills in the default runAsUser/fsGroup (pod) or runAsUser (container) values wherever securityContexts.pod / securityContexts.containers (or the per-component overrides) are left empty — the securityContext key is omitted from the rendered manifest entirely, rather than emitting an explicit null.
  • Reverted the values.schema.json change back to the vendored io.k8s.api.core.v1.PodSecurityContext ref (dropped the earlier AirflowPodSecurityContext nullable-fields workaround), since the flag makes that special-casing unnecessary.
  • Explicit values in securityContexts.pod / securityContexts.containers (global or per-component) still take priority over disableDefaults, so existing fine-grained overrides are unaffected.
  • Updated the newsfragment, production-guide.rst, and test_security_context.py to describe the flag instead of the null-based workaround.

Let me know if this matches what you had in mind, or if you'd adjust the flag's scope or naming.

@Aaryan123456679 Aaryan123456679 changed the title Allow runAsUser and fsGroup to be explicitly null in pod securityContexts Add securityContexts.disableDefaults flag for OpenShift SCC compatibility Jul 24, 2026
…ma description

securityContexts.pod / securityContexts.containers appeared as plain text in
the disableDefaults description, which the docs build renders as prose rather
than code, tripping the spellchecker on the camelCase identifier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helm chart can't remove .securityContexts.runAsUser and securityContexts.fsGroup for Openshift compatibility

3 participants