@@ -411,6 +411,118 @@ func TestMixedResourceNonResourceUncovered(t *testing.T) {
411
411
}.test (t )
412
412
}
413
413
414
+ func TestAttributeRestrictionsCovering (t * testing.T ) {
415
+ escalationTest {
416
+ ownerRules : []authorizationapi.PolicyRule {
417
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
418
+ },
419
+ servantRules : []authorizationapi.PolicyRule {
420
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
421
+ },
422
+
423
+ expectedCovered : true ,
424
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
425
+ }.test (t )
426
+ escalationTest {
427
+ ownerRules : []authorizationapi.PolicyRule {
428
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" )},
429
+ },
430
+ servantRules : []authorizationapi.PolicyRule {
431
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
432
+ },
433
+
434
+ expectedCovered : true ,
435
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
436
+ }.test (t )
437
+ escalationTest {
438
+ ownerRules : []authorizationapi.PolicyRule {
439
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
440
+ {Verbs : sets .NewString ("update" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
441
+ },
442
+ servantRules : []authorizationapi.PolicyRule {},
443
+
444
+ expectedCovered : true ,
445
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
446
+ }.test (t )
447
+ escalationTest {
448
+ ownerRules : []authorizationapi.PolicyRule {},
449
+ servantRules : []authorizationapi.PolicyRule {
450
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
451
+ {Verbs : sets .NewString ("update" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
452
+ },
453
+
454
+ expectedCovered : true ,
455
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
456
+ }.test (t )
457
+ escalationTest {
458
+ ownerRules : []authorizationapi.PolicyRule {
459
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("pods" )},
460
+ },
461
+ servantRules : []authorizationapi.PolicyRule {
462
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
463
+ {Verbs : sets .NewString ("update" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
464
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.ClusterRole {}},
465
+ {Verbs : sets .NewString ("impersonate" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.ClusterPolicyBinding {}},
466
+ },
467
+
468
+ expectedCovered : true ,
469
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
470
+ }.test (t )
471
+ escalationTest {
472
+ ownerRules : []authorizationapi.PolicyRule {
473
+ {Verbs : sets .NewString (authorizationapi .VerbAll ), Resources : sets .NewString (authorizationapi .ResourceAll ), AttributeRestrictions : & authorizationapi.Role {}},
474
+ },
475
+ servantRules : []authorizationapi.PolicyRule {
476
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
477
+ {Verbs : sets .NewString ("update" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
478
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.ClusterRole {}},
479
+ {Verbs : sets .NewString ("impersonate" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.ClusterPolicyBinding {}},
480
+ },
481
+
482
+ expectedCovered : true ,
483
+ expectedUncoveredRules : []authorizationapi.PolicyRule {},
484
+ }.test (t )
485
+ escalationTest {
486
+ ownerRules : []authorizationapi.PolicyRule {
487
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
488
+ },
489
+ servantRules : []authorizationapi.PolicyRule {
490
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" )},
491
+ },
492
+
493
+ expectedCovered : false ,
494
+ expectedUncoveredRules : []authorizationapi.PolicyRule {
495
+ {Verbs : sets .NewString ("create" ), Resources : sets .NewString ("builds" )},
496
+ },
497
+ }.test (t )
498
+ escalationTest {
499
+ ownerRules : []authorizationapi.PolicyRule {
500
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" ), AttributeRestrictions : & authorizationapi.Role {}},
501
+ },
502
+ servantRules : []authorizationapi.PolicyRule {
503
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" )},
504
+ },
505
+
506
+ expectedCovered : false ,
507
+ expectedUncoveredRules : []authorizationapi.PolicyRule {
508
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" )},
509
+ },
510
+ }.test (t )
511
+ escalationTest {
512
+ ownerRules : []authorizationapi.PolicyRule {
513
+ {Verbs : sets .NewString (authorizationapi .VerbAll ), Resources : sets .NewString (authorizationapi .ResourceAll ), AttributeRestrictions : & authorizationapi.IsPersonalSubjectAccessReview {}},
514
+ },
515
+ servantRules : []authorizationapi.PolicyRule {
516
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" )},
517
+ },
518
+
519
+ expectedCovered : false ,
520
+ expectedUncoveredRules : []authorizationapi.PolicyRule {
521
+ {Verbs : sets .NewString ("delete" ), Resources : sets .NewString ("builds" )},
522
+ },
523
+ }.test (t )
524
+ }
525
+
414
526
func (test escalationTest ) test (t * testing.T ) {
415
527
actualCovered , actualUncoveredRules := Covers (test .ownerRules , test .servantRules )
416
528
0 commit comments