pub struct ToolContext { /* private fields */ }Expand description
Proof that a tool invocation has passed the capability leash, carrying the least-authority caveats it is permitted to act under.
Constructible only inside this crate (see ToolContext::mint, called
solely by crate::Gate::authorize). There is intentionally no public
constructor and no pub field — that un-forgeability is the enforcement.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn caveats(&self) -> &Caveats
pub fn caveats(&self) -> &Caveats
The effective (least-authority) caveats this invocation may act under.
Sourcepub fn sandbox_kind(&self) -> SandboxKind
pub fn sandbox_kind(&self) -> SandboxKind
The OS-level sandbox actually in force for this invocation.
Sourcepub fn strength_floor(&self) -> AxisEnforcement
pub fn strength_floor(&self) -> AxisEnforcement
The required fence strength (ADR 0012 D3): a confinement site refuses to
spawn when the real backend cannot enforce every restricted axis at or
above this floor. Default is the permissive AxisEnforcement::Advisory
(set on the crate::Gate); a strong principal raises it to Kernel.
Sourcepub fn check_exec(&self, program: &str) -> Result<(), ToolError>
pub fn check_exec(&self, program: &str) -> Result<(), ToolError>
Leash check: may this invocation execute program?
Allowed iff exec is All, or the bounded exec scope contains the
program as named (the string passed in, typically argv0 or a
PATH-resolved absolute path) or its basename
(Path::new(program).file_name()).
This is what makes bare-name grants usable: a grant of ["git"]
allows git, /usr/bin/git, and /opt/homebrew/bin/git alike, because
the resolved absolute path the interceptor hands in has basename git.
To pin an exact executable instead, grant a full path: a grant of
["/usr/bin/git"] matches only /usr/bin/git, not a git found
elsewhere on PATH.
Security tradeoff: a bare-name grant authorizes any binary named
git reachable on PATH (PATH ordering / shadowing decides which one
actually runs). When that ambiguity is unacceptable, grant the full
path to pin exactly. A grant that contains a path separator only ever
matches that exact path (its basename is still considered, but a grant
like ["/bin/echo"] will not be matched by a bare echo because the
grant’s own basename echo is compared against the program token, not
the reverse — see [exec_scope_allows]). Out-of-scope programs are
denied here, before the tool spawns anything.
Sourcepub fn check_net(&self, host: &str) -> Result<(), ToolError>
pub fn check_net(&self, host: &str) -> Result<(), ToolError>
Leash check: may this invocation reach network host?
Sourcepub fn check_path_read(&self, path: &Path) -> Result<(), ToolError>
pub fn check_path_read(&self, path: &Path) -> Result<(), ToolError>
Leash check: may this invocation read path?
See Self::check_path_write for the canonicalization contract; the
only difference is which axis (fs_read) is consulted.
Sourcepub fn check_path_write(&self, path: &Path) -> Result<(), ToolError>
pub fn check_path_write(&self, path: &Path) -> Result<(), ToolError>
Leash check: may this invocation write path?
Canonicalizes first, then tests membership (DESIGN §6): the path is
resolved to a real, symlink-free location and rejected if it escapes the
granted scope via .. or a symlink. Membership is a containment test
against each granted scope entry (an entry authorizes that path and its
descendants), computed on canonical paths — never a raw string
prefix. This closes the @repo/../../etc traversal class.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
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 Freeze for ToolContext
impl RefUnwindSafe for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnsafeUnpin for ToolContext
impl UnwindSafe for ToolContext
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<F, T> ConvertInto<T> for Fwhere
T: ConvertFrom<F>,
impl<F, T> ConvertInto<T> for Fwhere
T: ConvertFrom<F>,
Source§fn convert_into(self) -> T
fn convert_into(self) -> T
Self to a value of type T.Source§impl<F, T> ConvertTryFrom<F> for Twhere
F: ConvertInto<T>,
impl<F, T> ConvertTryFrom<F> for Twhere
F: ConvertInto<T>,
Source§impl<F, T> ConvertTryInto<T> for Fwhere
T: ConvertTryFrom<F>,
impl<F, T> ConvertTryInto<T> for Fwhere
T: ConvertTryFrom<F>,
Source§type Error = <T as ConvertTryFrom<F>>::Error
type Error = <T as ConvertTryFrom<F>>::Error
Source§fn convert_try_into(self) -> Result<T, <T as ConvertTryFrom<F>>::Error>
fn convert_try_into(self) -> Result<T, <T as ConvertTryFrom<F>>::Error>
Self to a value of type T.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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