-
Notifications
You must be signed in to change notification settings - Fork 103
CNTRLPLANE-2247:Adding KMS TestKMSEncryptionOnOff test for Routes #644
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 |
|---|---|---|
| @@ -1,20 +1,67 @@ | ||
| package e2e_encryption_kms | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/util/rand" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/cluster-openshift-apiserver-operator/pkg/operator/operatorclient" | ||
| operatorencryption "github.com/openshift/cluster-openshift-apiserver-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: | ||
| // 1. Deploys the mock KMS plugin | ||
| // 2. Enables KMS encryption | ||
| // 3. Verifies secrets are encrypted | ||
| // 4. Disables encryption (Identity) | ||
| // 5. Verifies secrets are not encrypted | ||
| // 6. Re-enables KMS encryption | ||
| // 7. Cleans up | ||
| // | ||
| // TODO: Implement full KMS encryption test once the CI job is validated. | ||
| // 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 | ||
| // 11. Cleans up the KMS plugin | ||
| func TestKMSEncryptionOnOff(t *testing.T) { | ||
| t.Log("KMS encryption on/off test placeholder - CI job validation") | ||
| // 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) | ||
|
|
||
| ctx := context.TODO() | ||
| cs := operatorencryption.GetClients(t) | ||
|
|
||
| ns := fmt.Sprintf("test-kms-encryption-on-off-%s", rand.String(4)) | ||
| _, err := cs.KubeClient.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}}, metav1.CreateOptions{}) | ||
| require.NoError(t, err) | ||
| defer cs.KubeClient.CoreV1().Namespaces().Delete(ctx, ns, metav1.DeleteOptions{}) | ||
|
|
||
| library.TestEncryptionTurnOnAndOff(t, library.OnOffScenario{ | ||
| BasicScenario: library.BasicScenario{ | ||
| Namespace: operatorclient.GlobalMachineSpecifiedConfigNamespace, | ||
| LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + operatorclient.TargetNamespace, | ||
| EncryptionConfigSecretName: fmt.Sprintf("encryption-config-%s", operatorclient.TargetNamespace), | ||
| EncryptionConfigSecretNamespace: operatorclient.GlobalMachineSpecifiedConfigNamespace, | ||
| OperatorNamespace: operatorclient.OperatorNamespace, | ||
| TargetGRs: operatorencryption.DefaultTargetGRs, | ||
| AssertFunc: operatorencryption.AssertRoutes, | ||
| }, | ||
| CreateResourceFunc: func(t testing.TB, _ library.ClientSet, namespace string) runtime.Object { | ||
| return operatorencryption.CreateAndStoreRouteOfLife(context.TODO(), t, operatorencryption.GetClients(t), ns) | ||
| }, | ||
| AssertResourceEncryptedFunc: operatorencryption.AssertRouteOfLifeEncrypted, | ||
| AssertResourceNotEncryptedFunc: operatorencryption.AssertRouteOfLifeNotEncrypted, | ||
| ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.RouteOfLife(t, ns) }, | ||
| ResourceName: "TokenOfLife", | ||
| EncryptionProvider: configv1.EncryptionTypeKMS, | ||
| }) | ||
| } | ||
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.
why is this required ?
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.
E2E framework in this repo is designed that way
cluster-openshift-apiserver-operator/test/e2e-encryption/encryption_test.go
Lines 52 to 74 in 3f56d50
CreateAndStoreRouteOfLifeandRouteOfLifefunctions expect ns.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.
ah, ic, thanks.