feat(admin): first-run bootstrap latch + CLI setup [operator §3]

No trust-on-first-use: bootstrap mode is an explicit, MAC-protected latch
(server_config singleton), NOT inferred from "no admin keys". The latch MAC
(ADMIN_KEY_INTEGRITY_SECRET over setup_state|bootstrap_completed_at) means a
DB-write attacker who restores a pre-bootstrap backup or flips the state to
re-open TOFU produces a mismatch the boot path detects and fails closed on.

- migration 20260626000002: server_config (id=1 singleton; setup_state +
  bootstrap_completed_at + integrity_mac).
- db::server_config: read_setup_state -> {Fresh,Uninitialized,Locked,Tampered}
  (MAC-verified); has_any_users; init_server_config (adoption: a live upgrade
  latches `locked` so it never exposes a setup window; a truly empty DB begins
  uninitialized); bootstrap_admin (insert the FIRST active admin AND latch
  locked + hash-chained audit, ONE tx; refuses if an active admin already
  exists); reset_setup (shell recovery; recomputes MAC, preserves admin keys).
- main boot (admin enabled): adopt/await-bootstrap, and FAIL CLOSED on a tampered
  latch.
- smirk-admin: `setup --pubkey` (the supported headless bootstrap) + `reset-setup
  --i-understand`.
- 1 L1 test: Fresh -> locked(valid) -> wrong-secret Tampered -> raw-flip Tampered
  -> reset Uninitialized -> bootstrap refused while an active admin exists.

Deferred (documented): the HTTP /setup/* wizard. Per the spec the CLI / `docker
exec` is the SUPPORTED bootstrap (pure-PaaS without shell is explicitly
unsupported), so the loopback TTY wizard is a later convenience, not load-bearing.
This commit is contained in:
jwinterm
2026-06-27 14:11:28 -04:00
parent 12e4a54c63
commit 67faf8f762
7 changed files with 387 additions and 0 deletions
+12
View File
@@ -280,6 +280,18 @@ pub struct NewAdminKey {
pub activation_deadline: Option<DateTime<Utc>>,
}
/// The singleton bootstrap-latch row (operator §3.2). MAC-protected against
/// restore-to-pre-bootstrap tampering.
#[derive(Debug, Clone, FromRow)]
pub struct ServerConfig {
pub id: i32,
pub setup_state: String,
pub bootstrap_completed_at: Option<DateTime<Utc>>,
pub locked_at: Option<DateTime<Utc>>,
pub updated_at: DateTime<Utc>,
pub integrity_mac: String,
}
/// A row in the tamper-evident privileged-action audit chain.
#[derive(Debug, Clone, FromRow)]
pub struct AdminAuditLog {