@@ -192,7 +192,7 @@ func TestSubjectCheckers(t *testing.T) {
192
192
shouldAllow : true ,
193
193
},
194
194
{
195
- name : "allow service account by literal name match " ,
195
+ name : "allow service account with explicit namespace by match on literal name and explicit namespace " ,
196
196
checker : mustNewSubjectChecker (t ,
197
197
& authorizationapi.RoleBindingRestrictionSpec {
198
198
ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
@@ -208,7 +208,7 @@ func TestSubjectCheckers(t *testing.T) {
208
208
shouldAllow : true ,
209
209
},
210
210
{
211
- name : "allow service account by literal name match with implicit namespace" ,
211
+ name : "allow service account with explicit namespace by match on literal name and implicit namespace" ,
212
212
checker : mustNewSubjectChecker (t ,
213
213
& authorizationapi.RoleBindingRestrictionSpec {
214
214
ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
@@ -220,6 +220,113 @@ func TestSubjectCheckers(t *testing.T) {
220
220
subject : serviceaccountRef ,
221
221
shouldAllow : true ,
222
222
},
223
+ {
224
+ name : "prohibit service account with explicit namespace where literal name matches but explicit namespace does not" ,
225
+ checker : mustNewSubjectChecker (t ,
226
+ & authorizationapi.RoleBindingRestrictionSpec {
227
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
228
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
229
+ {
230
+ Namespace : serviceaccountRef .Namespace ,
231
+ Name : serviceaccountRef .Name ,
232
+ },
233
+ },
234
+ },
235
+ }),
236
+ subject : kapi.ObjectReference {
237
+ Kind : authorizationapi .ServiceAccountKind ,
238
+ Namespace : "othernamespace" ,
239
+ Name : serviceaccountRef .Name ,
240
+ },
241
+ shouldAllow : false ,
242
+ },
243
+ {
244
+ name : "prohibit service account with explicit namespace where literal name matches but implicit namespace does not" ,
245
+ checker : mustNewSubjectChecker (t ,
246
+ & authorizationapi.RoleBindingRestrictionSpec {
247
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
248
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
249
+ {Name : serviceaccountRef .Name },
250
+ },
251
+ },
252
+ }),
253
+ subject : kapi.ObjectReference {
254
+ Kind : authorizationapi .ServiceAccountKind ,
255
+ Namespace : "othernamespace" ,
256
+ Name : serviceaccountRef .Name ,
257
+ },
258
+ shouldAllow : false ,
259
+ },
260
+ {
261
+ name : "allow service account with implicit namespace by match on literal name and explicit namespace" ,
262
+ checker : mustNewSubjectChecker (t ,
263
+ & authorizationapi.RoleBindingRestrictionSpec {
264
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
265
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
266
+ {
267
+ Name : serviceaccountRef .Name ,
268
+ Namespace : serviceaccountRef .Namespace ,
269
+ },
270
+ },
271
+ },
272
+ }),
273
+ subject : kapi.ObjectReference {
274
+ Kind : authorizationapi .ServiceAccountKind ,
275
+ Name : serviceaccountRef .Name ,
276
+ },
277
+ shouldAllow : true ,
278
+ },
279
+ {
280
+ name : "allow service account with implicit namespace by match on literal name and implicit namespace" ,
281
+ checker : mustNewSubjectChecker (t ,
282
+ & authorizationapi.RoleBindingRestrictionSpec {
283
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
284
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
285
+ {Name : serviceaccountRef .Name },
286
+ },
287
+ },
288
+ }),
289
+ subject : kapi.ObjectReference {
290
+ Kind : authorizationapi .ServiceAccountKind ,
291
+ Name : serviceaccountRef .Name ,
292
+ },
293
+ shouldAllow : true ,
294
+ },
295
+ {
296
+ name : "prohibit service account with implicit namespace where literal name matches but explicit namespace does not" ,
297
+ checker : mustNewSubjectChecker (t ,
298
+ & authorizationapi.RoleBindingRestrictionSpec {
299
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
300
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
301
+ {
302
+ Namespace : "othernamespace" ,
303
+ Name : serviceaccountRef .Name ,
304
+ },
305
+ },
306
+ },
307
+ }),
308
+ subject : kapi.ObjectReference {
309
+ Kind : authorizationapi .ServiceAccountKind ,
310
+ Name : serviceaccountRef .Name ,
311
+ },
312
+ shouldAllow : false ,
313
+ },
314
+ {
315
+ name : "prohibit service account with explicit namespace where explicit namespace matches but literal name does not" ,
316
+ checker : mustNewSubjectChecker (t ,
317
+ & authorizationapi.RoleBindingRestrictionSpec {
318
+ ServiceAccountRestriction : & authorizationapi.ServiceAccountRestriction {
319
+ ServiceAccounts : []authorizationapi.ServiceAccountReference {
320
+ {
321
+ Namespace : serviceaccountRef .Namespace ,
322
+ Name : "othername" ,
323
+ },
324
+ },
325
+ },
326
+ }),
327
+ subject : serviceaccountRef ,
328
+ shouldAllow : false ,
329
+ },
223
330
{
224
331
name : "allow service account by match on namespace" ,
225
332
checker : mustNewSubjectChecker (t ,
0 commit comments