-
Notifications
You must be signed in to change notification settings - Fork 115
[release-4.21] OCPBUGS-74418: Add KMS test scenarios #844
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
base: release-4.21
Are you sure you want to change the base?
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,82 @@ | ||
| package e2e_encryption_kms | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/rand/v2" | ||
| "testing" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| 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" | ||
| ) | ||
|
|
||
| // TestKMSEncryptionOnOff tests KMS encryption on/off cycle. | ||
| // This test: | ||
| // 2. Creates a test OAuth access token (TokenOfLife) | ||
| // 3. Enables KMS encryption | ||
| // 4. Verifies token is encrypted | ||
| // 5. Disables encryption (Identity) | ||
| // 6. Verifies token is NOT encrypted | ||
| // 7. Re-enables KMS encryption | ||
| // 8. Verifies token is encrypted again | ||
| // 9. Disables encryption (Identity) again | ||
| // 10. Verifies token is NOT encrypted again | ||
| func TestKMSEncryptionOnOff(t *testing.T) { | ||
| // Deploy the mock KMS plugin for testing. | ||
| // NOTE: This manual deployment is only required for KMS v1. In the future, | ||
| // the platform will manage the KMS plugins, and this code will no longer be needed. | ||
| librarykms.DeployUpstreamMockKMSPlugin(context.Background(), t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage) | ||
| library.TestEncryptionTurnOnAndOff(t, library.OnOffScenario{ | ||
| 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)) | ||
| }, | ||
| AssertResourceEncryptedFunc: operatorencryption.AssertTokenOfLifeEncrypted, | ||
| AssertResourceNotEncryptedFunc: operatorencryption.AssertTokenOfLifeNotEncrypted, | ||
| ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.TokenOfLife(t) }, | ||
| ResourceName: "TokenOfLife", | ||
| EncryptionProvider: configv1.EncryptionTypeKMS, | ||
| }) | ||
| } | ||
|
|
||
| // TestKMSEncryptionProvidersMigration tests migration between KMS and AES encryption providers. | ||
| // This test: | ||
| // 1. Deploys the mock KMS plugin | ||
| // 2. Creates a test OAuth access token (TokenOfLife) | ||
| // 3. Randomly picks one AES encryption provider (AESGCM or AESCBC) | ||
| // 4. Shuffles the selected AES provider with KMS to create a randomized migration order | ||
| // 5. Migrates between the providers in the shuffled order | ||
| // 6. Verifies token is correctly encrypted after each migration | ||
| func TestKMSEncryptionProvidersMigration(t *testing.T) { | ||
| librarykms.DeployUpstreamMockKMSPlugin(context.Background(), t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage) | ||
| library.TestEncryptionProvidersMigration(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)) | ||
| }, | ||
| AssertResourceEncryptedFunc: operatorencryption.AssertTokenOfLifeEncrypted, | ||
| AssertResourceNotEncryptedFunc: operatorencryption.AssertTokenOfLifeNotEncrypted, | ||
| ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.TokenOfLife(t) }, | ||
| ResourceName: "TokenOfLife", | ||
| EncryptionProviders: library.ShuffleEncryptionProviders([]configv1.EncryptionType{configv1.EncryptionTypeKMS, library.SupportedStaticEncryptionProviders[rand.IntN(len(library.SupportedStaticEncryptionProviders))]}), | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package e2e_encryption_kms | ||
|
|
||
| import ( | ||
| "math/rand" | ||
| "os" | ||
| "reflect" | ||
| "testing" | ||
| "time" | ||
| "unsafe" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| randomizeTestOrder(m) | ||
|
Member
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. Instead of randomizing manually, I wonder whether we could leverage go's |
||
| os.Exit(m.Run()) | ||
| } | ||
|
|
||
| func randomizeTestOrder(m *testing.M) { | ||
| pointerVal := reflect.ValueOf(m) | ||
| val := reflect.Indirect(pointerVal) | ||
|
|
||
| testsMember := val.FieldByName("tests") | ||
| ptrToTests := unsafe.Pointer(testsMember.UnsafeAddr()) | ||
| realPtrToTests := (*[]testing.InternalTest)(ptrToTests) | ||
|
|
||
| tests := *realPtrToTests | ||
|
|
||
| rand.Seed(time.Now().UnixNano()) | ||
|
Member
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. nit: |
||
| rand.Shuffle(len(tests), func(i, j int) { tests[i], tests[j] = tests[j], tests[i] }) | ||
|
|
||
| *realPtrToTests = tests | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
nit: list numbering starts at 2