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:
@@ -145,3 +145,28 @@ func TestKeys(t *testing.T) {
|
||||
t.Fatal("relative folder accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOldKey(t *testing.T) {
|
||||
env := server()
|
||||
env[EnvOldKey] = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
c, err := Load(envOf(env))
|
||||
if err != nil || len(c.OldKey) != 32 {
|
||||
t.Fatal(c.OldKey, err)
|
||||
}
|
||||
found := false
|
||||
for _, it := range c.Summary() {
|
||||
if it.Name == "Secrets" && strings.Contains(it.Help, "unset "+EnvOldKey) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Error("the summary doesn't say a key change is under way")
|
||||
}
|
||||
env[EnvOldKey] = key
|
||||
if _, err := Load(envOf(env)); err == nil || !strings.Contains(err.Error(), "same key") {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := Load(envOf(map[string]string{EnvOldKey: key})); err == nil || !strings.Contains(err.Error(), "without") {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user