@@ -596,35 +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
- // TODO: see remarks below about privileged acceess / engineer role. Let's rename this to "admin" access to avoid any confusion.
605
- g .Context ("as privileged user" , func () {
611
+ g .Context ("as admin user" , func () {
606
612
var client * kubernetes.Clientset
607
613
608
614
g .BeforeEach (func () {
609
615
var err error
610
616
611
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
617
+ client , err = getAdminClient (eksCluster , awsAccountID )
612
618
framework .ExpectNoError (err )
613
619
})
614
620
615
621
g .It ("should allow write access in user namespace" , func () {
616
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
617
- 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 )
618
624
})
619
625
620
626
g .It ("should allow write access in collaborator namespace" , func () {
621
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
622
- 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 )
623
629
})
624
630
625
631
g .It ("should allow write access in system namespace" , func () {
626
- _ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
627
- 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 )
628
634
})
629
635
})
630
636
@@ -639,42 +645,21 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
639
645
})
640
646
641
647
g .It ("should allow write access in user namespace" , func () {
642
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
643
- 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 )
644
650
})
645
651
646
- // Not needed actually
647
- // // TODO: need to create resource before deleting it
648
- // g.It("should deny delete access in collaborator namespace", func() {
649
- // err := client.CoreV1().Pods(collaboratorResource.Namespace).Delete(context.Background(), collaboratorResource.Name, metav1.DeleteOptions{DryRun: []string{"All"}})
650
- // gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("delete operations are forbidden")))
651
- // })
652
-
653
- // Should allow visibility ns deletion?
654
- // g.It("should allow delete access in collaborator namespace", func() {
655
- // err := client.CoreV1().Pods(collaboratorResource.Namespace).Delete(context.Background(), collaboratorResource.Name, metav1.DeleteOptions{DryRun: []string{"All"}})
656
- // framework.ExpectNoError(err, "failed to delete pod: %s in namespace: %s", collaboratorResource.Name, collaboratorResource.Namespace)
657
- // })
658
-
659
652
g .It ("should allow write access in collaborator namespace" , func () {
660
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
661
- 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 )
662
655
})
663
656
664
657
g .It ("should deny write access in system namespace" , func () {
665
- _ , 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" }})
666
659
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
667
660
})
668
-
669
- // Not needed actually
670
- // // TODO: need to create resource before deleting it
671
- // g.It("should deny delete access in system namespace", func() {
672
- // err := client.CoreV1().Pods(systemResource.Namespace).Delete(context.Background(), systemResource.Name, metav1.DeleteOptions{DryRun: []string{"All"}})
673
- // gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("delete operations are forbidden")))
674
- // })
675
661
})
676
662
677
- // TODO: this is for manual/ememergency access (to be consistent let's rename it to "privleged" because this si now called "privielegd access" by the IAM team)
678
663
g .Context ("as engineer user" , func () {
679
664
var client * kubernetes.Clientset
680
665
@@ -685,46 +670,44 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
685
670
framework .ExpectNoError (err )
686
671
})
687
672
688
- // these tests are similar to the ones for unprivileged (let's think about that) (also see remarks of the first test in the block below)
689
673
g .It ("should allow write access in user namespace" , func () {
690
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
691
- 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 )
692
676
})
693
677
694
678
g .It ("should deny write access in collaborator namespace" , func () {
695
- _ , 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" }})
696
680
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
697
681
})
698
682
699
683
g .It ("should deny write access in system namespace" , func () {
700
- _ , 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" }})
701
685
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
702
686
})
703
687
})
704
688
705
- g .Context ("as unprivileged user" , func () {
689
+ g .Context ("as read-only user" , func () {
706
690
var client * kubernetes.Clientset
707
691
708
692
g .BeforeEach (func () {
709
693
var err error
710
694
711
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
695
+ client , err = getReadOnlyClient (eksCluster , awsAccountID )
712
696
framework .ExpectNoError (err )
713
697
})
714
698
715
- // TODO: is that correct?? We use "readonly" as the role in the test case, why should this be able to delete something?
716
- g .It ("should allow write access in user namespace" , func () {
717
- _ , err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Create (context .Background (), nonSystemResource , metav1.CreateOptions {DryRun : []string {"All" }})
718
- framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
699
+ g .It ("should deny write access in user namespace" , func () {
700
+ err := client .CoreV1 ().Pods (nonSystemResource .Namespace ).Delete (context .Background (), nonSystemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
701
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
719
702
})
720
703
721
704
g .It ("should deny write access in collaborator namespace" , func () {
722
- _ , err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Create (context .Background (), collaboratorResource , metav1.CreateOptions {DryRun : []string {"All" }})
705
+ err := client .CoreV1 ().Pods (collaboratorResource .Namespace ).Delete (context .Background (), collaboratorResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
723
706
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
724
707
})
725
708
726
709
g .It ("should deny write access in system namespace" , func () {
727
- _ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
710
+ err := client .CoreV1 ().Pods (systemResource .Namespace ).Delete (context .Background (), systemResource . Name , metav1.DeleteOptions {DryRun : []string {"All" }})
728
711
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
729
712
})
730
713
})
@@ -746,13 +729,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
746
729
framework .ExpectNoError (err )
747
730
})
748
731
749
- g .Context ("as privileged user" , func () {
732
+ g .Context ("as admin user" , func () {
750
733
var client * kubernetes.Clientset
751
734
752
735
g .BeforeEach (func () {
753
736
var err error
754
737
755
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
738
+ client , err = getAdminClient (eksCluster , awsAccountID )
756
739
framework .ExpectNoError (err )
757
740
})
758
741
@@ -761,6 +744,11 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
761
744
framework .ExpectNoError (err , "failed to delete cluster role: %s" , nonSystemResource .Name )
762
745
})
763
746
747
+ g .It ("should allow write access for collaborator resources" , func () {
748
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
749
+ framework .ExpectNoError (err , "failed to delete cluster role: %s" , "visibility" )
750
+ })
751
+
764
752
g .It ("should allow write access for system resources" , func () {
765
753
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
766
754
framework .ExpectNoError (err , "failed to delete cluster role: %s" , systemResource .Name )
@@ -782,22 +770,31 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
782
770
framework .ExpectNoError (err , "failed to delete cluster role: %s" , nonSystemResource .Name )
783
771
})
784
772
773
+ g .It ("should allow write access for collaborator resources" , func () {
774
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
775
+ framework .ExpectNoError (err , "failed to delete cluster role: %s" , "visibility" )
776
+ })
777
+
785
778
g .It ("should deny write access for system resources" , func () {
786
779
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
787
780
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
788
781
})
789
782
790
783
// test specific namespaces
791
-
792
- g .It ("should deny deletion of kube-system namespace" , func () {
793
- err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "kube-system" , metav1.DeleteOptions {DryRun : []string {"All" }})
794
- gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
784
+ g .It ("should allow deletion of non-system namespace" , func () {
785
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), nonSystemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
786
+ framework .ExpectNoError (err , "failed to delete namespace: %s" , nonSystemResource .Name )
795
787
})
796
788
797
789
g .It ("should deny deletion of visibility namespace" , func () {
798
790
err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
799
791
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
800
792
})
793
+
794
+ g .It ("should deny deletion of kube-system namespace" , func () {
795
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
796
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
797
+ })
801
798
})
802
799
803
800
g .Context ("as engineer user" , func () {
@@ -815,39 +812,49 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
815
812
framework .ExpectNoError (err , "failed to delete cluster role: %s" , nonSystemResource .Name )
816
813
})
817
814
815
+ g .It ("should deny write access for collaborator resources" , func () {
816
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
817
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
818
+ })
819
+
818
820
g .It ("should deny write access for system resources" , func () {
819
821
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
820
822
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
821
823
})
822
824
823
825
// test specific namespaces
824
-
825
- g .It ("should deny deletion of kube-system namespace" , func () {
826
- err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "kube-system" , metav1.DeleteOptions {DryRun : []string {"All" }})
827
- gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
828
- })
829
-
830
826
g .It ("should deny deletion of visibility namespace" , func () {
831
827
err := client .CoreV1 ().Namespaces ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
832
828
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
833
829
})
830
+
831
+ g .It ("should deny deletion of kube-system namespace" , func () {
832
+ err := client .CoreV1 ().Namespaces ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
833
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("this namespace may not be deleted" )))
834
+ })
834
835
})
835
836
836
- g .Context ("as unprivileged user" , func () {
837
+ g .Context ("as read-only user" , func () {
837
838
var client * kubernetes.Clientset
838
839
839
840
g .BeforeEach (func () {
840
841
var err error
841
842
842
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
843
+ client , err = getReadOnlyClient (eksCluster , awsAccountID )
843
844
framework .ExpectNoError (err )
844
845
})
845
846
847
+ // why allow any write acess for read-only user?
846
848
g .It ("should allow write access for non-system resources" , func () {
847
849
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), nonSystemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
848
850
framework .ExpectNoError (err , "failed to delete cluster role: %s" , nonSystemResource .Name )
849
851
})
850
852
853
+ g .It ("should deny write access for collaborator resources" , func () {
854
+ err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), "visibility" , metav1.DeleteOptions {DryRun : []string {"All" }})
855
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
856
+ })
857
+
851
858
g .It ("should deny write access for system resources" , func () {
852
859
err := client .RbacV1 ().ClusterRoles ().Delete (context .Background (), systemResource .Name , metav1.DeleteOptions {DryRun : []string {"All" }})
853
860
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
@@ -901,13 +908,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
901
908
})
902
909
})
903
910
904
- g .Context ("as privileged user" , func () {
911
+ g .Context ("as admin user" , func () {
905
912
var client * kubernetes.Clientset
906
913
907
914
g .BeforeEach (func () {
908
915
var err error
909
916
910
- client , err = getPrivilegedClient (eksCluster , awsAccountID )
917
+ client , err = getAdminClient (eksCluster , awsAccountID )
911
918
framework .ExpectNoError (err )
912
919
})
913
920
@@ -927,13 +934,13 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
927
934
})
928
935
})
929
936
930
- g .Context ("as unprivileged user" , func () {
937
+ g .Context ("as read-only user" , func () {
931
938
var client * kubernetes.Clientset
932
939
933
940
g .BeforeEach (func () {
934
941
var err error
935
942
936
- client , err = getUnprivilegedClient (eksCluster , awsAccountID )
943
+ client , err = getReadOnlyClient (eksCluster , awsAccountID )
937
944
framework .ExpectNoError (err )
938
945
})
939
946
@@ -955,8 +962,8 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
955
962
})
956
963
})
957
964
958
- // getPrivilegedClient returns a client with the `zalando:administrator` group.
959
- func getPrivilegedClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
965
+ // getAdminClient returns a client with the `zalando:administrator` group.
966
+ func getAdminClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
960
967
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-privileged-role" , awsAccountID , aws .ToString (cluster .Name )))
961
968
}
962
969
@@ -970,8 +977,8 @@ func getEngineerClient(cluster *types.Cluster, awsAccountID string) (*kubernetes
970
977
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-engineer-role" , awsAccountID , aws .ToString (cluster .Name )))
971
978
}
972
979
973
- // getUnprivilegedClient returns a client with the `zalando:readonly` group.
974
- func getUnprivilegedClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
980
+ // getReadOnlyClient returns a client with the `zalando:readonly` group.
981
+ func getReadOnlyClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
975
982
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-unprivileged-role" , awsAccountID , aws .ToString (cluster .Name )))
976
983
}
977
984
0 commit comments