Allow providing the master API key via MASTER_API_KEY env var #19
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The master API key is only auto-generated on first boot (
main.rs, whenget_master_key()returnsNone) and printed once to stdout. There is no way to pre-define it — unlikeENCRYPTION_KEY, which the operator can supply via env.This blocks automated / declarative deployment: you can't bake the master key into your deploy secrets ahead of time and have a fresh instance come up using it. You currently have to boot, scrape the key from the logs, and feed it back in — not viable for reproducible infra.
Fix
Read a
MASTER_API_KEYenv var at startup (unprefixed, matchingENCRYPTION_KEY/DATABASE_URLinfra-config convention):ENCRYPTION_KEY). Do not print it — the operator already has it.Coordination with #18
Forward-compatible with hashing API keys at rest (#18): the env var always carries the raw key; when #18 lands, the ingestion path here hashes it before storing, exactly like a key created via the API. No change to the env contract.
Picking this up immediately — it unblocks automated ER deployment.
Resolved in
5a0008b.MASTER_API_KEY(unprefixed, likeENCRYPTION_KEY) is read at startup and is authoritative when set:A value under 16 chars is rejected at startup (loud failure beats a weak key in an automated deploy). The seed/generate/match/rotate decision is a pure
decide_master_keyfunction with a unit test per branch; the IO stays inmain.Secrets are never echoed (covers your follow-up on this): an env-provided master key is never printed — only an auto-generated one is (so you can capture it). While here, the encryption-key load paths now log which source they came from (env / file / persisted path) without the key material — they were previously silent.
Forward-compatible with #18: the env carries the raw key; the single equality check and the store write are each in one place for the hashing work to update.
Docs:
MASTER_API_KEYadded to the env table, plus a commenteddocker-compose.ymlexample. Tests: all five decision branches + a DB test proving a rotate makes the new value the master and invalidates the old one. Full suite green (168), clippy and fmt clean.This unblocks pre-defining the key for automated ER deployment.