Skip to content

fix: merge configured pod securityContext in agent mode (ENG-809) - #347

Merged
jasonopslevel merged 1 commit into
mainfrom
eng-809-merge-agent-securitycontext
Nov 19, 2026
Merged

jasonopslevel merged 1 commit into
mainfrom
eng-809-merge-agent-securitycontext

Conversation

@jasonopslevel

Copy link
Copy Markdown
Contributor

Written by Claude (Claude Code). Please review it the way you would any automated change.

Resolves ENG-809.

Problem

In agent mode, getPodObject replaced the pod securityContext from --config with a hard-coded runAsUser: 0, fsGroup: 0, so anything the pod config set there was silently dropped. On prod-sandbox this left the projected EKS Pod Identity token readable only by root, and CodingAgentV3 jobs (which drop to node) failed Bedrock auth with EACCES.

Change

  • Agent mode now starts from a deep copy of podConfig.SecurityContext and sets RunAsUser and FSGroup to 0 only when they are unset. Docker-in-Docker still runs as root by default.
  • No change with no pod config (0/0 as before) and no change in non-agent mode.
  • The shared pod config is not mutated (it's deep-copied before defaults are applied).

Tests

TestGetPodObject_AgentModeSecurityContextMerge in src/pkg/k8s_test.go:

case result
agent mode, no config runAsUser 0, fsGroup 0 (unchanged)
agent mode, fsGroup: 1000 only runAsUser 0, fsGroup 1000
agent mode, every field set config wins
non-agent mode, empty / fsGroup: 1000 passed through unchanged

Each case also checks that the pod config was not mutated. go test ./... and go vet ./... pass locally.

Kind verification (ticket's open question)

Result: it works. With fsGroup: 1000, uid 1000 can read the projected service-account token.

Setup: kind v1.35.0 (kind-opslevel-runner). The pod was shaped like agent-mode output: pod securityContext {runAsUser: 0, fsGroup: <N>}, a privileged container, and a projected serviceAccountToken volume (audience pods.eks.amazonaws.com) mounted at /var/run/secrets/pods.eks.amazonaws.com/serviceaccount. A node user (uid/gid 1000) was added in the container.

ls -ln token setpriv --reuid=1000 --regid=1000 --init-groups cat <token>
fsGroup: 1000 -rw-r----- 0 1000 ✅ reads the token
fsGroup: 0 (today's behaviour) -rw-r----- 0 0 ❌ Permission denied

The kubelet wrote the token as 0640 with group set to the fsGroup, not 0600 owned by the runAsUser, so the 0600 concern in the ticket doesn't apply when runAsUser is 0 and fsGroup is set.

Caveats: this ran on kind, not EKS. On EKS the Pod Identity webhook injects the volume, but the kubelet sets file ownership the same way. The read relies on uid 1000 being in group 1000; in the node image that's its primary group.

Follow-ups (out of scope)

  • Set fsGroup: 1000 in the prod-sandbox pod config (opslevel-kubernetes) after a runner release.
  • Then remove the image-side token copy in the monolith.

🤖 Generated with Claude Code

Agent mode replaced the pod securityContext from the pod config with a
hard-coded runAsUser 0 / fsGroup 0, silently dropping any configured
values. Start from the configured securityContext and default RunAsUser
and FSGroup to 0 only when they are unset.
@jasonopslevel
jasonopslevel merged commit ac0d04f into main Nov 19, 2026
4 checks passed
@jasonopslevel
jasonopslevel deleted the eng-809-merge-agent-securitycontext branch November 19, 2026 18:21
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.

2 participants