@@ -224,13 +224,26 @@ func TestNodeAuthorizer(t *testing.T) {
224
224
225
225
createNode2MirrorPod := func (client clientset.Interface ) func () error {
226
226
return func () error {
227
- _ , err := client .CoreV1 ().Pods ("ns" ).Create (context .TODO (), & corev1.Pod {
227
+ const nodeName = "node2"
228
+ node , err := client .CoreV1 ().Nodes ().Get (context .TODO (), nodeName , metav1.GetOptions {})
229
+ if err != nil {
230
+ return err
231
+ }
232
+ controller := true
233
+ _ , err = client .CoreV1 ().Pods ("ns" ).Create (context .TODO (), & corev1.Pod {
228
234
ObjectMeta : metav1.ObjectMeta {
229
235
Name : "node2mirrorpod" ,
230
236
Annotations : map [string ]string {corev1 .MirrorPodAnnotationKey : "true" },
237
+ OwnerReferences : []metav1.OwnerReference {{
238
+ APIVersion : corev1 .SchemeGroupVersion .String (),
239
+ Kind : "Node" ,
240
+ Name : nodeName ,
241
+ UID : node .UID ,
242
+ Controller : & controller ,
243
+ }},
231
244
},
232
245
Spec : corev1.PodSpec {
233
- NodeName : "node2" ,
246
+ NodeName : nodeName ,
234
247
Containers : []corev1.Container {{Name : "image" , Image : "busybox" }},
235
248
},
236
249
}, metav1.CreateOptions {})
@@ -462,9 +475,7 @@ func TestNodeAuthorizer(t *testing.T) {
462
475
expectForbidden (t , getPVC (nodeanonClient ))
463
476
expectForbidden (t , getPV (nodeanonClient ))
464
477
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
465
- expectForbidden (t , createNode2MirrorPod (nodeanonClient ))
466
478
expectForbidden (t , deleteNode2NormalPod (nodeanonClient ))
467
- expectForbidden (t , deleteNode2MirrorPod (nodeanonClient ))
468
479
expectForbidden (t , createNode2MirrorPodEviction (nodeanonClient ))
469
480
expectForbidden (t , createNode2 (nodeanonClient ))
470
481
expectForbidden (t , updateNode2Status (nodeanonClient ))
@@ -476,8 +487,6 @@ func TestNodeAuthorizer(t *testing.T) {
476
487
expectForbidden (t , getPVC (node1Client ))
477
488
expectForbidden (t , getPV (node1Client ))
478
489
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
479
- expectForbidden (t , createNode2MirrorPod (node1Client ))
480
- expectNotFound (t , deleteNode2MirrorPod (node1Client ))
481
490
expectNotFound (t , createNode2MirrorPodEviction (node1Client ))
482
491
expectForbidden (t , createNode2 (node1Client ))
483
492
expectNotFound (t , updateNode2Status (node1Client ))
@@ -492,21 +501,23 @@ func TestNodeAuthorizer(t *testing.T) {
492
501
493
502
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
494
503
// mirror pod and self node lifecycle is allowed
504
+ expectAllowed (t , createNode2 (node2Client ))
505
+ expectAllowed (t , updateNode2Status (node2Client ))
506
+ expectForbidden (t , createNode2MirrorPod (nodeanonClient ))
507
+ expectForbidden (t , deleteNode2MirrorPod (nodeanonClient ))
508
+ expectForbidden (t , createNode2MirrorPod (node1Client ))
509
+ expectNotFound (t , deleteNode2MirrorPod (node1Client ))
510
+ // create a pod as an admin to add object references
511
+ expectAllowed (t , createNode2NormalPod (superuserClient ))
512
+
495
513
expectAllowed (t , createNode2MirrorPod (node2Client ))
496
514
expectAllowed (t , deleteNode2MirrorPod (node2Client ))
497
515
expectAllowed (t , createNode2MirrorPod (node2Client ))
498
516
expectAllowed (t , createNode2MirrorPodEviction (node2Client ))
499
- expectAllowed (t , createNode2 (node2Client ))
500
- expectAllowed (t , updateNode2Status (node2Client ))
501
517
// self deletion is not allowed
502
518
expectForbidden (t , deleteNode2 (node2Client ))
503
519
// modification of another node's status is not allowed
504
520
expectForbidden (t , updateNode2Status (node1Client ))
505
- // clean up node2
506
- expectAllowed (t , deleteNode2 (superuserClient ))
507
-
508
- // create a pod as an admin to add object references
509
- expectAllowed (t , createNode2NormalPod (superuserClient ))
510
521
511
522
// unidentifiable node and node1 are still forbidden
512
523
expectForbidden (t , getSecret (nodeanonClient ))
@@ -553,6 +564,8 @@ func TestNodeAuthorizer(t *testing.T) {
553
564
expectAllowed (t , createNode2MirrorPod (superuserClient ))
554
565
expectAllowed (t , createNode2NormalPodEviction (node2Client ))
555
566
expectAllowed (t , createNode2MirrorPodEviction (node2Client ))
567
+ // clean up node2
568
+ expectAllowed (t , deleteNode2 (superuserClient ))
556
569
557
570
// re-create a pod as an admin to add object references
558
571
expectAllowed (t , createNode2NormalPod (superuserClient ))
0 commit comments