Skip to main content

Capabilities

Struct Capabilities 

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

The capabilities a spec grants a job.

v1 has exactly one kind, filesystem reads under named roots. An empty set grants nothing — deny-by-default is the whole posture, so “no capabilities declared” must never read as “unrestricted”.

Implementations§

Source§

impl Capabilities

Source

pub fn new(read_roots: Vec<PathBuf>) -> Self

Grant read access beneath each of read_roots, and nothing else.

Source

pub fn with_fetch(self, fetch_prefixes: Vec<String>) -> Self

Also grant fetching any URL beginning with one of fetch_prefixes.

Source

pub fn allows_fetch(&self, url: &str) -> bool

Whether url may be fetched.

Prefix matching on the URL as written, deliberately: it is the rule a spec author can predict from reading their own capability line. No normalisation, no host-only matching — Fetch "https://x.org/docs/" grants that subtree and not https://x.org/other, and not http:// either, since the scheme is part of the prefix.

The one thing checked beyond the prefix is that the URL cannot climb out with .., which would otherwise let a granted prefix reach anywhere on the host.

Source

pub fn fetch_prefixes(&self) -> &[String]

The granted fetch prefixes, as configured.

Source

pub fn allows_read(&self, path: &Path) -> bool

Whether path may be read.

Both sides are canonicalized before comparison, and that is the entire substance of this function. The tempting implementation — path.starts_with(root) on the raw strings — admits two escapes:

  • Traversal. /granted/inner/../../secret has /granted/inner as a string prefix while naming a file outside it.
  • Symlinks. A path genuinely under the granted root can name a file anywhere on the system.

canonicalize resolves .. and follows symlinks, so the comparison is between the real locations rather than the spellings. Comparing with Path::starts_with rather than string prefixes additionally means /data-secret is not treated as nested inside /data.

A path that cannot be canonicalized — because it does not exist — is denied. That is deliberate on two counts: a nonexistent path cannot be proven inside the grant, and refusing it here means the decision cannot be made against a file that only appears afterwards.

Note the residual limitation: this resolves the path once, and the caller opens it separately. A sufficiently determined attacker who can swap a symlink between those two steps still has a window. Closing it properly needs the caller to pass an already-open descriptor; see the transport discussion in the cuttlefishd crate docs.

Source

pub fn read_denial(&self, path: &Path) -> Option<ReadDenial>

Why a read was refused, when it was.

Self::allows_read answers yes-or-no, which is the right shape for the decision and the wrong shape for the message. Two very different situations reach it as false: a path the spec never granted, and a granted path that simply is not there. Reporting both as “read not permitted” sends somebody to re-read their capabilities line when what they actually have is a typo in a filename or a manifest listing a file that was moved.

Saying “does not exist” is only safe where the job could have found out anyway. So it is said only when the nearest existing ancestor of the path is itself inside a granted root — a directory the job may already open and read. For anything else the answer stays the undifferentiated refusal, because distinguishing “absent” from “forbidden” outside the grant is exactly the probe a capability list exists to prevent.

Source

pub fn read_roots(&self) -> &[PathBuf]

The granted read roots, as configured.

Trait Implementations§

Source§

impl Clone for Capabilities

Source§

fn clone(&self) -> Capabilities

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 Capabilities

Source§

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

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

impl Default for Capabilities

Source§

fn default() -> Capabilities

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

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