23
23
{"CollaboratorPowerUser" },
24
24
{"Administrator" },
25
25
}
26
+
27
+ // "secrets" are not included as they have their own set of test cases.
28
+ namespacedResources = []string {
29
+ "pods" ,
30
+ "apps/deployments" ,
31
+ "apps/statefulsets" ,
32
+ "apps/deployments/scale" ,
33
+ "apps/statefulsets/scale" ,
34
+ "services" ,
35
+ "persistentvolumes" ,
36
+ "persistentvolumeclaims" ,
37
+ "configmaps" ,
38
+ }
39
+ // "nodes" are not included as they have their own set of test cases.
40
+ globalResources = []string {
41
+ "namespaces" ,
42
+ "rbac.authorization.k8s.io/clusterroles" ,
43
+ "storage.k8s.io/storageclasses" ,
44
+ "apiextensions.k8s.io/customresourcedefinitions" ,
45
+ }
46
+ readOperations = []string {"get" , "list" , "watch" }
47
+ writeOperations = []string {"create" , "update" , "delete" , "patch" }
48
+ allOperations = append (readOperations , writeOperations ... )
26
49
)
27
50
28
51
var _ = g .Describe ("Authorization [RBAC] [Zalando]" , func () {
@@ -92,55 +115,38 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
92
115
tc .data .resources = []string {"secrets" }
93
116
})
94
117
g .It ("should deny access in all namespaces" , func () {
95
- tc .data .verbs = [] string { "get" , "list" , "watch" , "create" , "update" , "delete" , "patch" }
118
+ tc .data .verbs = allOperations
96
119
tc .data .namespaces = []string {"" , "teapot" , "kube-system" }
97
120
tc .run (context .TODO (), cs , false )
98
121
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
99
122
})
100
123
})
101
124
g .When ("the resource is not a Secret resource" , func () {
102
125
g .BeforeEach (func () {
103
- tc .data .resources = []string {
104
- "pods" ,
105
- "apps/deployments" ,
106
- "apps/daemonsets" ,
107
- "apps/statefulsets" ,
108
- "apps/deployments/scale" ,
109
- "apps/statefulsets/scale" ,
110
- "services" ,
111
- "persistentvolumes" ,
112
- "persistentvolumeclaims" ,
113
- "configmaps" ,
114
- }
126
+ tc .data .resources = namespacedResources
115
127
tc .data .namespaces = []string {"" , "teapot" , "kube-system" }
116
128
})
117
129
g .It ("should allow read access in all namespaces" , func () {
118
- tc .data .verbs = [] string { "get" , "list" , "watch" }
130
+ tc .data .verbs = readOperations
119
131
tc .run (context .TODO (), cs , true )
120
132
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
121
133
})
122
134
g .It ("should deny write access in all namespaces" , func () {
123
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
135
+ tc .data .verbs = writeOperations
124
136
tc .run (context .TODO (), cs , false )
125
137
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
126
138
})
127
139
})
128
140
g .When ("the resource is a global resource" , func () {
129
141
g .BeforeEach (func () {
130
- tc .data .resources = []string {
131
- "namespaces" ,
132
- "nodes" ,
133
- "rbac.authorization.k8s.io/clusterroles" ,
134
- "storage.k8s.io/storageclasses" ,
135
- "apiextensions.k8s.io/customresourcedefinitions" ,
136
- }
142
+ tc .data .resources = append (globalResources , "nodes" )
137
143
g .It ("should allow read access" , func () {
138
- tc .data .verbs = [] string { "get" , "list" , "watch" }
144
+ tc .data .verbs = readOperations
139
145
tc .run (context .TODO (), cs , true )
140
146
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
141
147
})
142
148
g .It ("should deny write access" , func () {
143
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
149
+ tc .data .verbs = writeOperations
144
150
tc .run (context .TODO (), cs , false )
145
151
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
146
152
})
@@ -162,21 +168,21 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
162
168
g .It ("should deny read access to Secrets in kube-system and visibility namespaces" , func () {
163
169
tc .data .resources = []string {"secrets" }
164
170
tc .data .namespaces = []string {"kube-system" , "visibility" }
165
- tc .data .verbs = [] string { "get" , "list" , "watch" }
171
+ tc .data .verbs = readOperations
166
172
tc .run (context .TODO (), cs , false )
167
173
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
168
174
})
169
175
170
176
g .It ("should deny write access to Nodes" , func () {
171
177
tc .data .resources = []string {"nodes" }
172
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
178
+ tc .data .verbs = writeOperations
173
179
tc .run (context .TODO (), cs , false )
174
180
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
175
181
})
176
182
177
183
g .It ("should deny write access to DaemonSets" , func () {
178
184
tc .data .resources = []string {"apps/daemonsets" }
179
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
185
+ tc .data .verbs = writeOperations
180
186
tc .run (context .TODO (), cs , false )
181
187
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
182
188
})
@@ -198,18 +204,8 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
198
204
199
205
g .When ("the resource is a namespaced resource" , func () {
200
206
g .BeforeEach (func () {
201
- tc .data .resources = []string {
202
- "pods" ,
203
- "apps/deployments" ,
204
- "apps/statefulsets" ,
205
- "apps/deployments/scale" ,
206
- "apps/statefulsets/scale" ,
207
- "services" ,
208
- "persistentvolumes" ,
209
- "persistentvolumeclaims" ,
210
- "configmaps" ,
211
- }
212
- tc .data .verbs = []string {"create" , "update" , "delete" , "patch" }
207
+ tc .data .resources = namespacedResources
208
+ tc .data .verbs = writeOperations
213
209
})
214
210
// These should be covered by the admission-controller tests.
215
211
// They're written here for completeness.
@@ -218,19 +214,15 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
218
214
})
219
215
g .When ("the resource is a global resource" , func () {
220
216
g .BeforeEach (func () {
221
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
217
+ tc .data .verbs = writeOperations
222
218
})
223
219
g .It ("should deny write access to Nodes" , func () {
224
220
tc .data .resources = []string {"nodes" }
225
221
tc .run (context .TODO (), cs , false )
226
222
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
227
223
})
228
224
g .It ("should allow write access to resources other than Nodes" , func () {
229
- tc .data .resources = []string {
230
- "namespaces" ,
231
- "storage.k8s.io/storageclasses" ,
232
- "apiextensions.k8s.io/customresourcedefinitions" ,
233
- }
225
+ tc .data .resources = globalResources
234
226
tc .run (context .TODO (), cs , true )
235
227
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
236
228
})
@@ -253,7 +245,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
253
245
g .When ("the resource is a Secret" , func () {
254
246
g .BeforeEach (func () {
255
247
tc .data .resources = []string {"secrets" }
256
- tc .data .verbs = [] string { "get" , "list" , "watch" }
248
+ tc .data .verbs = readOperations
257
249
})
258
250
259
251
g .It ("should allow read access to visibility namespace" , func () {
@@ -270,13 +262,13 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
270
262
271
263
g .It ("should deny write access to Nodes" , func () {
272
264
tc .data .resources = []string {"nodes" }
273
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
265
+ tc .data .verbs = writeOperations
274
266
tc .run (context .TODO (), cs , false )
275
267
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
276
268
})
277
269
g .It ("should allow write access to DaemonSets" , func () {
278
270
tc .data .resources = []string {"apps/daemonsets" }
279
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
271
+ tc .data .verbs = writeOperations
280
272
tc .data .namespaces = []string {"visibility" }
281
273
tc .run (context .TODO (), cs , true )
282
274
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
@@ -297,16 +289,8 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
297
289
298
290
g .When ("the resource is a namespaced resource" , func () {
299
291
g .BeforeEach (func () {
300
- tc .data .resources = []string {
301
- "pods" ,
302
- "apps/deployments" ,
303
- "apps/statefulsets" ,
304
- "services" ,
305
- "persistentvolumes" ,
306
- "persistentvolumeclaims" ,
307
- "configmaps" ,
308
- }
309
- tc .data .verbs = []string {"create" , "update" , "delete" , "patch" }
292
+ tc .data .resources = namespacedResources
293
+ tc .data .verbs = writeOperations
310
294
})
311
295
// This should be covered by the admission-controller tests.
312
296
// It's written here for completeness.
@@ -320,19 +304,15 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
320
304
321
305
g .When ("the resource is a global resource" , func () {
322
306
g .BeforeEach (func () {
323
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
307
+ tc .data .verbs = writeOperations
324
308
})
325
309
g .It ("should deny access to Nodes" , func () {
326
310
tc .data .resources = []string {"nodes" }
327
311
tc .run (context .TODO (), cs , false )
328
312
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
329
313
})
330
314
g .It ("should allow access to resources other than Nodes" , func () {
331
- tc .data .resources = []string {
332
- "namespaces" ,
333
- "storage.k8s.io/storageclasses" ,
334
- "apiextensions.k8s.io/customresourcedefinitions" ,
335
- }
315
+ tc .data .resources = globalResources
336
316
tc .run (context .TODO (), cs , true )
337
317
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
338
318
})
@@ -512,7 +492,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
512
492
tc .data .resources = []string {"secrets" }
513
493
})
514
494
g .It ("should allow read access" , func () {
515
- tc .data .verbs = [] string { "get" , "list" , "watch" }
495
+ tc .data .verbs = readOperations
516
496
tc .run (context .TODO (), cs , true )
517
497
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
518
498
})
@@ -523,12 +503,12 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
523
503
tc .data .resources = []string {"pods" }
524
504
})
525
505
g .It ("should allow read access" , func () {
526
- tc .data .verbs = [] string { "get" , "list" , "watch" }
506
+ tc .data .verbs = readOperations
527
507
tc .run (context .TODO (), cs , true )
528
508
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
529
509
})
530
510
g .It ("should allow write access" , func () {
531
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
511
+ tc .data .verbs = writeOperations
532
512
tc .run (context .TODO (), cs , true )
533
513
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
534
514
})
@@ -552,7 +532,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
552
532
tc .data .resources = []string {"secrets" }
553
533
})
554
534
g .It ("should allow read access" , func () {
555
- tc .data .verbs = [] string { "get" , "list" , "watch" }
535
+ tc .data .verbs = readOperations
556
536
tc .run (context .TODO (), cs , true )
557
537
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
558
538
})
@@ -562,7 +542,7 @@ var _ = g.Describe("Authorization [RBAC] [Zalando]", func() {
562
542
tc .data .resources = []string {"pods, apps/daemonsets" }
563
543
})
564
544
g .It ("should allow write access" , func () {
565
- tc .data .verbs = [] string { "create" , "update" , "delete" , "patch" }
545
+ tc .data .verbs = writeOperations
566
546
tc .run (context .TODO (), cs , true )
567
547
gomega .Expect (tc .output .passed ).To (gomega .BeTrue (), tc .output .String ())
568
548
})
0 commit comments