-
Notifications
You must be signed in to change notification settings - Fork 122
NO-JIRA: Add test for KMS to KMS migration #938
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||||||||||||||||||||||||
| package e2e_encryption_kms | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| g "github.com/onsi/ginkgo/v2" | ||||||||||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/runtime" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| operatorencryption "github.com/openshift/cluster-authentication-operator/test/library/encryption" | ||||||||||||||||||||||||||||||||||||
| library "github.com/openshift/library-go/test/library/encryption" | ||||||||||||||||||||||||||||||||||||
| librarykms "github.com/openshift/library-go/test/library/encryption/kms" | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var _ = g.Describe("[sig-auth] cluster-authentication-operator", func() { | ||||||||||||||||||||||||||||||||||||
| g.It("TestKMSEncryptionKMSToKMSMigration [OCPFeatureGate:KMSEncryption][Serial][Timeout:120m][Suite:encryption-kms-2]", func(ctx context.Context) { | ||||||||||||||||||||||||||||||||||||
| testKMSEncryptionKMSToKMSMigration(ctx, g.GinkgoTB()) | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // testKMSEncryptionKMSToKMSMigration tests migration between two distinct KMS providers | ||||||||||||||||||||||||||||||||||||
| // (default Vault instance and secondary Vault instance). | ||||||||||||||||||||||||||||||||||||
| // This test: | ||||||||||||||||||||||||||||||||||||
| // 1. Shuffles the KMS and AES providers to create a randomized migration order | ||||||||||||||||||||||||||||||||||||
| // 2. Migrates between the providers in the shuffled order | ||||||||||||||||||||||||||||||||||||
| // 3. Verifies token is correctly encrypted after each migration | ||||||||||||||||||||||||||||||||||||
| // 4. Switches to identity (off) to verify the resource is re-written unencrypted | ||||||||||||||||||||||||||||||||||||
| func testKMSEncryptionKMSToKMSMigration(ctx context.Context, t testing.TB) { | ||||||||||||||||||||||||||||||||||||
| library.TestEncryptionProvidersMigration(ctx, t, library.ProvidersMigrationScenario{ | ||||||||||||||||||||||||||||||||||||
| BasicScenario: library.BasicScenario{ | ||||||||||||||||||||||||||||||||||||
| Namespace: "openshift-config-managed", | ||||||||||||||||||||||||||||||||||||
| LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + "openshift-oauth-apiserver", | ||||||||||||||||||||||||||||||||||||
| EncryptionConfigSecretName: "encryption-config-openshift-oauth-apiserver", | ||||||||||||||||||||||||||||||||||||
| EncryptionConfigSecretNamespace: "openshift-config-managed", | ||||||||||||||||||||||||||||||||||||
| OperatorNamespace: "openshift-authentication-operator", | ||||||||||||||||||||||||||||||||||||
| TargetGRs: operatorencryption.DefaultTargetGRs, | ||||||||||||||||||||||||||||||||||||
| AssertFunc: operatorencryption.AssertTokens, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| CreateResourceFunc: func(t testing.TB, _ library.ClientSet, namespace string) runtime.Object { | ||||||||||||||||||||||||||||||||||||
| return operatorencryption.CreateAndStoreTokenOfLife(context.TODO(), t, operatorencryption.GetClients(t)) | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+41
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Discarding the passed-in
🔧 Proposed fix CreateResourceFunc: func(t testing.TB, _ library.ClientSet, namespace string) runtime.Object {
- return operatorencryption.CreateAndStoreTokenOfLife(context.TODO(), t, operatorencryption.GetClients(t))
+ return operatorencryption.CreateAndStoreTokenOfLife(ctx, t, operatorencryption.GetClients(t))
},As per coding guidelines, "When a function accepts or has access to a 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||
| AssertResourceEncryptedFunc: operatorencryption.AssertTokenOfLifeEncrypted, | ||||||||||||||||||||||||||||||||||||
| AssertResourceNotEncryptedFunc: operatorencryption.AssertTokenOfLifeNotEncrypted, | ||||||||||||||||||||||||||||||||||||
| ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.TokenOfLife(t) }, | ||||||||||||||||||||||||||||||||||||
| ResourceName: "TokenOfLife", | ||||||||||||||||||||||||||||||||||||
| EncryptionProviders: library.ShuffleEncryptionProviders([]library.EncryptionProvider{ | ||||||||||||||||||||||||||||||||||||
| librarykms.DefaultVaultEncryptionProvider(ctx, t), | ||||||||||||||||||||||||||||||||||||
| librarykms.SecondaryVaultEncryptionProvider(ctx, t), | ||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the helper comment to describe two KMS providers.
Lines 24-25 still say “KMS and AES providers”, but this scenario only shuffles the default and secondary Vault KMS providers, so the comment now misstates the test flow.
Suggested fix
As per coding guidelines, "Comments should be meaningful and add context and/or explain choices that cannot be expressed through clear code."
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines