@@ -36,29 +36,40 @@ var (
36
36
"persistentvolumeclaims" ,
37
37
"configmaps" ,
38
38
}
39
+
39
40
// "nodes" are not included as they have their own set of test cases.
40
41
globalResources = []string {
41
42
"namespaces" ,
42
43
"rbac.authorization.k8s.io/clusterroles" ,
43
44
"storage.k8s.io/storageclasses" ,
44
45
"apiextensions.k8s.io/customresourcedefinitions" ,
45
46
}
46
- readOperations = []string {"get" , "list" , "watch" }
47
+ // a slice of "get", "list", "watch" verbs
48
+ readOperations = []string {"get" , "list" , "watch" }
49
+
50
+ // a slice of "create", "update", "delete", "patch" verbs
47
51
writeOperations = []string {"create" , "update" , "delete" , "patch" }
48
- allOperations = append (readOperations , writeOperations ... )
52
+
53
+ // a slice of all operations
54
+ allOperations = append (readOperations , writeOperations ... )
55
+
56
+ // a slice representing all namespaces with respect to the test cases
57
+ // "" represents the default namespace
58
+ // "teapot" is a random namespace
59
+ // "visibility" is a namespace where collaborators will have access
60
+ // "kube-system" is a namespace where only administrators will have access
61
+ allNamespaces = []string {"" , "teapot" , "visibility" , "kube-system" }
49
62
)
50
63
51
64
var _ = g .Describe ("Authorization [RBAC] [Zalando]" , func () {
52
65
var cs kubernetes.Interface
53
66
54
67
f := framework .NewDefaultFramework ("authorization" )
55
68
56
- // Initialise the clientset before each test
57
69
g .BeforeEach (func () {
58
70
cs = f .ClientSet
59
71
})
60
72
61
- // Test cases for all groups of users
62
73
g .Context ("For all groups" , func () {
63
74
var tc testCase
64
75
g .BeforeEach (func () {
@@ -80,7 +91,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
80
91
})
81
92
g .It ("should deny access for service accounts" , func () {
82
93
tc .data .resources = []string {"serviceaccounts" }
83
- tc .data .namespaces = [] string { "" , "teapot" , "kube-system" }
94
+ tc .data .namespaces = allNamespaces
84
95
tc .run (context .TODO (), cs , false )
85
96
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
86
97
})
@@ -97,7 +108,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
97
108
})
98
109
g .It ("should deny access for roles in all namespaces" , func () {
99
110
tc .data .resources = []string {"rbac.authorization.k8s.io/role" }
100
- tc .data .namespaces = [] string { "" , "teapot" , "kube-system" }
111
+ tc .data .namespaces = allNamespaces
101
112
tc .run (context .TODO (), cs , false )
102
113
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
103
114
})
@@ -116,15 +127,15 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
116
127
})
117
128
g .It ("should deny access in all namespaces" , func () {
118
129
tc .data .verbs = allOperations
119
- tc .data .namespaces = [] string { "" , "teapot" , "kube-system" }
130
+ tc .data .namespaces = allNamespaces
120
131
tc .run (context .TODO (), cs , false )
121
132
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
122
133
})
123
134
})
124
135
g .When ("the resource is not a Secret resource" , func () {
125
136
g .BeforeEach (func () {
126
137
tc .data .resources = namespacedResources
127
- tc .data .namespaces = [] string { "" , "teapot" , "kube-system" }
138
+ tc .data .namespaces = allNamespaces
128
139
})
129
140
g .It ("should allow read access in all namespaces" , func () {
130
141
tc .data .verbs = readOperations
@@ -498,34 +509,23 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
498
509
g .BeforeEach (func () {
499
510
tc .data .resources = []string {"secrets" }
500
511
})
501
- g .It ("should allow read access" , func () {
502
- tc .data .verbs = readOperations
503
- tc .run (context .TODO (), cs , true )
504
- gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
505
- })
506
- g .It ("should allow write access" , func () {
507
- tc .data .verbs = writeOperations
512
+ g .It ("should allow read and write access" , func () {
513
+ tc .data .verbs = allOperations
508
514
tc .run (context .TODO (), cs , true )
509
515
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
510
516
})
511
517
})
512
518
513
519
g .When ("the resource is not a Secret" , func () {
514
520
g .BeforeEach (func () {
515
- tc .data .resources = [] string { "pods" }
521
+ tc .data .resources = namespacedResources
516
522
})
517
- g .It ("should allow read access" , func () {
518
- tc .data .verbs = readOperations
519
- tc .run (context .TODO (), cs , true )
520
- gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
521
- })
522
- g .It ("should allow write access" , func () {
523
- tc .data .verbs = writeOperations
523
+ g .It ("should allow read and write access" , func () {
524
+ tc .data .verbs = allOperations
524
525
tc .run (context .TODO (), cs , true )
525
526
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
526
527
})
527
528
})
528
-
529
529
})
530
530
531
531
g .When ("namespace is not kube-system" , func () {
@@ -551,7 +551,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
551
551
})
552
552
g .When ("the resource is not a Secret" , func () {
553
553
g .BeforeEach (func () {
554
- tc .data .resources = [] string { "pods, apps/daemonsets" }
554
+ tc .data .resources = namespacedResources
555
555
})
556
556
g .It ("should allow write access" , func () {
557
557
tc .data .verbs = writeOperations
0 commit comments