@@ -107,24 +107,35 @@ const (
107
107
108
108
var codecs serializer.CodecFactory
109
109
110
- // this atomic bool allows us to swap enablement of the KMSv2KDF feature in tests
110
+ // this map allows us to swap enablement of the KMSv2KDF feature in tests
111
111
// as the feature gate is now locked to true starting with v1.29
112
112
// Note: it cannot be set by an end user
113
- var kdfDisabled atomic.Bool
113
+ // KDF enablement is tracked per KMS provider to allow tests to run in parallel.
114
+ var kdfEnabledPerKMS sync.Map // map[string]bool, KMS name -> KDF enabled
114
115
115
116
// this function should only be called in tests to swap enablement of the KMSv2KDF feature
116
- func SetKDFForTests ( b bool ) func () {
117
- kdfDisabled . Store ( ! b )
118
- return func () {
119
- kdfDisabled . Store ( false )
117
+ // Caller must guarantee that all KMS providers have distinct names across all tests.
118
+ func SetKDFForTests ( kmsName string , b bool ) func () {
119
+ if len ( kmsName ) == 0 { // guarantee that GetKDF("") returns the default value
120
+ panic ( "empty KMS name used in test" )
120
121
}
122
+ if _ , loaded := kdfEnabledPerKMS .LoadOrStore (kmsName , b ); loaded {
123
+ panic ("duplicate KMS name used in test" )
124
+ }
125
+ return func () { kdfEnabledPerKMS .Delete (kmsName ) }
121
126
}
122
127
123
128
// this function should be used to determine enablement of the KMSv2KDF feature
124
129
// instead of getting it from DefaultFeatureGate as the feature gate is now locked
125
130
// to true starting with v1.29
126
- func GetKDF () bool {
127
- return ! kdfDisabled .Load ()
131
+ // to allow integration tests to run in parallel, this "feature flag" can be set
132
+ // per KMS provider as long as all providers use distinct names.
133
+ func GetKDF (kmsName string ) bool {
134
+ kdfEnabled , ok := kdfEnabledPerKMS .Load (kmsName )
135
+ if ! ok {
136
+ return true // explicit config is missing, but KDF is enabled by default
137
+ }
138
+ return kdfEnabled .(bool ) // this will panic if a non-bool ever gets stored, which should never happen
128
139
}
129
140
130
141
func init () {
@@ -390,7 +401,7 @@ func (h *kmsv2PluginProbe) rotateDEKOnKeyIDChange(ctx context.Context, statusKey
390
401
// this gate can only change during tests, but the check is cheap enough to always make
391
402
// this allows us to easily exercise both modes without restarting the API server
392
403
// TODO integration test that this dynamically takes effect
393
- useSeed := GetKDF ()
404
+ useSeed := GetKDF (h . name )
394
405
stateUseSeed := state .EncryptedObject .EncryptedDEKSourceType == kmstypes .EncryptedDEKSourceType_HKDF_SHA256_XNONCE_AES_GCM_SEED
395
406
396
407
// state is valid and status keyID is unchanged from when we generated this DEK/seed so there is no need to rotate it
0 commit comments