Skip to content

Drop root's supplementary groups when sandboxing student code - #55

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/drop-supplementary-groups
Nov 18, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/drop-supplementary-groups

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

drop_privileges set the sandbox user's uid and gid but never dropped the supplementary groups inherited from root. The sandbox user stayed in group 0 (and others), so chmod go-rwx style group restrictions couldn't rely on the sandbox being outside those groups. This adds os.setgroups([]), called while still root and before setuid.

This is the boundary that PR #53 ("Stop student code from reading the test files") has to defend with owner-only file modes; with the groups dropped, that defense no longer depends on the sandbox happening to lack read bits through a shared group.

Testing

The in-CI scenario harness doesn't pass --worker-username, so it never actually drops privileges. I verified the real behavior in the grader image, running as ag through run.sh:

  • Released image: student code sees os.getgroups() == [0, 0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27].
  • With this change: os.getgroups() == [], and uid is still ag (1000).
  • A normal question still grades (score 1.0).

A new unit test asserts setgroups([]) runs before setuid/setgid (the ordering is the real regression risk). The existing privilege-drop scenario now also captures getgroups() and, when a worker user is set, asserts group 0 is gone.

🤖 Generated with Claude Code

drop_privileges set the sandbox uid and gid but left the supplementary
groups inherited from root in place, so the sandbox user still belonged to
group 0 and others. Group permissions therefore didn't restrict it. Clear
the supplementary groups with setgroups([]) while still root, before setuid.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 18, 2026 22:21
@eliotwrobson
eliotwrobson merged commit a320be4 into main Nov 18, 2026
5 checks passed
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