@@ -590,12 +590,14 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
590
590
591
591
g .Context ("for namespaced resources" , func () {
592
592
var (
593
- systemResource * corev1.Pod
594
- nonSystemResource * corev1.Pod
593
+ systemResource * corev1.Pod
594
+ collaboratorResource * corev1.Pod
595
+ nonSystemResource * corev1.Pod
595
596
)
596
597
597
598
g .BeforeEach (func () {
598
599
systemResource = examplePod ("kube-system" , nil )
600
+ collaboratorResource = examplePod ("visibility" , nil )
599
601
nonSystemResource = examplePod (f .Namespace .Name , nil )
600
602
})
601
603
@@ -614,12 +616,43 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
614
616
framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
615
617
})
616
618
619
+ 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 )
622
+ })
623
+
617
624
g .It ("should allow write access in system namespace" , func () {
618
625
_ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
619
626
framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , systemResource .Name , systemResource .Namespace )
620
627
})
621
628
})
622
629
630
+ g .Context ("as collaborator user" , func () {
631
+ var client * kubernetes.Clientset
632
+
633
+ g .BeforeEach (func () {
634
+ var err error
635
+
636
+ client , err = getCollaboratorClient (eksCluster , awsAccountID )
637
+ framework .ExpectNoError (err )
638
+ })
639
+
640
+ 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 )
643
+ })
644
+
645
+ 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 )
648
+ })
649
+
650
+ 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" }})
652
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
653
+ })
654
+ })
655
+
623
656
g .Context ("as unprivileged user" , func () {
624
657
var client * kubernetes.Clientset
625
658
@@ -635,6 +668,11 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
635
668
framework .ExpectNoError (err , "failed to create pod: %s in namespace: %s" , nonSystemResource .Name , nonSystemResource .Namespace )
636
669
})
637
670
671
+ 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" }})
673
+ gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
674
+ })
675
+
638
676
g .It ("should deny write access in system namespace" , func () {
639
677
_ , err := client .CoreV1 ().Pods (systemResource .Namespace ).Create (context .Background (), systemResource , metav1.CreateOptions {DryRun : []string {"All" }})
640
678
gomega .Expect (err ).To (gomega .MatchError (gomega .ContainSubstring ("write operations are forbidden" )))
@@ -806,6 +844,11 @@ func getPrivilegedClient(cluster *types.Cluster, awsAccountID string) (*kubernet
806
844
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-privileged-role" , awsAccountID , aws .ToString (cluster .Name )))
807
845
}
808
846
847
+ // getCollaboratorClient returns a client with the `zalando:collaborator` group.
848
+ func getCollaboratorClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
849
+ return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-collaborator-role" , awsAccountID , aws .ToString (cluster .Name )))
850
+ }
851
+
809
852
// getUnprivilegedClient returns a client with the `zalando:readonly` group.
810
853
func getUnprivilegedClient (cluster * types.Cluster , awsAccountID string ) (* kubernetes.Clientset , error ) {
811
854
return newClientWithRole (cluster , fmt .Sprintf ("arn:aws:iam::%s:role/%s-e2e-eks-iam-test-unprivileged-role" , awsAccountID , aws .ToString (cluster .Name )))
0 commit comments