Phase 9, part 4: secrets in the database, encrypted

The server and multi-tenant editions keep keys and tokens in a secrets
table (schema 30, the first migration for both databases), each sealed
with AES-256-GCM under a key derived from SUPERMARKET_SECRET_KEY and bound
to its name. A wrong key stops the start with a clear message;
SUPERMARKET_SECRET_KEY_OLD reseals everything under a new key. Values are
read when asked for, so several copies of the app agree on a refreshed
token. The local edition keeps secrets.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 07:31:41 -07:00
co-authored by Claude Opus 5.5
parent d827d507c1
commit c76a7791ee
9 changed files with 503 additions and 8 deletions
+14 -1
View File
@@ -22,7 +22,20 @@ type Migration struct {
// both are the migrations after schema 29, on both databases: schema 30
// is both[0]. (migrations, before them, are SQLite's own; Postgres starts
// from postgres.sql, which is schema 29 as a whole.)
var both = []Migration{}
var both = []Migration{
// 30
{
Note: "secrets kept in the database, encrypted (server and multi-tenant editions)",
SQLite: `
CREATE TABLE secrets (
name TEXT PRIMARY KEY,
value TEXT NOT NULL, -- v1:<base64 of the nonce and the sealed value>, AES-256-GCM
key_id TEXT NOT NULL, -- which key sealed it: a fingerprint, never the key
updated_at TEXT NOT NULL
);
`,
},
}
// Schema is the schema version this build migrates databases to.
func Schema() int { return len(migrations) + len(both) }