k8s: create workspace group-writable in fs-init so non-root job images can write it#395
Open
DJRH wants to merge 1 commit into
Open
k8s: create workspace group-writable in fs-init so non-root job images can write it#395DJRH wants to merge 1 commit into
DJRH wants to merge 1 commit into
Conversation
fs-init runs as uid 1001 and mkdir's the work/externals/github dirs at the default 0755. The pod securityContext uses fsGroup: 1001, so every job container process is in group 1001 — but 0755 grants the group only r-x, so a job image running as a non-root uid other than 1001 can't write the workspace and checkout fails with '.git: Permission denied'. Set umask 002 in fs-init so those dirs are created 0775 (group-writable), letting any job user write the workspace via the fsGroup.
1f7c4d6 to
3af9543
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
kubernetes-novolumecontainer mode, a job whose container image runs as a non-root user with a uid other than 1001 cannot write its own workspace —actions/checkout(and anything that writes the workspace) fails with:Images that run as root or as uid 1001 are unaffected, so this only shows up with hardened app images that use a dedicated non-root user (e.g. uid 8001).
Root cause
In novolume mode the workspace lives on an
emptyDirthat thefs-initcontainer populates.fs-initruns as uid/gid 1001 and creates the work directories with a plainmkdir(default umask022→ mode0755):The pod
securityContextsetsfsGroup: 1001, so every job container process is a member of group 1001 — but a0755directory only grants the groupr-x. A job process running as a non-1001 uid therefore has no write permission on the workspace it's supposed to use.(The classic
kubernetesmode isn't affected: there the workspace is a mounted shared volume that Kubernetes makes group-writable viafsGroup, rather than a directory created byfs-init.)Fix
Set
umask 002infs-initso those directories are created0775(group-writable). Combined with the existingfsGroup: 1001, any job container user can then write the workspace, regardless of its uid.Testing
npm run build-allbuilds cleanly.kubernetes-novolumerunners: with the fix, job containers whose image runs as a non-root uid (≠1001) get adrwxrwsr-xworkspace andactions/checkoutsucceeds where it previously failed with.git: Permission denied.