-
Notifications
You must be signed in to change notification settings - Fork 117
CNTRLPLANE-2589: Migrate test/e2e-encryption to Ginkgo v2 framework #839
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
Merged
openshift-merge-bot
merged 8 commits into
openshift:master
from
ropatil010:migrate-e2e-encryption
Mar 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac1c999
Migrate encryption and OIDC e2e tests to Ginkgo v2 framework
d931a2a
Improve OIDC e2e test integration with Ginkgo v2
c2e56d6
Fix Ginkgo v2 migration issues in OIDC e2e test
f3eb497
Migrate e2e-encryption-kms tests to Ginkgo v2 framework
e378c68
Add missing KMS encryption type support to complete Ginkgo v2 migration
e857f14
Refactor feature gate checks and fix OIDC test race condition
5eac65a
Remove unused imports from KMS encryption test
c2a1e31
Address PR review feedback for e2e test improvements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package e2eencryptionkms | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/rand/v2" | ||
| "testing" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/api/features" | ||
| testlibrary "github.com/openshift/cluster-authentication-operator/test/library" | ||
| 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] authentication operator", func() { | ||
| g.It("[Encryption][Serial] TestKMSEncryptionOnOff [Timeout:2h]", func() { | ||
| testKMSEncryptionOnOff(g.GinkgoTB()) | ||
| }) | ||
|
|
||
| g.It("[Encryption][Serial] TestKMSEncryptionProvidersMigration [Timeout:2h]", func() { | ||
| testKMSEncryptionProvidersMigration(g.GinkgoTB()) | ||
| }) | ||
| }) | ||
|
|
||
| // testKMSEncryptionOnOff tests KMS encryption on/off cycle. | ||
| // This test: | ||
| // 1. Deploys the mock KMS plugin | ||
| // 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.TB) { | ||
| ctx := context.Background() | ||
| testClients := testlibrary.NewTestClients(t) | ||
|
|
||
| // Check if KMS encryption feature gates are enabled, skip if not | ||
| testlibrary.CheckFeatureGatesOrSkip(t, ctx, testClients.ConfigClient, features.FeatureGateKMSEncryption, features.FeatureGateKMSEncryptionProvider) | ||
|
|
||
| // TODO: Remove this skip once the authentication operator fully supports KMS encryption. | ||
| // Currently, while the API accepts encryption.type: "KMS" and the operator mounts the KMS | ||
| // plugin socket, it does not generate the EncryptionConfiguration with KMS provider stanza. | ||
| // This causes tests to timeout waiting for encryption keys to be created and migration to complete. | ||
| // See: https://redhat.atlassian.net/browse/OCPSTRAT-108 it is still under techincal preview | ||
| t.Skip("Skipping KMS encryption test: operator implementation is incomplete") | ||
|
|
||
| // 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(ctx, t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage) | ||
| testlibrary.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.TB) { | ||
| ctx := context.Background() | ||
| testClients := testlibrary.NewTestClients(t) | ||
|
|
||
| // Check if KMS encryption feature gates are enabled, skip if not | ||
| testlibrary.CheckFeatureGatesOrSkip(t, ctx, testClients.ConfigClient, features.FeatureGateKMSEncryption, features.FeatureGateKMSEncryptionProvider) | ||
|
|
||
| // TODO: Remove this skip once the authentication operator fully supports KMS encryption. | ||
| // Currently, while the API accepts encryption.type: "KMS" and the operator mounts the KMS | ||
| // plugin socket, it does not generate the EncryptionConfiguration with KMS provider stanza. | ||
| // This causes tests to timeout waiting for encryption keys to be created and migration to complete. | ||
| // See: https://redhat.atlassian.net/browse/OCPSTRAT-108 it is still under techincal preview | ||
| t.Skip("Skipping KMS encryption test: operator implementation is incomplete") | ||
|
|
||
| librarykms.DeployUpstreamMockKMSPlugin(ctx, t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage) | ||
| testlibrary.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))]}), | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,82 +1,13 @@ | ||
| package e2e_encryption_kms | ||
| package e2eencryptionkms | ||
|
|
||
| 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, | ||
| }) | ||
| testKMSEncryptionOnOff(t) | ||
| } | ||
|
|
||
| // 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))]}), | ||
| }) | ||
| testKMSEncryptionProvidersMigration(t) | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.