feat(store): encrypt playbook binding secrets at rest
binding.Binding.Secret was persisted as plaintext in the bindings.secret column, so anyone with the SQLite file saw sender-side HMAC secrets. Seal it with AES-256-GCM transparently inside the store: encrypt-on-write, decrypt-on-read. - cipher: AES-256-GCM, 12-byte random nonce, SHA-256-normalised 32-byte key resolved through the secret registry ([bindings].encryption_key). - envelope 'arcie-binding:v1:<fingerprint>:<b64(nonce||ct||tag)>' so a future cipher/KDF change is a version bump and old rows stay readable. - rotation via previous_encryption_keys; key identity is the material's SHA-256 fingerprint embedded in each row. - legacy plaintext rows written before a key was configured stay readable; encryption is not retroactive. - nil cipher (no key configured) preserves the pre-t2db.7 plaintext path. Deferred: captured_events.body redaction upgrade (separate concern, see docs/prds/binding-secret-encryption.md). Refs archie-core-t2db.7
This commit is contained in:
1 parent
8bbed9cdbf
commit
7ee6ee5554
11 files changed
+683
-9
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
)
|
||||
|
||||
// bindingCipherFromConfig resolves the binding at-rest encryption key from
|
||||
// config through the secret registry and returns a store cipher. An unset
|
||||
// encryption_key returns a nil cipher, keeping the legacy plaintext path (the
|
||||
// store's default). See docs/prds/binding-secret-encryption.md.
|
||||
func bindingCipherFromConfig(cfg config.Config, secrets *secret.Registry) (store.BindingCipher, error) {
|
||||
if cfg.Bindings.EncryptionKey == (secret.SecretRef{}) {
|
||||
return nil, nil
|
||||
}
|
||||
active, err := cfg.Bindings.EncryptionKey.Resolve(secrets)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("resolve bindings encryption_key: %w", err)
|
||||
}
|
||||
active = strings.TrimSpace(active)
|
||||
if active == "" {
|
||||
return nil, fmt.Errorf("bindings encryption_key resolved empty")
|
||||
}
|
||||
|
||||
previous := make([]string, 0, len(cfg.Bindings.PreviousEncryptionKeys))
|
||||
for _, ref := range cfg.Bindings.PreviousEncryptionKeys {
|
||||
v, err := ref.Resolve(secrets)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("resolve bindings previous_encryption_key: %w", err)
|
||||
}
|
||||
if v = strings.TrimSpace(v); v != "" {
|
||||
previous = append(previous, v)
|
||||
}
|
||||
}
|
||||
return store.NewBindingCipher(active, previous)
|
||||
}
|
||||
@@ -243,7 +243,13 @@ func (b *boot) openStores(ctx context.Context) error {
|
||||
b.secrets = secrets
|
||||
b.forgeClient, b.token = resolveForge(cfg.Forge, secrets, log)
|
||||
|
||||
st, err := openProductionTaskStore(ctx, taskDBPath(cfg.DBPath))
|
||||
bindingCipher, err := bindingCipherFromConfig(cfg, secrets)
|
||||
if err != nil {
|
||||
log.Error("configure bindings cipher", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
st, err := openProductionTaskStore(ctx, taskDBPath(cfg.DBPath), store.WithBindingCipher(bindingCipher))
|
||||
if err != nil {
|
||||
log.Error("open store", "err", err)
|
||||
return err
|
||||
|
||||
@@ -277,8 +277,8 @@ func resolveForge(cfg config.Forge, secrets *secret.Registry, log *slog.Logger)
|
||||
return client, token
|
||||
}
|
||||
|
||||
func openProductionTaskStore(ctx context.Context, path string) (store.TaskStore, error) {
|
||||
return store.Open(ctx, path)
|
||||
func openProductionTaskStore(ctx context.Context, path string, opts ...store.OpenOption) (store.TaskStore, error) {
|
||||
return store.Open(ctx, path, opts...)
|
||||
}
|
||||
|
||||
func taskDBPath(configuredPath string) string {
|
||||
|
||||
Reference in new issue
Block a user