-
Notifications
You must be signed in to change notification settings - Fork 273
CNTRLPLANE-3237: Error out when encryption-config Secret contains mismatching KMS providers #2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -657,7 +657,10 @@ func TestFromEncryptionState(t *testing.T) { | |
| } | ||
| grState[gr] = ks | ||
| } | ||
| actualOutput := encryptiondata.FromEncryptionState(grState) | ||
| actualOutput, err := encryptiondata.FromEncryptionState(grState) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error from FromEncryptionState: %v", err) | ||
| } | ||
| expectedOutput := scenario.makeOutput(scenario.writeKeyIn, scenario.readKeysIn) | ||
|
|
||
| if !cmp.Equal(expectedOutput, actualOutput.Encryption.Resources) { | ||
|
|
@@ -705,6 +708,96 @@ func newFakeIdentityKeyForTest() []byte { | |
| return make([]byte, 16) | ||
| } | ||
|
|
||
| func TestFromEncryptionStateKMSProviderConfigValidation(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| encryptionState map[schema.GroupResource]state.GroupResourceState | ||
| expectedErr string | ||
| }{ | ||
| { | ||
| name: "matching provider configs across resources", | ||
| encryptionState: map[schema.GroupResource]state.GroupResourceState{ | ||
| {Resource: "secrets"}: { | ||
| ReadKeys: []state.KeyState{{ | ||
| Key: apiserverconfigv1.Key{Name: "1", Secret: "AAAAAAAAAAAAAAAAAAAAAA=="}, | ||
| Mode: state.KMS, | ||
| KMSConfig: &state.KMSConfig{ | ||
| Encryption: &apiserverconfigv1.KMSConfiguration{APIVersion: "v2", Name: "1", Endpoint: "unix:///var/run/kmsplugin/kms-1.sock"}, | ||
| Provider: encryptiontesting.DefaultKMSProviderConfig, | ||
| }, | ||
| }}, | ||
| }, | ||
| {Resource: "configmaps"}: { | ||
| ReadKeys: []state.KeyState{{ | ||
| Key: apiserverconfigv1.Key{Name: "1", Secret: "AAAAAAAAAAAAAAAAAAAAAA=="}, | ||
| Mode: state.KMS, | ||
| KMSConfig: &state.KMSConfig{ | ||
| Encryption: &apiserverconfigv1.KMSConfiguration{APIVersion: "v2", Name: "1", Endpoint: "unix:///var/run/kmsplugin/kms-1.sock"}, | ||
| Provider: encryptiontesting.DefaultKMSProviderConfig, | ||
| }, | ||
|
Comment on lines
+718
to
+737
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use distinct-but-equal provider configs in the “matching” test case. Line 726 and Line 736 currently reuse the same 🤖 Prompt for AI Agents |
||
| }}, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "mismatched provider configs across resources", | ||
| encryptionState: map[schema.GroupResource]state.GroupResourceState{ | ||
| {Resource: "secrets"}: { | ||
| ReadKeys: []state.KeyState{{ | ||
| Key: apiserverconfigv1.Key{Name: "1", Secret: "AAAAAAAAAAAAAAAAAAAAAA=="}, | ||
| Mode: state.KMS, | ||
| KMSConfig: &state.KMSConfig{ | ||
| Encryption: &apiserverconfigv1.KMSConfiguration{APIVersion: "v2", Name: "1", Endpoint: "unix:///var/run/kmsplugin/kms-1.sock"}, | ||
| Provider: &configv1.KMSConfig{ | ||
| Type: configv1.VaultKMSProvider, | ||
| Vault: configv1.VaultKMSConfig{ | ||
| VaultAddress: "https://vault-a.example.com", | ||
| TransitKey: "key-a", | ||
| }, | ||
| }, | ||
| }, | ||
| }}, | ||
| }, | ||
| {Resource: "configmaps"}: { | ||
| ReadKeys: []state.KeyState{{ | ||
| Key: apiserverconfigv1.Key{Name: "1", Secret: "AAAAAAAAAAAAAAAAAAAAAA=="}, | ||
| Mode: state.KMS, | ||
| KMSConfig: &state.KMSConfig{ | ||
| Encryption: &apiserverconfigv1.KMSConfiguration{APIVersion: "v2", Name: "1", Endpoint: "unix:///var/run/kmsplugin/kms-1.sock"}, | ||
| Provider: &configv1.KMSConfig{ | ||
| Type: configv1.VaultKMSProvider, | ||
| Vault: configv1.VaultKMSConfig{ | ||
| VaultAddress: "https://vault-b.example.com", | ||
| TransitKey: "key-b", | ||
| }, | ||
| }, | ||
| }, | ||
| }}, | ||
| }, | ||
| }, | ||
| expectedErr: `KMS provider config mismatch for keyID 1: configs from different resources must be identical`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| _, err := encryptiondata.FromEncryptionState(tt.encryptionState) | ||
| if tt.expectedErr != "" { | ||
| if err == nil { | ||
| t.Fatal("expected error, got nil") | ||
| } | ||
| if err.Error() != tt.expectedErr { | ||
| t.Fatalf("unexpected error:\n got: %v\n expected: %v", err, tt.expectedErr) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSecretRoundtrip(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what scenarios can this happen? When the user manually change the secrets? Or when there's a bug in our code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mostly this can cause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that too, that's why we want to add an extra check.