Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ test-e2e-sno-disruptive: GO_TEST_FLAGS += -p 1
test-e2e-sno-disruptive: test-unit
.PHONY: test-e2e-sno-disruptive

# KMS encryption tests
test-e2e-encryption-kms: GO_TEST_PACKAGES :=./test/e2e-encryption-kms/...
test-e2e-encryption-kms: GO_TEST_FLAGS += -v
test-e2e-encryption-kms: GO_TEST_FLAGS += -timeout 4h
test-e2e-encryption-kms: GO_TEST_FLAGS += -p 1
test-e2e-encryption-kms: test-unit
.PHONY: test-e2e-encryption-kms

clean:
$(RM) ./cluster-kube-apiserver-operator
.PHONY: clean
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
github.com/openshift/library-go v0.0.0-20251205073205-ab8d51820e0b
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github.com/pkg/profile v1.7.0 // indirect
github.com/prometheus/client_golang v1.22.0
github.com/spf13/cobra v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee h1:+S
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 h1:9JBeIXmnHlpXTQPi7LPmu1jdxznBhAE7bb1K+3D8gxY=
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235/go.mod h1:L49W6pfrZkfOE5iC1PqEkuLkXG4W0BX4w8b+L2Bv7fM=
github.com/openshift/library-go v0.0.0-20251205073205-ab8d51820e0b h1:Fh2PJw4DP4zylB7oOu2T1C5rxhI0G36aj1D71vwS5S4=
github.com/openshift/library-go v0.0.0-20251205073205-ab8d51820e0b/go.mod h1:ErDfiIrPHH+menTP/B4LKd0nxFDdvCbTamAc6SWMIh8=
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6 h1:9PoupWybtdTNB7bVBKac/tR5X+3IYydcTIrSyO5QR7E=
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6/go.mod h1:ErDfiIrPHH+menTP/B4LKd0nxFDdvCbTamAc6SWMIh8=
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20251001123353-fd5b1fb35db1 h1:PMTgifBcBRLJJiM+LgSzPDTk9/Rx4qS09OUrfpY6GBQ=
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20251001123353-fd5b1fb35db1/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
Expand Down
79 changes: 79 additions & 0 deletions test/e2e-encryption-kms/encryption_kms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package e2e_encryption_kms

import (
"context"
"fmt"
"math/rand/v2"
"testing"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/operatorclient"
operatorencryption "github.com/openshift/cluster-kube-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. Creates a test secret (SecretOfLife)
// 3. Enables KMS encryption
// 4. Verifies secret is encrypted
// 5. Disables encryption (Identity)
// 6. Verifies secret is NOT encrypted
// 7. Re-enables KMS encryption
// 8. Verifies secret is encrypted again
// 9. Disables encryption (Identity) again
// 10. Verifies secret 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: 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.AssertSecretsAndConfigMaps,
},
CreateResourceFunc: operatorencryption.CreateAndStoreSecretOfLife,
AssertResourceEncryptedFunc: operatorencryption.AssertSecretOfLifeEncrypted,
AssertResourceNotEncryptedFunc: operatorencryption.AssertSecretOfLifeNotEncrypted,
ResourceFunc: operatorencryption.SecretOfLife,
ResourceName: "SecretOfLife",
EncryptionProvider: configv1.EncryptionTypeKMS,
})
}

// TestKMSEncryptionProvidersMigration tests migration between KMS and AES encryption providers.
// This test:
// 1. Deploys the mock KMS plugin
// 2. Creates a test secret (SecretOfLife)
// 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 secret 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: 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.AssertSecretsAndConfigMaps,
},
CreateResourceFunc: operatorencryption.CreateAndStoreSecretOfLife,
AssertResourceEncryptedFunc: operatorencryption.AssertSecretOfLifeEncrypted,
AssertResourceNotEncryptedFunc: operatorencryption.AssertSecretOfLifeNotEncrypted,
ResourceFunc: operatorencryption.SecretOfLife,
ResourceName: "SecretOfLife",
EncryptionProviders: library.ShuffleEncryptionProviders([]configv1.EncryptionType{configv1.EncryptionTypeKMS, library.SupportedStaticEncryptionProviders[rand.IntN(len(library.SupportedStaticEncryptionProviders))]}),
})
}
31 changes: 31 additions & 0 deletions test/e2e-encryption-kms/main_test.go
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)
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())
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.

Loading