Skip to content

Commit 1b7e154

Browse files
committed
fix admision-controller test cases
Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
1 parent e042dd9 commit 1b7e154

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

test/e2e/authorization.go

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,15 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
529529
tc.run(context.TODO(), cs, true)
530530
gomega.Expect(tc.output.passed).To(gomega.BeTrue(), tc.output.String())
531531
})
532+
g.It("should create a clusterrole with read secret permission", func() {
533+
tc.data.namespaces = []string{"teapot"}
534+
tc.data.resources = []string{"clusterrole"}
535+
tc.data.verbs = []string{"create"}
536+
tc.run(context.TODO(), cs, true)
537+
gomega.Expect(tc.output.passed).To(gomega.BeTrue(), tc.output.String())
538+
})
532539
})
533-
g.When("the service account is CDP", func() {
540+
g.When("[Katyanna] the service account is CDP", func() {
534541
g.BeforeEach(func() {
535542
tc.data.groups = [][]string{{"system:serviceaccounts:default"}}
536543
tc.data.users = []string{"system:serviceaccount:default:cdp"}
@@ -549,7 +556,6 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
549556
tc.run(context.TODO(), cs, true)
550557
gomega.Expect(tc.output.passed).To(gomega.BeTrue(), tc.output.String())
551558
})
552-
// TODO: create clusterrole with read secret permission
553559
g.It("should create a clusterrole with read secret permission", func() {
554560
tc.data.namespaces = []string{"teapot"}
555561
tc.data.resources = []string{"clusterrole"}
@@ -956,17 +962,22 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
956962
// granted to CDP and deployment-service are revoked.
957963
g.Context("cdp and deployment-service", func() {
958964
var (
959-
testSecret *corev1.Secret
960-
systemSecret *corev1.Secret
965+
systemResource *rbacv1.ClusterRole
966+
nonSystemResource *rbacv1.ClusterRole
961967
)
962968

963969
g.BeforeEach(func() {
964-
var err error
965-
testSecret, err = createSecret(context.Background(), f.ClientSet, f.Namespace.Name, map[string]string{"application": "my-app"})
966-
framework.ExpectNoError(err)
967-
968-
systemSecret, err = createSecret(context.Background(), f.ClientSet, "kube-system", map[string]string{"application": "my-app"})
969-
framework.ExpectNoError(err)
970+
systemResource = &rbacv1.ClusterRole{
971+
ObjectMeta: metav1.ObjectMeta{
972+
GenerateName: "test-cluster-role-",
973+
Labels: map[string]string{"admission.zalando.org/infrastructure-component": "true"},
974+
},
975+
}
976+
nonSystemResource = &rbacv1.ClusterRole{
977+
ObjectMeta: metav1.ObjectMeta{
978+
GenerateName: "test-cluster-role-",
979+
},
980+
}
970981
})
971982

972983
g.Context("cdp", func() {
@@ -979,14 +990,14 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
979990
framework.ExpectNoError(err)
980991
})
981992

982-
g.It("should deny secret read access to user namespace", func() {
983-
_, err := client.CoreV1().Secrets(testSecret.Namespace).Get(context.Background(), testSecret.Name, metav1.GetOptions{})
984-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("read operations are forbidden")))
993+
g.It("should deny creating clusterrole with read secret permission on system namespace", func() {
994+
_, err := client.RbacV1().ClusterRoles().Create(context.Background(), systemResource, metav1.CreateOptions{DryRun: []string{}})
995+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("write operations are forbidden")))
985996
})
986997

987-
g.It("should deny secret read access to kube-system namespace", func() {
988-
_, err := client.CoreV1().Secrets(systemSecret.Namespace).Get(context.Background(), systemSecret.Name, metav1.GetOptions{})
989-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("read operations are forbidden")))
998+
g.It("should deny creating clusterrole with read secret permission on user namespace", func() {
999+
_, err := client.RbacV1().ClusterRoles().Create(context.Background(), nonSystemResource, metav1.CreateOptions{DryRun: []string{}})
1000+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("write operations are forbidden")))
9901001
})
9911002
})
9921003

@@ -1000,14 +1011,14 @@ var _ = g.Describe("Authorization via admission-controller [RBAC] [Zalando]", fu
10001011
framework.ExpectNoError(err)
10011012
})
10021013

1003-
g.It("should deny secret read access to user namespace", func() {
1004-
_, err := client.CoreV1().Secrets(testSecret.Namespace).Get(context.Background(), testSecret.Name, metav1.GetOptions{})
1005-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("read operations are forbidden")))
1014+
g.It("should deny creating clusterrole with read secret permission on system namespace", func() {
1015+
_, err := client.RbacV1().ClusterRoles().Create(context.Background(), systemResource, metav1.CreateOptions{DryRun: []string{}})
1016+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("write operations are forbidden")))
10061017
})
10071018

1008-
g.It("should deny secret read access to kube-system namespace", func() {
1009-
_, err := client.CoreV1().Secrets(systemSecret.Namespace).Get(context.Background(), systemSecret.Name, metav1.GetOptions{})
1010-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("read operations are forbidden")))
1019+
g.It("should deny creating clusterrole with read secret permission on user namespace", func() {
1020+
_, err := client.RbacV1().ClusterRoles().Create(context.Background(), nonSystemResource, metav1.CreateOptions{DryRun: []string{}})
1021+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("write operations are forbidden")))
10111022
})
10121023
})
10131024
})

0 commit comments

Comments
 (0)