-
Notifications
You must be signed in to change notification settings - Fork 261
encryption: fix freezing key controller #615
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
9e1ce74
654fd05
181c0e9
2977f17
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
@@ -12,6 +13,7 @@ import ( | |
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/util/diff" | ||
| apiserverconfigv1 "k8s.io/apiserver/pkg/apis/config/v1" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
| clientgotesting "k8s.io/client-go/testing" | ||
|
|
||
|
|
@@ -210,6 +212,48 @@ func TestKeyController(t *testing.T) { | |
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "create a new write key when the previous key expired and another read key exists", | ||
| targetGRs: []schema.GroupResource{ | ||
| {Group: "", Resource: "secrets"}, | ||
| }, | ||
| initialObjects: []runtime.Object{ | ||
| encryptiontesting.CreateDummyKubeAPIPod("kube-apiserver-1", "kms", "node-1"), | ||
| encryptiontesting.CreateExpiredMigratedEncryptionKeySecretWithRawKey("kms", []schema.GroupResource{{Group: "", Resource: "secrets"}}, 6, []byte("61def964fb967f5d7c44a2af8dab6865")), | ||
| encryptiontesting.CreateEncryptionKeySecretWithRawKey("kms", nil, 5, []byte("51def964fb967f5d7c44a2af8dab6865")), | ||
| func() *corev1.Secret { | ||
| keysResForSecrets := encryptiontesting.EncryptionKeysResourceTuple{ | ||
| Resource: "secrets", | ||
| Keys: []apiserverconfigv1.Key{ | ||
| { | ||
| Name: "6", | ||
| Secret: base64.StdEncoding.EncodeToString([]byte("61def964fb967f5d7c44a2af8dab6865")), | ||
| }, | ||
| { | ||
| Name: "5", | ||
| Secret: base64.StdEncoding.EncodeToString([]byte("51def964fb967f5d7c44a2af8dab6865")), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| ec := encryptiontesting.CreateEncryptionCfgWithWriteKey([]encryptiontesting.EncryptionKeysResourceTuple{keysResForSecrets}) | ||
| ecs := createEncryptionCfgSecret(t, "kms", "1", ec) | ||
| ecs.APIVersion = corev1.SchemeGroupVersion.String() | ||
|
|
||
| return ecs | ||
| }(), | ||
| }, | ||
| apiServerObjects: apiServerAesCBC, | ||
| targetNamespace: "kms", | ||
| expectedActions: []string{ | ||
| "list:pods:kms", | ||
| "get:secrets:kms", | ||
| "list:secrets:openshift-config-managed", | ||
| "create:secrets:openshift-config-managed", | ||
|
Contributor
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. this only says that something was created ;)
Contributor
Author
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. that's a general issue in this test, isn't it? But what else do we create in the key controller than keys? :)
Contributor
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. yeah, hard to beat that argument :) |
||
| "create:events:kms", | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "no-op when the previous key was migrated and the current one is valid but hasn't been observed", | ||
| targetGRs: []schema.GroupResource{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,11 +34,15 @@ func MigratedFor(grs []schema.GroupResource, km KeyState) (ok bool, missing []sc | |
| return true, nil, "" | ||
| } | ||
|
|
||
| // KeysWithPotentiallyPersistedData returns the minimal, recent secrets which have migrated all given GRs. | ||
| func KeysWithPotentiallyPersistedData(grs []schema.GroupResource, recentFirstSortedKeys []KeyState) []KeyState { | ||
| // KeysWithPotentiallyPersistedDataAndNextReadKey returns the minimal, recent secrets which have migrated all given GRs. | ||
| func KeysWithPotentiallyPersistedDataAndNextReadKey(grs []schema.GroupResource, recentFirstSortedKeys []KeyState) []KeyState { | ||
| for i, k := range recentFirstSortedKeys { | ||
| if allMigrated, missing, _ := MigratedFor(grs, k); allMigrated { | ||
| return recentFirstSortedKeys[:i+1] | ||
| if i+1 < len(recentFirstSortedKeys) { | ||
|
Contributor
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. this looks to be safe, we could have a unit test for it.
Contributor
Author
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. what do you want to test?
Contributor
Author
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. we have tests that "one more read-key" is fine. So this is covered. The rest here is just Golang standard behaviour.
Contributor
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. sgtm. |
||
| return recentFirstSortedKeys[:i+2] | ||
| } else { | ||
| return recentFirstSortedKeys[:i+1] | ||
| } | ||
| } else { | ||
| // continue with keys we haven't found a migration key for yet | ||
| grs = missing | ||
|
|
||
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.
shouldn't we validate if a new key was created? (
validateFuncfunction)