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

Function check_restrict_to_user_objects

src/sql/src/rbac.rs:327–353  ·  view source on GitHub ↗

When `restrict_to_user_objects` is active, rejects access to system catalog objects. Functions and types are allowed through because they are needed for query execution. All other system items (tables, views, sources, sinks, etc.) are blocked. This is an allow-list — new catalog item types are blocked by default. See: doc/developer/design/20260508_restrict_to_user_objects.md

(
    catalog: &impl SessionCatalog,
    session: &dyn SessionMetadata,
    resolved_ids: &ResolvedIds,
)

Source from the content-addressed store, hash-verified

325///
326/// See: doc/developer/design/20260508_restrict_to_user_objects.md
327fn check_restrict_to_user_objects(
328 catalog: &impl SessionCatalog,
329 session: &dyn SessionMetadata,
330 resolved_ids: &ResolvedIds,
331) -> Result<(), UnauthorizedError> {
332 if !session.restrict_to_user_objects() {
333 return Ok(());
334 }
335 for item_id in resolved_ids.items() {
336 if item_id.is_system() {
337 if let Some(item) = catalog.try_get_item(item_id) {
338 match item.item_type() {
339 CatalogItemType::Func | CatalogItemType::Type => {}
340 _ => {
341 if RESTRICT_TO_USER_OBJECTS_ALLOWED_OIDS.contains(&item.oid()) {
342 continue;
343 }
344 return Err(UnauthorizedError::RestrictedSystemObject {
345 object_name: item.name().item.clone(),
346 });
347 }
348 }
349 }
350 }
351 }
352 Ok(())
353}
354
355/// Checks if a `session` is authorized to use `resolved_ids`. If not, an error is returned.
356pub fn check_usage(

Callers 2

check_usageFunction · 0.85
check_planFunction · 0.85

Calls 9

itemsMethod · 0.45
is_systemMethod · 0.45
try_get_itemMethod · 0.45
item_typeMethod · 0.45
containsMethod · 0.45
oidMethod · 0.45
cloneMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected