@@ -596,34 +596,41 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
596
596
)
597
597
598
598
g .BeforeEach (func () {
599
- systemResource = examplePod ("kube-system" , nil )
600
- collaboratorResource = examplePod ("visibility" , nil )
601
- nonSystemResource = examplePod (f .Namespace .Name , nil )
599
+ var err error
600
+
601
+ nonSystemResource , err = createPod (context .Background (), f .ClientSet , f .Namespace .Name , nil )
602
+ framework .ExpectNoError (err )
603
+
604
+ collaboratorResource , err = createPod (context .Background (), f .ClientSet , "visibility" , nil )
605
+ framework .ExpectNoError (err )
606
+
607
+ systemResource , err = createPod (context .Background (), f .ClientSet , "kube-system" , map [string ]string {"admission.zalando.org/infrastructure-component" : "true" })
608
+ framework .ExpectNoError (err )
602
609
})
603
610
604
- g .Context ("as privileged user" , func () {
611
+ g .Context ("as admin user" , func () {
605
612
var client * kubernetes.Clientset
606
613
607
614
g .BeforeEach (func () {
608
615
var err error
609
616
610
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
617
+ client , err = getAdminClient (eksCluster , awsAccountID )
611
618
framework .ExpectNoError (err )
612
619
})
613
620
614
621
g .It ("should allow write access in user namespace" , func () {
615
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
616
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
622
+ err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Delete (context .Background (), nonSystemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
623
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
617
624
})
618
625
619
626
g .It ("should allow write access in collaborator namespace" , func () {
620
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
621
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , collaboratorResource .Name , collaboratorResource .Namespace )
627
+ err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Delete (context .Background (), collaboratorResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
628
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , collaboratorResource .Name , collaboratorResource .Namespace )
622
629
})
623
630
624
631
g .It ("should allow write access in system namespace" , func () {
625
- _ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
626
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , systemResource .Name , systemResource .Namespace )
632
+ err := client .CoreV1 ().Pods (systemResource .Namespace ).Delete (context .Background (), systemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
633
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , systemResource .Name , systemResource .Namespace )
627
634
})
628
635
})
629
636
@@ -638,43 +645,43 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
638
645
})
639
646
640
647
g .It ("should allow write access in user namespace" , func () {
641
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
642
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
648
+ err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Delete (context .Background (), nonSystemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
649
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
643
650
})
644
651
645
652
g .It ("should allow write access in collaborator namespace" , func () {
646
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
647
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , collaboratorResource .Name , collaboratorResource .Namespace )
653
+ err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Delete (context .Background (), collaboratorResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
654
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , collaboratorResource .Name , collaboratorResource .Namespace )
648
655
})
649
656
650
657
g .It ("should deny write access in system namespace" , func () {
651
- _ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
658
+ err := client .CoreV1 ().Pods (systemResource .Namespace ).Delete (context .Background (), systemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
652
659
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
653
660
})
654
661
})
655
662
656
- g .Context ("as unprivileged user" , func () {
663
+ g .Context ("as engineer user" , func () {
657
664
var client * kubernetes.Clientset
658
665
659
666
g .BeforeEach (func () {
660
667
var err error
661
668
662
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
669
+ client , err = getEngineerClient (eksCluster , awsAccountID )
663
670
framework .ExpectNoError (err )
664
671
})
665
672
666
673
g .It ("should allow write access in user namespace" , func () {
667
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
668
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
674
+ err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Delete (context .Background (), nonSystemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
675
+ framework .ExpectNoError (err , "failed to delete pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
669
676
})
670
677
671
678
g .It ("should deny write access in collaborator namespace" , func () {
672
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
679
+ err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Delete (context .Background (), collaboratorResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
673
680
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
674
681
})
675
682
676
683
g .It ("should deny write access in system namespace" , func () {
677
- _ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
684
+ err := client .CoreV1 ().Pods (systemResource .Namespace ).Delete (context .Background (), systemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
678
685
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
679
686
})
680
687
})
@@ -696,13 +703,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
696
703
framework .ExpectNoError (err )
697
704
})
698
705
699
- g .Context ("as privileged user" , func () {
706
+ g .Context ("as admin user" , func () {
700
707
var client * kubernetes.Clientset
701
708
702
709
g .BeforeEach (func () {
703
710
var err error
704
711
705
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
712
+ client , err = getAdminClient (eksCluster , awsAccountID )
706
713
framework .ExpectNoError (err )
707
714
})
708
715
@@ -717,13 +724,45 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
717
724
})
718
725
})
719
726
720
- g .Context ("as unprivileged user" , func () {
727
+ g .Context ("as collaborator user" , func () {
728
+ var client * kubernetes.Clientset
729
+
730
+ g .BeforeEach (func () {
731
+ var err error
732
+
733
+ client , err = getCollaboratorClient (eksCluster , awsAccountID )
734
+ framework .ExpectNoError (err )
735
+ })
736
+
737
+ g .It ("should allow write access for non-system resources" , func () {
738
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), nonSystemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
739
+ framework .ExpectNoError (err , "failed to delete cluster role: %s" , nonSystemResource .Name )
740
+ })
741
+
742
+ g .It ("should deny write access for system resources" , func () {
743
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
744
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
745
+ })
746
+
747
+ // test specific namespaces
748
+ g .It ("should deny deletion of visibility namespace" , func () {
749
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
750
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
751
+ })
752
+
753
+ g .It ("should deny deletion of kube-system namespace" , func () {
754
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "kube-system" , metav1.DeleteOptions {DryRun : []string {"All" }})
755
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
756
+ })
757
+ })
758
+
759
+ g .Context ("as engineer user" , func () {
721
760
var client * kubernetes.Clientset
722
761
723
762
g .BeforeEach (func () {
724
763
var err error
725
764
726
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
765
+ client , err = getEngineerClient (eksCluster , awsAccountID )
727
766
framework .ExpectNoError (err )
728
767
})
729
768
@@ -736,6 +775,17 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
736
775
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
737
776
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
738
777
})
778
+
779
+ // test specific namespaces
780
+ g .It ("should deny deletion of visibility namespace" , func () {
781
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
782
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
783
+ })
784
+
785
+ g .It ("should deny deletion of kube-system namespace" , func () {
786
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "kube-system" , metav1.DeleteOptions {DryRun : []string {"All" }})
787
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
788
+ })
739
789
})
740
790
})
741
791
@@ -785,13 +835,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
785
835
})
786
836
})
787
837
788
- g .Context ("as privileged user" , func () {
838
+ g .Context ("as admin user" , func () {
789
839
var client * kubernetes.Clientset
790
840
791
841
g .BeforeEach (func () {
792
842
var err error
793
843
794
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
844
+ client , err = getAdminClient (eksCluster , awsAccountID )
795
845
framework .ExpectNoError (err )
796
846
})
797
847
@@ -811,13 +861,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
811
861
})
812
862
})
813
863
814
- g .Context ("as unprivileged user" , func () {
864
+ g .Context ("as read-only user" , func () {
815
865
var client * kubernetes.Clientset
816
866
817
867
g .BeforeEach (func () {
818
868
var err error
819
869
820
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
870
+ client , err = getReadOnlyClient (eksCluster , awsAccountID )
821
871
framework .ExpectNoError (err )
822
872
})
823
873
@@ -839,19 +889,24 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
839
889
})
840
890
})
841
891
842
- // getPrivilegedClient returns a client with the `zalando:administrator` group.
843
- func getPrivilegedClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
844
- return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-privileged -role" , awsAccountID , aws .ToString (cluster .Name )))
892
+ // getAdminClient returns a client with the `zalando:administrator` group.
893
+ func getAdminClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
894
+ return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-administrator -role" , awsAccountID , aws .ToString (cluster .Name )))
845
895
}
846
896
847
897
// getCollaboratorClient returns a client with the `zalando:collaborator` group.
848
898
func getCollaboratorClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
849
899
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-collaborator-role" , awsAccountID , aws .ToString (cluster .Name )))
850
900
}
851
901
852
- // getUnprivilegedClient returns a client with the `zalando:readonly` group.
853
- func getUnprivilegedClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
854
- return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-unprivileged-role" , awsAccountID , aws .ToString (cluster .Name )))
902
+ // getEngineerClient returns a client with the `zalando:engineer` group.
903
+ func getEngineerClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
904
+ return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-engineer-role" , awsAccountID , aws .ToString (cluster .Name )))
905
+ }
906
+
907
+ // getReadOnlyClient returns a client with the `zalando:readonly` group.
908
+ func getReadOnlyClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
909
+ return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-read-only-role" , awsAccountID , aws .ToString (cluster .Name )))
855
910
}
856
911
857
912
// getPostgresAdministratorClient returns a client with the `zalando:postgres-admin` group.
0 commit comments