Repository navigation
Drop root's supplementary groups when sandboxing student code - #55
Merged
Merged
Conversation
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>
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.
drop_privilegesset 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), sochmod go-rwxstyle group restrictions couldn't rely on the sandbox being outside those groups. This addsos.setgroups([]), called while still root and beforesetuid.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 asagthroughrun.sh:os.getgroups() == [0, 0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27].os.getgroups() == [], anduidis stillag(1000).A new unit test asserts
setgroups([])runs beforesetuid/setgid(the ordering is the real regression risk). The existing privilege-drop scenario now also capturesgetgroups()and, when a worker user is set, asserts group 0 is gone.🤖 Generated with Claude Code