Skip to main content

RestrictSelf

Struct RestrictSelf 

Source
pub struct RestrictSelf { /* private fields */ }
Expand description

Builder for calling landlock_restrict_self() without creating a Landlock domain.

Use this when you want to configure landlock_restrict_self() flags without creating a ruleset or a Landlock domain (e.g., muting subdomain audit logs for nested domains).

Only log_subdomains() is available on this builder. Domain-specific setters (log_same_exec(), log_new_exec()) require a Landlock domain via RulesetCreated.

Available since Landlock ABI v7.

no_new_privs is enforced by default; call no_new_privs(false) to opt out.

§Example

use landlock::*;

let status = RestrictSelf::default()
    .log_subdomains(false)?
    .apply()?;
println!("Landlock status: {:?}", status.landlock);

Use set_compatibility() to control how unsupported flags are handled.

apply() returns a RestrictSelfStatus with the Landlock support status and the effective flag states. Its name differs from RulesetCreated::restrict_self() to avoid the redundant RestrictSelf::restrict_self().

Implementations§

Source§

impl RestrictSelf

Source

pub fn no_new_privs(self, yes: bool) -> Self

Configures whether to call prctl(PR_SET_NO_NEW_PRIVS) during apply(). Defaults to true.

This prctl(2) call is never ignored, even if an error was encountered while CompatLevel::SoftRequirement was set.

See RestrictSelfAttr::log_subdomains() for compat-state behavior when toggling this setter on unsupported kernels.

Source

pub fn apply(self) -> Result<RestrictSelfStatus, RulesetError>

Applies the configured restrict_self flags by calling landlock_restrict_self(-1, flags).

If no_new_privs is configured (default), also calls prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) first, since the kernel requires no_new_privs (or CAP_SYS_ADMIN) for landlock_restrict_self(). See no_new_privs() to opt out.

Returns a RestrictSelfStatus with the Landlock support status. Skips the restrict_self syscall if no flags are enforceable.

Trait Implementations§

Source§

impl Compatible for RestrictSelf

Source§

fn set_compatibility(self, level: CompatLevel) -> Self

To enable a best-effort security approach, Landlock features that are not supported by the running system are silently ignored by default, which is a sane choice for most use cases. However, on some rare circumstances, developers may want to have some guarantees that their applications will not run if a certain level of sandboxing is not possible. If we really want to error out when not all our requested requirements are met, then we can configure it with set_compatibility(). Read more
Source§

fn set_best_effort(self, best_effort: bool) -> Self
where Self: Sized,

👎Deprecated: Use set_compatibility() instead
Source§

impl Debug for RestrictSelf

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RestrictSelf

Source§

fn default() -> Self

Returns a new RestrictSelf. This call automatically probes the running kernel to know if it supports Landlock.

Source§

impl RestrictSelfAttr for RestrictSelf

Source§

fn log_subdomains(self, set: bool) -> Result<Self, RulesetError>

Controls logging of denied accesses from nested Landlock domains. Logging is enabled by default. See the kernel documentation. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.