补充运行时密文校验与迁移取消处理
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-08-30 21:48:29 +08:00
1 parent 3f6536bc87
commit 6de9fb1ebc
4 files changed
+77 -1

No files matched your search

+6
View File
@@ -173,6 +173,9 @@ func newConfigManager(root string, options ConfigLoaderOptions, security ConfigS
if err != nil {
return nil, err
}
if err := ValidateRuntimeSecrets(vault, runtime); err != nil {
return nil, err
}
snapshots, err := NewSnapshotStore(runtime, options.Validation)
if err != nil {
return nil, err
@@ -204,6 +207,9 @@ func (m *ConfigManager) Load(ctx context.Context) error {
if err != nil {
return err
}
if err := ValidateRuntimeSecrets(m.vault, runtime); err != nil {
return err
}
if err := m.snapshots.Publish(runtime); err != nil {
return err
}
+49
View File
@@ -139,6 +139,55 @@ func TestConfigLoaderRejectsMissingPartitionAndGenerationMismatch(t *testing.T)
}
}
func TestConfigManagerRejectsUnavailableRuntimeSecretsAtStartup(t *testing.T) {
root := t.TempDir()
runtime := validMySQLRuntimeConfig(t, root)
otherVault, err := credential.NewVault(t.TempDir())
if err != nil {
t.Fatal(err)
}
foreignCiphertext, err := otherVault.Encrypt("foreign-database-secret")
if err != nil {
t.Fatal(err)
}
runtime.Root.Database.Password.Ciphertext = foreignCiphertext
writeRuntimeFixture(t, root, runtime)
_, err = NewConfigManager(root, ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}})
if !errors.Is(err, ErrSecretUnavailable) {
t.Fatalf("manager construction error = %v, want unavailable secret", err)
}
}
func TestConfigManagerLoadRejectsUnavailableRuntimeSecretsWithoutChangingSnapshot(t *testing.T) {
root := t.TempDir()
options := ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}}
writeRuntimeFixture(t, root, validMySQLRuntimeConfig(t, root))
manager, err := NewConfigManager(root, options)
if err != nil {
t.Fatal(err)
}
current := manager.Snapshot()
otherVault, err := credential.NewVault(t.TempDir())
if err != nil {
t.Fatal(err)
}
foreignCiphertext, err := otherVault.Encrypt("foreign-database-secret")
if err != nil {
t.Fatal(err)
}
current.Root.Database.Password.Ciphertext = foreignCiphertext
writeRuntimeFixture(t, root, current)
if err := manager.Load(context.Background()); !errors.Is(err, ErrSecretUnavailable) {
t.Fatalf("load error = %v, want unavailable secret", err)
}
loaded := manager.Snapshot()
if loaded.Root.Database.Password.Ciphertext == foreignCiphertext {
t.Fatal("rejected load changed the active snapshot")
}
}
func TestConfigManagerApplyPreflightsSnapshotBeforePersisting(t *testing.T) {
root := t.TempDir()
writeRuntimeFixture(t, root, validRuntimeConfig())