Expand description
Authorization seam: MintPolicy, ReadPolicy, and their audience-based implementations
Authorization seam: MintPolicy, ReadPolicy, and the audience-based implementations that
resolve them from a caller’s AuthContext and a static grant map keyed by audience name.
No enforcement lands with this module itself. This module fixes the shape of
authorization – every caller of these traits must deny on Err, and ReadPolicy cannot
express ReadScope::All at all (its widest answer, ReadableAudiences::Every, is still
row-filtered) – while the resolved ReadableAudiences/ReadScope is
consumed downstream by OwnershipRewrite (the row-level filter) and the call-level guard’s UDTF/UDF guards. See
rust/analytics/src/lakehouse/read_scope.rs.
An audience is an opaque label, not a principal encoding. is_valid_audience and
PUBLIC_AUDIENCE define what a name is; AudienceGrants defines who may read or mint into
it. No code here derives an audience from a caller’s identity – see AudienceGrants for the
reasoning.
Structs§
- Audience
Grants - The parsed, validated grant map: “who can access this audience”, keyed by audience name, one
relation per axis (read/mint – AbAC plan’s
group_read_grants/group_mint_grants, kept as one static map here since the DB store (DbAudienceGrantsSource) is checked as a separate source, not merged into this one). - Audience
Mint Policy - The shipped
MintPolicy. Every caller, admin included, may mint only an audience in their mint set –grants[a].mint, nevergrants[a].read(a read grant confers no mint authority, unchanged fromAudienceReadPolicy’s split); being able to readpublicvia its seeded read grant does not imply being able to mint into it – that requires its own grant namingpublicin a"mint"list (in production, the seeded('public', 'mint', '*')row, schema v9). - Audience
Read Policy - The shipped
ReadPolicy: a lookup over anAudienceGrantsmap – and, when aDbAudienceGrantsSourceis attached viawith_store, a second lookup over that store’s snapshot – with no identity derivation anywhere. Resolves the readable set:
Enums§
- Grant
Axis - The Rust side of
audience_grants.axis– which selector list a DB row contributes to, mirroring the JSON grant map’s"read"/"mint"keys. - Readable
Audiences - What a policy resolved a caller may read.
Constants§
- ALL_
AUDIENCES - The grant audience meaning every audience, current and future. Read axis only.
- PUBLIC_
AUDIENCE - The conventional shared audience. Not a built-in read grant – every-principal readability
comes from the seeded
('public', 'read', '*')row (schema v9), an ordinary grant like any other, removable the same way.
Traits§
- Mint
Policy - Resolves the audience a newly minted key may be stamped with.
- Read
Policy - Resolves the set of audiences an authenticated caller may read.
Functions§
- caller_
selectors - The grant selectors
callermatches: a leading"*"(every caller matches it), then"user:<email>"whencaller.emailisSome, then"key:<id>"whencaller.analytics_key_idisSome, then one"group:<g>"per entry incaller.memberships.pub– shared by three consumers:flight_sql_service_impl.rs’sCallerContext::grant_selectors,analytics-web-srv’smy_audienceshandler, and the audience-grant write policy’s per-pair hold check (which must strip the leading"*"before binding the result – a*grant is not something a caller individually holds). - default_
audience_ from_ env - Resolves
{prefix}_DEFAULT_AUDIENCE(falling back toMICROMEGAS_DEFAULT_AUDIENCE) – the deployment default audience, defaulting toPUBLIC_AUDIENCEwhen unset. Resolved once at startup (web_server.rs) so a typo fails fast rather than surfacing as a per-request 400. Empty or otherwise invalid ⇒Err: with one knob there is no “unset” state left for an empty string to mean, so a blank value is a misconfiguration, not an opt-out. - is_
valid_ audience trueifaudis a valid audience name:[A-Za-z0-9_-]{1,255}, checked in bytes – the ASCII-only charset makes byte length and char length agree for every value that can pass, so this doubles as the length check theingestion_api_keys.audienceVARCHAR(255)column enforces on the SQL side.- is_
valid_ grant_ audience trueifaudis a valid audience in a grant:ALL_AUDIENCESor a valid audience name.*is never a valid stamped audience (is_valid_audiencerejects it).- key_
selector - The
key:<key_id>selector naming an analytics API key. - parse_
key_ selector - The key id of a
key:<uuid>selector, only when the uuid is in canonical (lowercase, hyphenated) form. Matching is an exact string compare, so any other spelling would be a selector that never matches. - valid_
selector - A principal selector on either axis of an
AudienceGrantsentry:*(any authenticated principal),user:<email>(matchesAuthContext.email),group:<g>(matches any entry inAuthContext.memberships– the caller’s resolved, transitive local-group closure), orkey:<uuid>in canonical form (matchesAuthContext.analytics_key_id). Validated at parse time;resolve/resolve_audiencenever see an unrecognized shape. This is the only place selector shape is enforced: the tables carry no CHECK for it.