MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / filter_requirements

Function filter_requirements

src/sql/src/rbac.rs:78–95  ·  view source on GitHub ↗

Filters `RbacRequirements` based on the session role metadata and RBAC related feature flags.

(
    catalog: &impl SessionCatalog,
    session_meta: &dyn SessionMetadata,
    rbac_requirements: RbacRequirements,
)

Source from the content-addressed store, hash-verified

76
77/// Filters `RbacRequirements` based on the session role metadata and RBAC related feature flags.
78fn filter_requirements(
79 catalog: &impl SessionCatalog,
80 session_meta: &dyn SessionMetadata,
81 rbac_requirements: RbacRequirements,
82) -> RbacRequirements {
83 // Skip RBAC non-mandatory checks if RBAC is disabled. However, we never skip RBAC checks for
84 // system roles. This allows us to limit access of system users even when RBAC is off.
85 let is_rbac_disabled = !is_rbac_enabled_for_session(catalog.system_vars(), session_meta)
86 && !session_meta.role_metadata().current_role.is_system()
87 && !session_meta.role_metadata().session_role.is_system();
88 // Skip RBAC checks on user items if the session is a superuser.
89 let is_superuser = session_meta.is_superuser();
90 if is_rbac_disabled || is_superuser {
91 return rbac_requirements.filter_to_mandatory_requirements();
92 }
93
94 rbac_requirements
95}
96
97// The default item types that most statements require USAGE privileges for.
98static DEFAULT_ITEM_USAGE: LazyLock<BTreeSet<CatalogItemType>> = LazyLock::new(|| {

Callers 2

check_usageFunction · 0.85
check_planFunction · 0.85

Calls 6

role_metadataMethod · 0.80
system_varsMethod · 0.45
is_systemMethod · 0.45
is_superuserMethod · 0.45

Tested by

no test coverage detected