Skip to main content

AudienceGuard

Struct AudienceGuard 

Source
pub struct AudienceGuard { /* private fields */ }
Expand description

The whole guard: pure decision (is_readable) plus async resolution (AudienceIndex), fail-closed throughout. One instance is built per request (in query.rs’s register_lakehouse_functions) and shared, via Arc, across every arg-addressed UDTF/UDF the request’s session registers.

Implementations§

Source§

impl AudienceGuard

Source

pub fn new( read_scope: ReadScope, lakehouse_admin: bool, public_view_sets: Vec<String>, index: Arc<AudienceIndex>, ) -> AudienceGuard

Source

pub fn read_scope(&self) -> &ReadScope

The caller’s scope. Exposed so callers with their own row-level filtering (list_partitions) can decide up front whether to even attempt an optimization (e.g. LIMIT pushdown) that’s only valid under ReadScope::All.

Source

pub async fn authorize( &self, id: Uuid, kind: IdKind, fname: &str, ) -> Result<Authorized, DataFusionError>

ReadScope::All ⇒ Ok with no I/O at all. Otherwise resolves id’s owning process’s audience and denies with a uniform, existence-oracle-proof message ({fname}: '{id}' not found or not accessible) on anything but a readable verdict – a resolution error included, never a pass. The real reason (resolved OwnerAudience, the caller’s scope) is logged at debug!, for operators only.

Source

pub async fn readable_ids( &self, ids: &[Uuid], kind: IdKind, ) -> Result<HashSet<Uuid>, DataFusionError>

Batch form of the same rule, for the callers that row-filter (list_partitions) or need an all-or-nothing verdict over a batch (get_payload) rather than a single witness. ReadScope::All ⇒ every id is readable, with no I/O.

Source

pub fn is_public_view_set(&self, view_set_name: &str) -> bool

Whether view_set_name is on the MICROMEGAS_PUBLIC_VIEW_SETS allowlist – an operator declaring every row of a view set readable by any authenticated caller. Shared by Self::global_rows_visible and Self::authorize_view_instance’s rule (2) so the two read the same allowlist through one accessor.

Source

pub fn global_rows_visible(&self, view_set_name: &str) -> bool

list_partitions’ 'global'-row rule: a global partition is a multi-audience file – it has no single owning audience to check against the caller’s scope. Visible under ReadScope::All, when view_set_name is on the public allowlist, or when the caller passes the lakehouse admin gate (the same boolean that already governs the mutating UDTFs/UDFs: a caller who can retire_partitions/regenerate_partitions a global file can see it – no new authority, no new knob).

Source

pub async fn authorize_view_instance( &self, view_set_name: &str, view_instance_id: &str, ) -> Result<(), DataFusionError>

The view_instance(view_set_name, view_instance_id) scan-time check, run by MaterializedView::scan before jit_update – so a caller scoped to one audience cannot trigger JIT materialization of an instance it cannot read.

Rules, in order:

  1. ReadScope::All -> Ok(()), no I/O. Internal, maintenance, --disable-auth, and every inner session built from an Authorized::internal_caller() take this arm.
  2. view_set_name on public_view_sets -> Ok(()). Matches the row-level filter: an operator who declared a view set public has said every row of it is readable, so denying materialization of one of its instances would be incoherent. Confidentiality-only: this leaves the cost/availability residual this method exists to close fully open for any view set an operator puts on the allowlist – any authenticated caller can still force jit_update for arbitrary process/stream ids of a public view set. Deliberate.
  3. view_instance_id == "global" -> Ok(()). Global instances are row-filtered, not call-guarded: jit_update is a no-op for every 'global' instance today (LogView/MetricsView, the only two view sets that accept 'global'), so there is no materialization to protect against, and denying the call would break the legal view_instance('log_entries', 'global') spelling of SELECT * FROM log_entries for no security gain – the row-level filter already filters its rows one at a time. This is a different rule from list_partitions’ global_rows_visible, which gates visibility of partition metadata about a 'global' file with no per-row filter available; reusing it here would deny the log_entries/measures 'global' instances to every non-admin scoped caller, a regression. The invariant that makes this rule sound – 'global' never triggers JIT – lives in each view set’s jit_update impl; a future view set whose 'global' instance does materialize would need to revisit this rule.
  4. view_instance_id parses as a Uuid -> Self::authorize under IdKind::ProcessOrStream, discarding the returned Authorized. The witness exists to gate construction of an inner unscoped session; this call site builds none – jit_update’s CallerContext::internal() is unchanged and stays where it is.
  5. anything else -> the same uniform denial as (4). Fail-closed, matching list_partitions’s “anything else is dropped” rule. Unreachable for today’s view sets (every make_view either accepts 'global' or Uuid::parse_strs, failing at plan time otherwise), so this is a safety net against a future view set with a different id vocabulary.

Trait Implementations§

Source§

impl Debug for AudienceGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Scope for T

§

fn with<F, R>(self, f: F) -> R
where Self: Sized, F: FnOnce(Self) -> R,

Scoped with ownership.
§

fn with_ref<F, R>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Scoped with reference.
§

fn with_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Scoped with mutable reference.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Value for T
where T: Send + Sync + 'static,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more