Expand description
Post-initialization sandboxing and privilege dropping for rustnet.
One apply_sandbox entry point with a platform backend behind it:
- Linux:
PR_SET_NO_NEW_PRIVS, capability drops (CAP_NET_RAW, CAP_BPF, CAP_PERFMON), the root uid drop, and Landlock filesystem/network/scope restrictions (behind thelandlockfeature). - macOS: the root uid drop, then a Seatbelt profile restricting outbound
network, credential reads, and writes under user home directories
(behind the
macos-sandboxfeature). - Windows: dangerous token privileges removed and a job object that blocks child process creation.
- FreeBSD: the root uid drop (Capsicum is planned).
§Application order contract
Sandboxing is a post-initialization step. Callers must apply it only after every privileged operation is done, in this order:
- Open capture handles (raw sockets, BPF/PKTAP devices, Npcap): the descriptors stay valid across the sandbox and uid drop.
- Load eBPF programs (needs CAP_BPF/CAP_PERFMON, which the sandbox drops).
- Securely open output files (logs, PCAP exports) and, when dropping root,
hand ownership to the drop target (
privdrop::chown_to_target). Retain these descriptors for writing after the drop instead of reopening paths or granting pathname write exceptions. - Call
apply_sandboxon the main thread. - Only then spawn worker threads that should inherit the restrictions: Landlock domains and capability sets are per-thread state that new threads inherit from their spawner; threads started before step 4 keep the unrestricted state.
Long-lived workers should not start before the sandbox. Capture handles and eBPF maps opened during initialization remain usable through their existing descriptors after capability and identity reduction. Workers created after step 4 inherit the reduced capability set and sandbox restrictions.
Modules§
- privdrop
- Root privilege drop (setuid) for Linux, macOS, and FreeBSD
Structs§
- Privilege
Drop Error - A requested root UID/GID transition failed.
- Sandbox
Config - Configuration for the sandbox
- Sandbox
Report - Result of sandbox application
Enums§
- Sandbox
Mode - Sandbox enforcement mode
- Sandbox
Status - Status of sandbox application
Functions§
- apply_
sandbox - Apply the sandbox with the given configuration.
- apply_
sandbox_ allowing_ dns - Apply the sandbox with its narrow platform DNS exception enabled.