pub struct Builder { /* private fields */ }Expand description
Policy builder for filesystem grants, network scope, and syscall denials.
Start with Profile::deny_all or derive a policy with Profile::edit.
Filesystem grants and capabilities accumulate, network scope is replaced by
each network call, and syscall denials compose by union.
Post-apply narrowing is separate; see Restrictions.
§Example
use sandbox::{Network, Profile, Syscalls};
let profile = Profile::deny_all()
.name("example_worker")
.read_exec("/usr/lib")
.read_write("/var/lib/worker")
.network(Network::None)
.syscalls(Syscalls::deny(["execve", "execveat"]))
.build();§Linux filesystem grants
Grants bind existing host paths at the same paths in the worker’s root.
Host-side symlinks are followed when binding a source. The bind captures the
source at startup; replacing the host file by rename does not retarget it.
Ordinary grants preserve host restrictions and add nosuid and nodev;
use device for a single device node.
Grants for the filesystem root (/) are unsupported and rejected by
apply before staging or mounting the filesystem.
Duplicate grants and lexically nested paths combine independently of
declaration order, retaining permissions already granted by an ancestor.
Combinations requiring both write and execute access are rejected during
apply.
The backend also provides writable scratch storage at /tmp and requires
either a fresh /proc mount or a restricted bind of the host’s /proc.
These are implicit backend facilities, not explicit grants added by this
builder. Landlock, where enforced, further limits proc access; the proc
mount’s own restrictions still apply.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn name(self, name: &'static str) -> Self
pub fn name(self, name: &'static str) -> Self
Attach a human-readable name used in tracing and error messages. Not consulted by the sandbox itself.
Sourcepub fn read(self, path: impl AsRef<Path>) -> Self
pub fn read(self, path: impl AsRef<Path>) -> Self
Grant read-only access to path, without allowing execution.
On Linux the bind is read-only and noexec; directory traversal is
still allowed. Use Builder::read_exec for shared libraries,
interpreters, and other executable code.
Sourcepub fn read_exec(self, path: impl AsRef<Path>) -> Self
pub fn read_exec(self, path: impl AsRef<Path>) -> Self
Grant read and execute access to path, without allowing writes.
Use this for executable mappings, including shared libraries, rather
than Builder::read.
Sourcepub fn read_write(self, path: impl AsRef<Path>) -> Self
pub fn read_write(self, path: impl AsRef<Path>) -> Self
Grant read and write access to path. The path is mounted
non-executable, so a worker cannot execute data it can write.
Sourcepub fn device(self, path: impl AsRef<Path>) -> Self
pub fn device(self, path: impl AsRef<Path>) -> Self
Grant read, write, and ioctl access to a single device node.
Unlike ordinary filesystem grants, this permits device-node use. The Linux backend rejects sources that are not character or block devices. Existing host mount restrictions and device permissions remain.
Sourcepub fn network(self, scope: Network) -> Self
pub fn network(self, scope: Network) -> Self
Grant network reachability up to scope.
The default (from Profile::deny_all) is Network::None — an
empty network namespace with no peer. Network::Unrestricted keeps
the worker in the caller’s network namespace.
Sourcepub fn syscalls(self, policy: Syscalls) -> Self
pub fn syscalls(self, policy: Syscalls) -> Self
Add to the worker’s syscall-filtering policy.
Syscall filtering is opt-in per worker class: the default is
Syscalls::Unfiltered (no seccomp filter). Syscalls::Deny
installs a seccomp filter that blocks the crate’s built-in set of
dangerous, namespace-escape, and historically CVE-prone syscalls, plus
any additional syscalls named in the list.
Successive calls compose monotonically: deny lists are unioned while
preserving first-seen order, and Syscalls::Unfiltered is the
identity. Once a base profile opts into filtering, a derived profile
cannot remove that filter or any of its denials.
Sourcepub fn capability(self, cap: Capability) -> Self
pub fn capability(self, cap: Capability) -> Self
Grant a named platform capability (e.g. a Windows LPAC capability).
Capabilities with no analogue on the current platform are a no-op.