Skip to content

Commit c9d8d3e

Browse files
Merge pull request #844 from gangwgr/backport-kms-cases-4.21
[release-4.21] OCPBUGS-74418: Add KMS test scenarios
2 parents e6c52f8 + 56600da commit c9d8d3e

16 files changed

Lines changed: 558 additions & 35 deletions

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ test-e2e-oidc: GO_TEST_FLAGS += -count 1
8686
test-e2e-oidc: test-unit
8787
.PHONY: test-e2e-oidc
8888

89+
# KMS encryption tests
90+
test-e2e-encryption-kms: GO_TEST_PACKAGES :=./test/e2e-encryption-kms/...
91+
test-e2e-encryption-kms: GO_TEST_FLAGS += -v
92+
test-e2e-encryption-kms: GO_TEST_FLAGS += -timeout 4h
93+
test-e2e-encryption-kms: GO_TEST_FLAGS += -p 1
94+
test-e2e-encryption-kms: test-unit
95+
.PHONY: test-e2e-encryption-kms
96+
8997
# Configure the 'telepresence' target
9098
# See vendor/github.com/openshift/build-machinery-go/scripts/run-telepresence.sh for usage and configuration details
9199
export TP_DEPLOYMENT_YAML ?=./manifests/07_deployment.yaml

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require (
77
github.com/ghodss/yaml v1.0.0
88
github.com/golang-jwt/jwt/v5 v5.2.2
99
github.com/google/go-cmp v0.7.0
10-
github.com/openshift/api v0.0.0-20251106190826-ebe535b08719
10+
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7
1111
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
1212
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
13-
github.com/openshift/library-go v0.0.0-20251107090138-0de9712313a5
13+
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6
1414
github.com/openshift/multi-operator-manager v0.0.0-20241205181422-20aa3906b99d
1515
github.com/spf13/cobra v1.9.1
1616
github.com/spf13/pflag v1.0.6

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM
147147
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
148148
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
149149
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
150-
github.com/openshift/api v0.0.0-20251106190826-ebe535b08719 h1:KEwYyKaJniwhoyLB75tAMmJn9pMlk0PUlRfrsXYOhwM=
151-
github.com/openshift/api v0.0.0-20251106190826-ebe535b08719/go.mod h1:d5uzF0YN2nQQFA0jIEWzzOZ+edmo6wzlGLvx5Fhz4uY=
150+
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7 h1:fdvcDJySvjVJctbPbdLPoMiMk+bls34+eq6tWOqdFZg=
151+
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7/go.mod h1:d5uzF0YN2nQQFA0jIEWzzOZ+edmo6wzlGLvx5Fhz4uY=
152152
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee h1:+Sp5GGnjHDhT/a/nQ1xdp43UscBMr7G5wxsYotyhzJ4=
153153
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
154154
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 h1:9JBeIXmnHlpXTQPi7LPmu1jdxznBhAE7bb1K+3D8gxY=
155155
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235/go.mod h1:L49W6pfrZkfOE5iC1PqEkuLkXG4W0BX4w8b+L2Bv7fM=
156-
github.com/openshift/library-go v0.0.0-20251107090138-0de9712313a5 h1:Gq8jCFgSrilZ2ZHjQleFZWlblikc1aaRZ0hqs+yvrP4=
157-
github.com/openshift/library-go v0.0.0-20251107090138-0de9712313a5/go.mod h1:OlFFws1AO51uzfc48MsStGE4SFMWlMZD0+f5a/zCtKI=
156+
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6 h1:9PoupWybtdTNB7bVBKac/tR5X+3IYydcTIrSyO5QR7E=
157+
github.com/openshift/library-go v0.0.0-20260303081410-9c30edf843c6/go.mod h1:ErDfiIrPHH+menTP/B4LKd0nxFDdvCbTamAc6SWMIh8=
158158
github.com/openshift/multi-operator-manager v0.0.0-20241205181422-20aa3906b99d h1:Rzx23P63JFNNz5D23ubhC0FCN5rK8CeJhKcq5QKcdyU=
159159
github.com/openshift/multi-operator-manager v0.0.0-20241205181422-20aa3906b99d/go.mod h1:iVi9Bopa5cLhjG5ie9DoZVVqkH8BGb1FQVTtecOLn4I=
160160
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package e2e_encryption_kms
2+
3+
import (
4+
"context"
5+
"math/rand/v2"
6+
"testing"
7+
8+
"k8s.io/apimachinery/pkg/runtime"
9+
10+
configv1 "github.com/openshift/api/config/v1"
11+
operatorencryption "github.com/openshift/cluster-authentication-operator/test/library/encryption"
12+
library "github.com/openshift/library-go/test/library/encryption"
13+
librarykms "github.com/openshift/library-go/test/library/encryption/kms"
14+
)
15+
16+
// TestKMSEncryptionOnOff tests KMS encryption on/off cycle.
17+
// This test:
18+
// 1. Creates a test OAuth access token (TokenOfLife)
19+
// 2. Enables KMS encryption
20+
// 3. Verifies token is encrypted
21+
// 4. Disables encryption (Identity)
22+
// 5. Verifies token is NOT encrypted
23+
// 6. Re-enables KMS encryption
24+
// 7. Verifies token is encrypted again
25+
// 8. Disables encryption (Identity) again
26+
// 9. Verifies token is NOT encrypted again
27+
func TestKMSEncryptionOnOff(t *testing.T) {
28+
// Deploy the mock KMS plugin for testing.
29+
// NOTE: This manual deployment is only required for KMS v1. In the future,
30+
// the platform will manage the KMS plugins, and this code will no longer be needed.
31+
librarykms.DeployUpstreamMockKMSPlugin(context.Background(), t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage)
32+
library.TestEncryptionTurnOnAndOff(t, library.OnOffScenario{
33+
BasicScenario: library.BasicScenario{
34+
Namespace: "openshift-config-managed",
35+
LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + "openshift-oauth-apiserver",
36+
EncryptionConfigSecretName: "encryption-config-openshift-oauth-apiserver",
37+
EncryptionConfigSecretNamespace: "openshift-config-managed",
38+
OperatorNamespace: "openshift-authentication-operator",
39+
TargetGRs: operatorencryption.DefaultTargetGRs,
40+
AssertFunc: operatorencryption.AssertTokens,
41+
},
42+
CreateResourceFunc: func(t testing.TB, _ library.ClientSet, namespace string) runtime.Object {
43+
return operatorencryption.CreateAndStoreTokenOfLife(context.TODO(), t, operatorencryption.GetClients(t))
44+
},
45+
AssertResourceEncryptedFunc: operatorencryption.AssertTokenOfLifeEncrypted,
46+
AssertResourceNotEncryptedFunc: operatorencryption.AssertTokenOfLifeNotEncrypted,
47+
ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.TokenOfLife(t) },
48+
ResourceName: "TokenOfLife",
49+
EncryptionProvider: configv1.EncryptionTypeKMS,
50+
})
51+
}
52+
53+
// TestKMSEncryptionProvidersMigration tests migration between KMS and AES encryption providers.
54+
// This test:
55+
// 1. Deploys the mock KMS plugin
56+
// 2. Creates a test OAuth access token (TokenOfLife)
57+
// 3. Randomly picks one AES encryption provider (AESGCM or AESCBC)
58+
// 4. Shuffles the selected AES provider with KMS to create a randomized migration order
59+
// 5. Migrates between the providers in the shuffled order
60+
// 6. Verifies token is correctly encrypted after each migration
61+
func TestKMSEncryptionProvidersMigration(t *testing.T) {
62+
librarykms.DeployUpstreamMockKMSPlugin(context.Background(), t, library.GetClients(t).Kube, librarykms.WellKnownUpstreamMockKMSPluginNamespace, librarykms.WellKnownUpstreamMockKMSPluginImage)
63+
library.TestEncryptionProvidersMigration(t, library.ProvidersMigrationScenario{
64+
BasicScenario: library.BasicScenario{
65+
Namespace: "openshift-config-managed",
66+
LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + "openshift-oauth-apiserver",
67+
EncryptionConfigSecretName: "encryption-config-openshift-oauth-apiserver",
68+
EncryptionConfigSecretNamespace: "openshift-config-managed",
69+
OperatorNamespace: "openshift-authentication-operator",
70+
TargetGRs: operatorencryption.DefaultTargetGRs,
71+
AssertFunc: operatorencryption.AssertTokens,
72+
},
73+
CreateResourceFunc: func(t testing.TB, _ library.ClientSet, namespace string) runtime.Object {
74+
return operatorencryption.CreateAndStoreTokenOfLife(context.TODO(), t, operatorencryption.GetClients(t))
75+
},
76+
AssertResourceEncryptedFunc: operatorencryption.AssertTokenOfLifeEncrypted,
77+
AssertResourceNotEncryptedFunc: operatorencryption.AssertTokenOfLifeNotEncrypted,
78+
ResourceFunc: func(t testing.TB, _ string) runtime.Object { return operatorencryption.TokenOfLife(t) },
79+
ResourceName: "TokenOfLife",
80+
EncryptionProviders: library.ShuffleEncryptionProviders([]configv1.EncryptionType{configv1.EncryptionTypeKMS, library.SupportedStaticEncryptionProviders[rand.IntN(len(library.SupportedStaticEncryptionProviders))]}),
81+
})
82+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package e2e_encryption_kms
2+
3+
import (
4+
"math/rand"
5+
"os"
6+
"reflect"
7+
"testing"
8+
"time"
9+
"unsafe"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
randomizeTestOrder(m)
14+
os.Exit(m.Run())
15+
}
16+
17+
func randomizeTestOrder(m *testing.M) {
18+
pointerVal := reflect.ValueOf(m)
19+
val := reflect.Indirect(pointerVal)
20+
21+
testsMember := val.FieldByName("tests")
22+
ptrToTests := unsafe.Pointer(testsMember.UnsafeAddr())
23+
realPtrToTests := (*[]testing.InternalTest)(ptrToTests)
24+
25+
tests := *realPtrToTests
26+
27+
rand.Seed(time.Now().UnixNano())
28+
rand.Shuffle(len(tests), func(i, j int) { tests[i], tests[j] = tests[j], tests[i] })
29+
30+
*realPtrToTests = tests
31+
}

vendor/github.com/openshift/library-go/pkg/crypto/crypto.go

Lines changed: 28 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/library-go/pkg/operator/certrotation/signer.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/library-go/test/library/encryption/helpers.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/library-go/test/library/encryption/kms/assets/k8s_mock_kms_plugin_configmap.yaml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/library-go/test/library/encryption/kms/assets/k8s_mock_kms_plugin_daemonset.yaml

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)