Expand description
DB-backed API key authentication DB-backed API key authentication.
Holds API keys in two Postgres tables — ingestion_api_keys and
analytics_api_keys (migration v5, rust/ingestion/src/sql_migration.rs) —
each row storing only a SHA-256 hash of the key, plus a
created_at/created_by/last_used_at/revoked_at/revoked_by audit trail.
crate::db_api_key::DbApiKeyAuthProvider validates by hash-indexed lookup behind a short-TTL
moka cache.
Structs§
- DbApi
KeyAuth Provider - DB-backed API key authentication provider, bound to one
ApiKeyTable. - DbApi
KeyConfig - Cache and audit knobs for
DbApiKeyAuthProvider, read from env with defaults.
Enums§
- ApiKey
Table - Which key table a provider (or the management API) is bound to.
Functions§
- dedicated_
key_ store_ pool - Builds a small, dedicated connection pool for key-store lookups from an
existing pool’s options — rather than sharing the caller’s lake pool
directly. Inherits the lake pool’s options wholesale (including any
after_connect/before_acquirehooks, e.g. the read-only-connection checks inmicromegas_ingestion::data_lake_connection), not just its connect options, so a strict or prefer-fallback lake pool’s write-session guarantee carries over to the key store.max_connections(4),acquire_timeout(2s): a credential flood or a DB outage on the key-lookup path can therefore never starve the write path of connections, and a lookup fails fast into its 503 rather than blocking up to sqlx’s default 30sacquire_timeout. - generate_
key - 256 bits of OS entropy, base64url-nopad,
mmk_-prefixed.mmk_makes minted keys recognizable to secret scanners; it is cosmetic to validation, sincehash_keycovers the whole string rather than parsing the prefix. - hash_
key - SHA-256 of the full key string. The only place a key is hashed; the mint
routes (
rust/analytics-web-srv/src/ingestion_keys.rs,analytics_keys.rs) and this provider’s lookup go through the same digest definition. - is_
read_ only_ error - True when
err’s SQLSTATE is25006(cannot execute ... in a read-only transaction) – the code thelast_used_atupdate raises when its connection turned read-only mid-query. A local copy ofmicromegas_ingestion::data_lake_connection::is_read_only_violation’s check:authdoesn’t depend oningestion. - key_
store_ has_ live_ rows SELECT EXISTS(SELECT 1 FROM <table> WHERE revoked_at IS NULL)— used byProviderBuilder::build()(rust/auth/src/default_provider.rs) to decide whether a non-empty key store counts as “auth configured” on its own. A missing relation (e.g. a schema that has not reached migration v5 yet) surfaces as anErrhere and must be propagated, never treated as “empty”.