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:
+11
-1
@@ -179,7 +179,17 @@ func run(log *slog.Logger) error {
|
||||
log.Error("writing the CRM state file", "err", err)
|
||||
}
|
||||
|
||||
sec, err := secrets.Open(filepath.Join(dataDir, "secrets.json"))
|
||||
// The local edition keeps its keys and tokens in a file beside the
|
||||
// database; the others, in the database, encrypted.
|
||||
var sec *secrets.Store
|
||||
if cfg.Edition == config.Local {
|
||||
sec, err = secrets.Open(filepath.Join(dataDir, "secrets.json"))
|
||||
} else {
|
||||
sec, err = secrets.OpenDB(database, cfg.SecretKey, cfg.OldKey)
|
||||
if err == nil && cfg.OldKey != nil {
|
||||
log.Warn("secrets: encrypted with the new key; unset " + config.EnvOldKey)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user