@@ -30,11 +30,14 @@ import (
30
30
"k8s.io/apimachinery/pkg/util/dump"
31
31
"k8s.io/apimachinery/pkg/util/validation/field"
32
32
"k8s.io/apiserver/pkg/authentication/request/headerrequest"
33
+ "k8s.io/apiserver/pkg/features"
33
34
"k8s.io/apiserver/pkg/server/dynamiccertificates"
35
+ utilfeature "k8s.io/apiserver/pkg/util/feature"
34
36
"k8s.io/client-go/kubernetes/fake"
35
37
corev1listers "k8s.io/client-go/listers/core/v1"
36
38
clienttesting "k8s.io/client-go/testing"
37
39
"k8s.io/client-go/tools/cache"
40
+ featuregatetesting "k8s.io/component-base/featuregate/testing"
38
41
)
39
42
40
43
var (
@@ -95,6 +98,7 @@ func TestWriteClientCAs(t *testing.T) {
95
98
preexistingObjs []runtime.Object
96
99
expectedConfigMaps map [string ]* corev1.ConfigMap
97
100
expectCreate bool
101
+ uidGate bool
98
102
}{
99
103
{
100
104
name : "basic" ,
@@ -107,6 +111,32 @@ func TestWriteClientCAs(t *testing.T) {
107
111
RequestHeaderCA : anotherRandomCAProvider ,
108
112
RequestHeaderAllowedNames : headerrequest.StaticStringSlice {"first" , "second" },
109
113
},
114
+ expectedConfigMaps : map [string ]* corev1.ConfigMap {
115
+ "extension-apiserver-authentication" : {
116
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
117
+ Data : map [string ]string {
118
+ "client-ca-file" : string (someRandomCA ),
119
+ "requestheader-username-headers" : `["alfa","bravo","charlie"]` ,
120
+ "requestheader-group-headers" : `["delta"]` ,
121
+ "requestheader-extra-headers-prefix" : `["echo","foxtrot"]` ,
122
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
123
+ "requestheader-allowed-names" : `["first","second"]` ,
124
+ },
125
+ },
126
+ },
127
+ expectCreate : true ,
128
+ },
129
+ {
130
+ name : "basic with feature gate" ,
131
+ clusterAuthInfo : ClusterAuthenticationInfo {
132
+ ClientCA : someRandomCAProvider ,
133
+ RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {"alfa" , "bravo" , "charlie" },
134
+ RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {"golf" , "hotel" , "india" },
135
+ RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {"delta" },
136
+ RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {"echo" , "foxtrot" },
137
+ RequestHeaderCA : anotherRandomCAProvider ,
138
+ RequestHeaderAllowedNames : headerrequest.StaticStringSlice {"first" , "second" },
139
+ },
110
140
expectedConfigMaps : map [string ]* corev1.ConfigMap {
111
141
"extension-apiserver-authentication" : {
112
142
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
@@ -122,6 +152,7 @@ func TestWriteClientCAs(t *testing.T) {
122
152
},
123
153
},
124
154
expectCreate : true ,
155
+ uidGate : true ,
125
156
},
126
157
{
127
158
name : "skip extension-apiserver-authentication" ,
@@ -134,7 +165,6 @@ func TestWriteClientCAs(t *testing.T) {
134
165
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
135
166
Data : map [string ]string {
136
167
"requestheader-username-headers" : `[]` ,
137
- "requestheader-uid-headers" : `[]` ,
138
168
"requestheader-group-headers" : `[]` ,
139
169
"requestheader-extra-headers-prefix" : `[]` ,
140
170
"requestheader-client-ca-file" : string (anotherRandomCA ),
@@ -169,7 +199,6 @@ func TestWriteClientCAs(t *testing.T) {
169
199
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
170
200
Data : map [string ]string {
171
201
"requestheader-username-headers" : `[]` ,
172
- "requestheader-uid-headers" : `[]` ,
173
202
"requestheader-group-headers" : `[]` ,
174
203
"requestheader-extra-headers-prefix" : `[]` ,
175
204
"requestheader-client-ca-file" : string (anotherRandomCA ),
@@ -205,7 +234,6 @@ func TestWriteClientCAs(t *testing.T) {
205
234
name : "overwrite extension-apiserver-authentication requestheader" ,
206
235
clusterAuthInfo : ClusterAuthenticationInfo {
207
236
RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {},
208
- RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {},
209
237
RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {},
210
238
RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {},
211
239
RequestHeaderCA : anotherRandomCAProvider ,
@@ -216,7 +244,6 @@ func TestWriteClientCAs(t *testing.T) {
216
244
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
217
245
Data : map [string ]string {
218
246
"requestheader-username-headers" : `[]` ,
219
- "requestheader-uid-headers" : `[]` ,
220
247
"requestheader-group-headers" : `[]` ,
221
248
"requestheader-extra-headers-prefix" : `[]` ,
222
249
"requestheader-client-ca-file" : string (someRandomCA ),
@@ -229,7 +256,6 @@ func TestWriteClientCAs(t *testing.T) {
229
256
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
230
257
Data : map [string ]string {
231
258
"requestheader-username-headers" : `[]` ,
232
- "requestheader-uid-headers" : `[]` ,
233
259
"requestheader-group-headers" : `[]` ,
234
260
"requestheader-extra-headers-prefix" : `[]` ,
235
261
"requestheader-client-ca-file" : string (someRandomCA ) + string (anotherRandomCA ),
@@ -260,7 +286,6 @@ func TestWriteClientCAs(t *testing.T) {
260
286
name : "skip on no change" ,
261
287
clusterAuthInfo : ClusterAuthenticationInfo {
262
288
RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {},
263
- RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {},
264
289
RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {},
265
290
RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {},
266
291
RequestHeaderCA : anotherRandomCAProvider ,
@@ -271,7 +296,6 @@ func TestWriteClientCAs(t *testing.T) {
271
296
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
272
297
Data : map [string ]string {
273
298
"requestheader-username-headers" : `[]` ,
274
- "requestheader-uid-headers" : `[]` ,
275
299
"requestheader-group-headers" : `[]` ,
276
300
"requestheader-extra-headers-prefix" : `[]` ,
277
301
"requestheader-client-ca-file" : string (anotherRandomCA ),
@@ -282,10 +306,126 @@ func TestWriteClientCAs(t *testing.T) {
282
306
expectedConfigMaps : map [string ]* corev1.ConfigMap {},
283
307
expectCreate : false ,
284
308
},
309
+ {
310
+ name : "drop uid without feature gate" ,
311
+ clusterAuthInfo : ClusterAuthenticationInfo {
312
+ RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {},
313
+ RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {"panda" },
314
+ RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {},
315
+ RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {},
316
+ RequestHeaderCA : anotherRandomCAProvider ,
317
+ RequestHeaderAllowedNames : headerrequest.StaticStringSlice {},
318
+ },
319
+ preexistingObjs : []runtime.Object {
320
+ & corev1.ConfigMap {
321
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
322
+ Data : map [string ]string {
323
+ "requestheader-username-headers" : `[]` ,
324
+ "requestheader-uid-headers" : `["snorlax"]` ,
325
+ "requestheader-group-headers" : `[]` ,
326
+ "requestheader-extra-headers-prefix" : `[]` ,
327
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
328
+ "requestheader-allowed-names" : `[]` ,
329
+ },
330
+ },
331
+ },
332
+ expectedConfigMaps : map [string ]* corev1.ConfigMap {
333
+ "extension-apiserver-authentication" : {
334
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
335
+ Data : map [string ]string {
336
+ "requestheader-username-headers" : `[]` ,
337
+ "requestheader-group-headers" : `[]` ,
338
+ "requestheader-extra-headers-prefix" : `[]` ,
339
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
340
+ "requestheader-allowed-names" : `[]` ,
341
+ },
342
+ },
343
+ },
344
+ expectCreate : false ,
345
+ },
346
+ {
347
+ name : "add uid with feature gate" ,
348
+ clusterAuthInfo : ClusterAuthenticationInfo {
349
+ RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {},
350
+ RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {"panda" },
351
+ RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {},
352
+ RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {},
353
+ RequestHeaderCA : anotherRandomCAProvider ,
354
+ RequestHeaderAllowedNames : headerrequest.StaticStringSlice {},
355
+ },
356
+ preexistingObjs : []runtime.Object {
357
+ & corev1.ConfigMap {
358
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
359
+ Data : map [string ]string {
360
+ "requestheader-username-headers" : `[]` ,
361
+ "requestheader-group-headers" : `[]` ,
362
+ "requestheader-extra-headers-prefix" : `[]` ,
363
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
364
+ "requestheader-allowed-names" : `[]` ,
365
+ },
366
+ },
367
+ },
368
+ expectedConfigMaps : map [string ]* corev1.ConfigMap {
369
+ "extension-apiserver-authentication" : {
370
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
371
+ Data : map [string ]string {
372
+ "requestheader-username-headers" : `[]` ,
373
+ "requestheader-uid-headers" : `["panda"]` ,
374
+ "requestheader-group-headers" : `[]` ,
375
+ "requestheader-extra-headers-prefix" : `[]` ,
376
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
377
+ "requestheader-allowed-names" : `[]` ,
378
+ },
379
+ },
380
+ },
381
+ expectCreate : false ,
382
+ uidGate : true ,
383
+ },
384
+ {
385
+ name : "append uid with feature gate" ,
386
+ clusterAuthInfo : ClusterAuthenticationInfo {
387
+ RequestHeaderUsernameHeaders : headerrequest.StaticStringSlice {},
388
+ RequestHeaderUIDHeaders : headerrequest.StaticStringSlice {"panda" },
389
+ RequestHeaderGroupHeaders : headerrequest.StaticStringSlice {},
390
+ RequestHeaderExtraHeaderPrefixes : headerrequest.StaticStringSlice {},
391
+ RequestHeaderCA : anotherRandomCAProvider ,
392
+ RequestHeaderAllowedNames : headerrequest.StaticStringSlice {},
393
+ },
394
+ preexistingObjs : []runtime.Object {
395
+ & corev1.ConfigMap {
396
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
397
+ Data : map [string ]string {
398
+ "requestheader-username-headers" : `[]` ,
399
+ "requestheader-uid-headers" : `["snorlax"]` ,
400
+ "requestheader-group-headers" : `[]` ,
401
+ "requestheader-extra-headers-prefix" : `[]` ,
402
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
403
+ "requestheader-allowed-names" : `[]` ,
404
+ },
405
+ },
406
+ },
407
+ expectedConfigMaps : map [string ]* corev1.ConfigMap {
408
+ "extension-apiserver-authentication" : {
409
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
410
+ Data : map [string ]string {
411
+ "requestheader-username-headers" : `[]` ,
412
+ "requestheader-uid-headers" : `["snorlax","panda"]` ,
413
+ "requestheader-group-headers" : `[]` ,
414
+ "requestheader-extra-headers-prefix" : `[]` ,
415
+ "requestheader-client-ca-file" : string (anotherRandomCA ),
416
+ "requestheader-allowed-names" : `[]` ,
417
+ },
418
+ },
419
+ },
420
+ expectCreate : false ,
421
+ uidGate : true ,
422
+ },
285
423
}
286
424
287
425
for _ , test := range tests {
288
426
t .Run (test .name , func (t * testing.T ) {
427
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .RemoteRequestHeaderUID , test .uidGate )
428
+
289
429
client := fake .NewSimpleClientset (test .preexistingObjs ... )
290
430
configMapIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc })
291
431
for _ , obj := range test .preexistingObjs {
@@ -341,7 +481,6 @@ func TestWriteConfigMapDeleted(t *testing.T) {
341
481
ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceSystem , Name : "extension-apiserver-authentication" },
342
482
Data : map [string ]string {
343
483
"requestheader-username-headers" : `[]` ,
344
- "requestheader-uid-headers" : `[]` ,
345
484
"requestheader-group-headers" : `[]` ,
346
485
"requestheader-extra-headers-prefix" : `[]` ,
347
486
"requestheader-client-ca-file" : string (anotherRandomCA ),
0 commit comments