Skip to content

Create global container and pod security context configs - #818

Draft
marcleblanc2 wants to merge 2 commits into
mainfrom
marc/global-security-context
Draft

marcleblanc2 wants to merge 2 commits into
mainfrom
marc/global-security-context

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

Open issues

Found in review on 2026-11-13 (review thread). This PR is a draft until the first four are settled.

  1. A component override can leak into other components. The merge only copies the chart default, so a nested override changes the global value for every template rendered after it. With a global pod seccompProfile.type: RuntimeDefault and gitserver.podSecurityContext.seccompProfile.type: Unconfined, six workloads render Unconfined: gitserver, plus cadvisor, blobstore, frontend, codeintel-db, and codeinsights-db. Fix: deepCopy the global and the override too, in all four copies of the helper
  2. The branch removes the redis: keep config checksum stable across chart versions #989 Redis fix. The sourcegraph.redis.conf helper, tests/redisConfigChecksum_test.yaml, and the changelog line are gone, and Git merges that without a conflict. Redis would again restart on every chart version bump when config.enabled is set
  3. A default install prints the cadvisor "privileged set to false" warning. NOTES.txt reads cadvisor.containerSecurityContext.privileged, which is now an empty override; the container itself still renders privileged: true
  4. Conflicts with main in values.yaml, README.md, and the syntactic code-intel worker Deployment; the fsGroup logic from Allow syntactic-code-intel-worker /tmp scratch on a per-pod PVC #987 needs porting to the merged helpers
  5. "Existing overrides continue as-is" is not true for a whole-map null. frontend.containerSecurityContext: null rendered securityContext: null before, and now renders the chart defaults (runAsUser: 100 and the rest). Honor an explicit null, or add a breaking-change changelog entry
  6. The global value does not reach every pod, and can produce a combination Kubernetes rejects.
    • Missed: the dind chart's private-docker-registry StatefulSet, dind gVisor mode, and executor job pods
    • A global allowPrivilegeEscalation: false renders next to privileged: true on cadvisor and dind. Kubernetes documents that combination as invalid; not run on a cluster
    • With --reuse-values, the stored old defaults act as overrides, and the global is ignored without a message
  7. Not in the description or a changelog: pgsql-exporter gains allowPrivilegeEscalation: false, so the three database pods restart on upgrade; a new executor.enabled value in the k8s executor chart gates only the Deployment and ConfigMap; no chart has a changelog entry
  8. Tests cover one new and one changed case. Nothing covers precedence, nested maps, nulls, the other three charts, or NOTES.txt

Not tested on a cluster: the first three were reproduced with helm template and a client-side dry run, and with the conflicts unresolved there is no chart to deploy that matches what would merge.

Problem:

  • When customers need to modify containerSecurityContext and / or podSecurityContext, they generally need to modify the same on all containers or all pods
  • For example, customers running in RedHat OpenShift must set runAsUser, runAsGroup, and fsGroup on all containers / pods to the same UID / GID assigned to their Kubernetes namespace (OpenShift Project)
  • Specific customer examples provided in Slack thread
  • This creates a bloated and hard-to-maintain override file, with scads of duplicate lines, or relies on using YAML hacks

Solution:

  • Create global configs, .Values.sourcegraph.containerSecurityContext and .Values.sourcegraph.podSecurityContext, so customers can set the global configs in one place, and if set, override our defaults
  • Renamed our default containerSecurityContext and podSecurityContext to defaultContainerSecurityContext and defaultPodSecurityContext, and created empty containerSecurityContext and podSecurityContext keys, so customers who already define overrides for these will continue as-is, without change, and this allows customers to set both the global configs to override our defaults, and override specific configs for specific pods / containers.

Linear issue FEIE-301: Usability: Create instance-wide config for default podSecurityContext and containerSecurityContext

Linked PRs

  • fix/resources: Drop unused ports, Services, Role verbs, and settings #1016 deletes the k8s executor's http-debug port 6060 and the executor-<queueName> Service. This PR now deletes them too (4ce480c), so the Service no longer conflicts. executor.Deployment.yaml still conflicts on one line, next to the removed port: keep this PR's sourcegraph.containerSecurityContext line

Checklist

Test plan

  • helm unittest and helm lint pass, for all 4 charts

Tested with helm template commands and compared diffs, using:

  • Default values.yaml
  • override.yaml files from 3 different customers

@marcleblanc2
marcleblanc2 requested a review from a team February 4, 2026 09:07
@michaellzc
michaellzc force-pushed the marc/global-security-context branch from 26ba364 to 7a23a3a Compare February 18, 2026 00:52
@marcleblanc2
marcleblanc2 force-pushed the marc/global-security-context branch from 7a23a3a to 8d667bc Compare October 30, 2026 22:00
@github-actions

Copy link
Copy Markdown

Add .Values.sourcegraph.containerSecurityContext and
.Values.sourcegraph.podSecurityContext so customers (e.g. OpenShift) can set
runAsUser / runAsGroup / fsGroup once for every container and pod.

Rename each component's shipped defaults to defaultContainerSecurityContext /
defaultPodSecurityContext and add empty containerSecurityContext /
podSecurityContext override keys. Templates render the 3-tier merge
(component default -> global -> component override) through shared helpers
in templates/_helpers/_securityContext.tpl, copied into all four charts.

- precise-code-intel-worker derives fsGroup from the merged container runAsGroup
- cadvisor gates /dev/kmsg on the merged privileged value
- k8s executor keeps the deprecated executor.securityContext pod fallback
- dind executor keeps dind.gVisor.securityContext as a full replacement
- otel-agent and otel-collector pods gain pod security context keys

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a18eb0-b6fb-7675-8f04-2fc05d2fe567
#1016 deletes the executor's http-debug
port 6060 and the executor-<queueName> Service in front of it: the executor
has not served that port since Sourcegraph 4.1. Making the same deletions
here keeps this PR and #1016 from conflicting in those files.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d269-2788-7075-b66b-b87e3087047d
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2
marcleblanc2 marked this pull request as draft November 13, 2026 10:02

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