Skip to main content

Builder

Struct Builder 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Profile

Finalize the policy.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more