feat(sandbox): drop root privileges after initialization on macOS#457
Merged
Conversation
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.
macOS counterpart of #456. Under sudo, rustnet kept euid 0 for its whole lifetime even though root is only needed to open the BPF/PKTAP capture devices.
After capture init the process now drops to SUDO_UID/SUDO_GID (or nobody for plain root), before Seatbelt is applied so the profile needs no setuid allowances. Pre-created export files are chowned to the target user so PCAP/JSONL reopens keep working. Opt out with --no-uid-drop or --no-sandbox; --sandbox-strict fails if the drop fails.
The default PKTAP attribution path is unaffected (process metadata arrives in-band on the open capture fd); the lsof fallback then only sees the target user's processes (documented in SECURITY.md).
Verified on macOS 26.5: sudo run at uid 501 with Seatbelt fully enforced and exports written post-drop, nobody fallback (-2) for plain root, and --no-uid-drop keeping root. fmt/clippy/tests clean; Linux build cross-checked.
Rebased on main after #456: the uid-drop wiring in cli.rs/main.rs is now shared with Linux (privdrop re-exported at the platform level). Expect a trivial conflict with #458 for whichever merges second; I'll rebase.