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

Method check

crates/openshell-server/src/auth/authz.rs:66–103  ·  view source on GitHub ↗
(&self, identity: &Identity, method: &str)

Source from the content-addressed store, hash-verified

64 /// (authentication-only mode for providers like GitHub).
65 #[allow(clippy::result_large_err)]
66 pub fn check(&self, identity: &Identity, method: &str) -> Result<(), Status> {
67 let required = match method_authz::required_role(method) {
68 Some(Role::Admin) => &self.admin_role,
69 // Default to user role for unknown methods, matching the
70 // pre-annotation behavior. The exhaustiveness test ensures
71 // every real RPC has an explicit declaration.
72 Some(Role::User) | None => &self.user_role,
73 };
74
75 // Empty role name = skip role check for this level (auth-only mode).
76 // Scope enforcement still applies if enabled.
77 if !required.is_empty() {
78 // Admin role implicitly satisfies user role requirements.
79 let has_role = identity.roles.iter().any(|r| r == required)
80 || (!self.admin_role.is_empty()
81 && required == &self.user_role
82 && identity.roles.iter().any(|r| r == &self.admin_role));
83
84 if !has_role {
85 debug!(
86 sub = %identity.subject,
87 required_role = required,
88 user_roles = ?identity.roles,
89 method = method,
90 "authorization denied: missing role"
91 );
92 return Err(Status::permission_denied(format!(
93 "role '{required}' required"
94 )));
95 }
96 }
97
98 if self.scopes_enabled {
99 self.check_scope(identity, method)?;
100 }
101
102 Ok(())
103 }
104
105 #[allow(clippy::result_large_err, clippy::unused_self)]
106 fn check_scope(&self, identity: &Identity, method: &str) -> Result<(), Status> {

Calls 3

required_roleFunction · 0.85
check_scopeMethod · 0.80
is_emptyMethod · 0.45