#[non_exhaustive]pub struct Restriction { /* private fields */ }Expand description
A validated, ready-to-run restriction.
Constructed by Restriction::builder; all validation, the seccomp
compilation, and the Landlock lowering happen in
RestrictionBuilder::build, which freezes the configuration into a
launch plan. run then executes the command under
the restriction and blocks until it terminates.
§Example
Run a command that may read the system trees and a work directory, and nothing else on the filesystem:
use ferroday_cage::{FsAccess, Restriction};
let status = Restriction::builder()
.command("/usr/bin/sort")
.args(["/work/input"])
.landlock_fs(FsAccess::READ | FsAccess::EXECUTE, "/usr")
.landlock_fs(FsAccess::READ | FsAccess::EXECUTE, "/lib")
.landlock_fs(FsAccess::READ, "/etc")
.landlock_fs(FsAccess::READ | FsAccess::WRITE, "/work")
.build()?
.run()?;
assert!(status.success());A Restriction holds no live resources — it is a frozen plan — so it is
Clone and every launch method takes &self, exactly as
Cage is. One restriction can launch the same command any
number of times, concurrently or in sequence.
Implementations§
Source§impl Restriction
impl Restriction
Sourcepub fn resolved_inputs(&self) -> ResolvedInputs
pub fn resolved_inputs(&self) -> ResolvedInputs
The environment this restriction will actually apply.
The counterpart of Cage::resolved_inputs.
Its mount list is always empty: a restriction confines a process in
place rather than building a filesystem for it.
Sourcepub fn builder() -> RestrictionBuilder
pub fn builder() -> RestrictionBuilder
Returns a builder for configuring a restriction.
Sourcepub fn run(&self) -> Result<ExitStatus, Error>
pub fn run(&self) -> Result<ExitStatus, Error>
Runs the command under the restriction and blocks until it terminates.
Returns Ok with the command’s ExitStatus whenever the command
was executed, regardless of its exit code. Err is reserved for the
library failing: spawning the process, a setup step (a Landlock rule
that cannot apply, a rejected filter), or collecting the outcome.
The command runs with the stream dispositions the restriction carries, which are inherited unless the builder said otherwise.
Sourcepub fn run_with(&self, observer: &mut dyn Observer) -> Result<ExitStatus, Error>
pub fn run_with(&self, observer: &mut dyn Observer) -> Result<ExitStatus, Error>
Runs the command under the restriction, streaming its output to the observer, and blocks until it terminates.
Like run, but the command’s standard output and
standard error are captured and delivered to observer as they are
produced, on the calling thread.
Sourcepub fn output(&self) -> Result<Output, Error>
pub fn output(&self) -> Result<Output, Error>
Runs the command under the restriction and returns its exit status together with everything it wrote.
The restriction’s counterpart of Cage::output,
with the same unbounded-capture caution: for a command whose output
volume the caller does not control, stream through an Observer that
caps what it keeps instead.
Sourcepub fn spawn(&self) -> Result<Running<'static>, Error>
pub fn spawn(&self) -> Result<Running<'static>, Error>
Starts the command under the restriction and returns a handle to it.
spawn blocks until the restriction is applied and the command is
executing, so a setup failure is reported here, as the same typed
error run would return. The command runs with
the stream dispositions the restriction carries; the returned Running
waits for,
signals, or kills it.
Sourcepub fn spawn_with<'obs>(
&self,
observer: &'obs mut dyn Observer,
) -> Result<Running<'obs>, Error>
pub fn spawn_with<'obs>( &self, observer: &'obs mut dyn Observer, ) -> Result<Running<'obs>, Error>
Sourcepub fn spawn_terminal(
&self,
terminal: &Terminal,
) -> Result<(Running<'static>, Pty), Error>
pub fn spawn_terminal( &self, terminal: &Terminal, ) -> Result<(Running<'static>, Pty), Error>
Starts the command on a pseudoterminal of its own, returning a handle to it and the caller’s end of the terminal.
The counterpart of
Cage::spawn_terminal, and the fallback
supports it in full: a host-allocated pseudoterminal needs no devpts
instance, so a restriction gets the same interactive story a cage does.
The command process is the session leader here, since a restriction has
no PID namespace and so no init above it.
Trait Implementations§
Source§impl Clone for Restriction
impl Clone for Restriction
Source§fn clone(&self) -> Restriction
fn clone(&self) -> Restriction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Restriction
impl !UnwindSafe for Restriction
impl Freeze for Restriction
impl Send for Restriction
impl Sync for Restriction
impl Unpin for Restriction
impl UnsafeUnpin for Restriction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.