Skip to main content

CapabilityManager

Struct CapabilityManager 

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

Security context that tracks capability state

Implementations§

Source§

impl CapabilityManager

Source

pub fn new() -> Self

Source

pub fn drop_bounding_set(&mut self) -> Result<()>

Phase 1: Drop the bounding set and clear ambient/inheritable caps.

After this call, CAP_SETUID and CAP_SETGID remain in the effective set so the caller can perform the identity switch (setuid/setgid). Call [finalize_drop] after the identity switch to clear remaining caps.

This follows Docker/runc convention: bounding set is cleared first while CAP_SETPCAP is still in the effective set.

Source

pub fn finalize_drop(&mut self) -> Result<()>

Phase 2: Clear all remaining capabilities (permitted + effective).

Call this AFTER the identity switch (setuid/setgid). If the process switched to a non-root UID, the kernel already cleared these sets; this call makes it explicit and verifies the result.

If no identity switch was needed (process stays root), this performs the actual clear.

Source

pub fn drop_all(&mut self) -> Result<()>

Drop all capabilities in a single call (convenience wrapper).

Equivalent to calling [drop_bounding_set] then [finalize_drop]. Use the two-phase API when an identity switch is needed between phases.

Source

pub fn drop_except(&mut self, keep: &[Capability]) -> Result<()>

Drop all capabilities except the specified ones

For most use cases, we drop ALL capabilities. This method is provided for special cases where specific capabilities are needed.

Source

pub fn apply_sets(&mut self, sets: &CapabilitySets) -> Result<()>

Apply explicit capability sets.

Bounding is handled as a drop-only upper bound; the remaining sets are set exactly to the provided values.

Source

pub fn is_dropped(&self) -> bool

Check if capabilities have been dropped

Source

pub fn verify_no_namespace_caps(production: bool) -> Result<()>

Verify that namespace-creating capabilities are actually absent from the effective set. Seccomp blocks unshare, filters clone namespace flags, and returns ENOSYS for clone3; dropping these capabilities is the independent capability-layer guard. If the check fails in production mode, it returns an error; otherwise it emits a warning.

Trait Implementations§

Source§

impl Default for CapabilityManager

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Instrument for T

Source§

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

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

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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