MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / ensure_sandbox_scope

Function ensure_sandbox_scope

crates/openshell-server/src/auth/guard.rs:30–51  ·  view source on GitHub ↗
(principal: &Principal, claimed_sandbox_id: &str)

Source from the content-addressed store, hash-verified

28/// store before calling this guard.
29#[allow(clippy::result_large_err)]
30pub fn ensure_sandbox_scope(principal: &Principal, claimed_sandbox_id: &str) -> Result<(), Status> {
31 match principal {
32 Principal::User(_) => Ok(()),
33 Principal::Sandbox(p) => {
34 if p.sandbox_id == claimed_sandbox_id {
35 Ok(())
36 } else {
37 info!(
38 principal_sandbox_id = %p.sandbox_id,
39 requested_sandbox_id = %claimed_sandbox_id,
40 "cross-sandbox access denied"
41 );
42 Err(Status::permission_denied(
43 "cross-sandbox access denied: principal does not own this sandbox",
44 ))
45 }
46 }
47 Principal::Anonymous => Err(Status::unauthenticated(
48 "sandbox-scoped methods require an authenticated caller",
49 )),
50 }
51}
52
53/// Convenience: read the `Principal` out of a request and apply
54/// [`ensure_sandbox_scope`]. Returns the principal so callers can read it

Calls

no outgoing calls