Expand description
Admin-managed query deny list: fingerprinting, the match
context, and the Postgres-backed, TTL-refreshed cache execute_query checks every query
against.
Admin-managed query deny list: a small set of admin-authored rules, stored in Postgres, cached
in every flight-sql-srv replica, and evaluated at the front of execute_query – before the
session context is built and before planning – so a matching query is rejected for a few
microseconds of work instead of a memory-pool reservation and a wave of object-store reads.
A rule is a boolean SQL expression over a fixed, documented match context (crate::lakehouse::query_deny_list::match_schema)
– parsed and evaluated by DataFusion itself, so there is no grammar of our own to specify or
keep in sync, and no evaluator of our own to get subtly wrong. Rules stand until an admin
removes them explicitly; there is no expiry.
Structs§
- Query
Attribution - Borrowed view of what
execute_queryhas already resolved, in the same column order asmatch_schema.service_account/session/notebook/cellareOptionbecause the corresponding header may be absent; every other field always has a value (falling back to"unknown"upstream when nothing better is available). - Query
Deny List - Owns the Postgres-backed rule store and the compiled, in-memory snapshot every query is
checked against. One instance is owned by
LakehouseContext, mirroringAudienceIndex. - Query
Deny Row - The DB row, exactly as
list_query_denials()returns it and asinsertechoes back. No compiled expression or in-process timestamp here – those exist only for a rule that has been compiled into aDenySnapshot, and a freshly inserted or listed row has not necessarily been through that yet on every replica. - Query
Deny Rule - A row compiled into one snapshot: the row, its planned expression, and the one piece of
in-process state a rule accumulates. Lives only inside a
DenySnapshot.
Constants§
- DEFAULT_
MAX_ RULES - Default value of
MICROMEGAS_QUERY_DENY_MAX_RULES. - DEFAULT_
REFRESH_ SECONDS - Default value of
MICROMEGAS_QUERY_DENY_REFRESH_SECONDS. - MICROMEGAS_
QUERY_ DENY_ MAX_ RULES - Env var: cap on the number of rules in force at once (bounds per-query evaluation cost).
- MICROMEGAS_
QUERY_ DENY_ REFRESH_ SECONDS {prefix}-less env var: snapshot refresh /last_hit_atflush interval, and the bound on cross-replica propagation of a newly inserted or removed rule.
Functions§
- compile_
match_ expr - Parses, validates, and plans
match_exprinto anArc<dyn PhysicalExpr>– the whole evaluator, correct by construction because DataFusion does the parsing and the evaluation. - fingerprint_
of - Literal-stripped fingerprint of a statement: the first 16 hex chars of the SHA-256 of the normalized token stream. Tokenizes internally; the token stream is an implementation detail and does not appear in the signature.
- match_
schema - max_
rules - The cap on rules in force at once, from
MICROMEGAS_QUERY_DENY_MAX_RULES(defaultDEFAULT_MAX_RULES). - skip_
for_ admin_ recovery - The primary escape hatch: the deny-list check is skipped when the caller can reach
the admin functions at all – the same predicate
register_lakehouse_functionsgatesdeny_queries/remove_query_denialon – and the statement mentions one ofdeny_queries/remove_query_denial/list_query_denials: threecontainschecks over the lowercased SQL text, nothing more. No call-position or token analysis: this only ever runs for a query that is already being denied, and the gate it sits behind means any caller it opens for could call those three functions directly anyway. - sorted_
snapshot - Sorts
rulesby(created_at, rule_id), oldest first, and wraps them into aDenySnapshot–pubso tests can build one directly, matching the invariantQueryDenyList::refreshandQueryDenyList::insertmaintain internally.
Type Aliases§
- Deny
Snapshot - The compiled rules, ordered by
(created_at, rule_id), oldest first – so the first match is always the oldest matching rule, on every replica. An alias, not a newtype: nothing hangs behind it.Arc<[_]>rather thanArc<Vec<_>>: the snapshot is immutable once built, and this drops a pointer hop off the per-query path.