forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
policy.go
1348 lines (1223 loc) · 64.4 KB
/
policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package bootstrappolicy
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kutilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/apps"
kauthenticationapi "k8s.io/kubernetes/pkg/apis/authentication"
kauthorizationapi "k8s.io/kubernetes/pkg/apis/authorization"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/settings"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy"
oapi "github.com/openshift/origin/pkg/api"
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
deployapi "github.com/openshift/origin/pkg/deploy/apis/apps"
imageapi "github.com/openshift/origin/pkg/image/apis/image"
oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth"
projectapi "github.com/openshift/origin/pkg/project/apis/project"
quotaapi "github.com/openshift/origin/pkg/quota/apis/quota"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
networkapi "github.com/openshift/origin/pkg/sdn/apis/network"
securityapi "github.com/openshift/origin/pkg/security/apis/security"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
userapi "github.com/openshift/origin/pkg/user/apis/user"
)
const (
// roleSystemOnly is an annotation key that determines if a role is system only
roleSystemOnly = "authorization.openshift.io/system-only"
// roleIsSystemOnly is an annotation value that denotes roleSystemOnly, and thus excludes the role from the UI
roleIsSystemOnly = "true"
)
var (
readWrite = []string{"get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"}
read = []string{"get", "list", "watch"}
kapiGroup = kapi.GroupName
appsGroup = apps.GroupName
autoscalingGroup = autoscaling.GroupName
batchGroup = batch.GroupName
certificatesGroup = certificates.GroupName
extensionsGroup = extensions.GroupName
policyGroup = policy.GroupName
rbacGroup = rbac.GroupName
securityGroup = securityapi.GroupName
legacySecurityGroup = securityapi.LegacyGroupName
storageGroup = storage.GroupName
settingsGroup = settings.GroupName
authzGroup = authorizationapi.GroupName
kAuthzGroup = kauthorizationapi.GroupName
kAuthnGroup = kauthenticationapi.GroupName
legacyAuthzGroup = authorizationapi.LegacyGroupName
buildGroup = buildapi.GroupName
legacyBuildGroup = buildapi.LegacyGroupName
deployGroup = deployapi.GroupName
legacyDeployGroup = deployapi.LegacyGroupName
imageGroup = imageapi.GroupName
legacyImageGroup = imageapi.LegacyGroupName
projectGroup = projectapi.GroupName
legacyProjectGroup = projectapi.LegacyGroupName
quotaGroup = quotaapi.GroupName
legacyQuotaGroup = quotaapi.LegacyGroupName
routeGroup = routeapi.GroupName
legacyRouteGroup = routeapi.LegacyGroupName
templateGroup = templateapi.GroupName
legacyTemplateGroup = templateapi.LegacyGroupName
userGroup = userapi.GroupName
legacyUserGroup = userapi.LegacyGroupName
oauthGroup = oauthapi.GroupName
legacyOauthGroup = oauthapi.LegacyGroupName
networkGroup = networkapi.GroupName
legacyNetworkGroup = networkapi.LegacyGroupName
)
func GetBootstrapOpenshiftRoles(openshiftNamespace string) []authorizationapi.Role {
roles := []authorizationapi.Role{
{
ObjectMeta: metav1.ObjectMeta{
Name: OpenshiftSharedResourceViewRoleName,
Namespace: openshiftNamespace,
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(read...).Groups(templateGroup, legacyTemplateGroup).Resources("templates").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams", "imagestreamtags", "imagestreamimages").RuleOrDie(),
// so anyone can pull from openshift/* image streams
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
},
},
}
// we don't want to expose the resourcegroups externally because it makes it very difficult for customers to learn from
// our default roles and hard for them to reason about what power they are granting their users
for i := range roles {
for j := range roles[i].Rules {
roles[i].Rules[j].Resources = authorizationapi.NormalizeResources(roles[i].Rules[j].Resources)
}
}
return roles
}
func GetOpenshiftBootstrapClusterRoles() []authorizationapi.ClusterRole {
// four resource can be a single line
// up to ten-ish resources per line otherwise
roles := []authorizationapi.ClusterRole{
{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterAdminRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A super-user that can perform any action in the cluster. When granted to a user within a project, they have full control over quota and membership and can perform every action on every resource in the project.",
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("*").Groups("*").Resources("*").RuleOrDie(),
{
Verbs: sets.NewString(authorizationapi.VerbAll),
NonResourceURLs: sets.NewString(authorizationapi.NonResourceAll),
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: SudoerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("impersonate").Groups(userGroup, legacyUserGroup).Resources(authorizationapi.SystemUserResource).Names(SystemAdminUsername).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterReaderRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("bindings", "componentstatuses", "configmaps", "endpoints", "events", "limitranges",
"namespaces", "namespaces/status", "nodes", "nodes/status", "persistentvolumeclaims", "persistentvolumeclaims/status", "persistentvolumes",
"persistentvolumes/status", "pods", "pods/binding", "pods/eviction", "pods/log", "pods/status", "podtemplates", "replicationcontrollers", "replicationcontrollers/scale",
"replicationcontrollers/status", "resourcequotas", "resourcequotas/status", "securitycontextconstraints", "serviceaccounts", "services",
"services/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(appsGroup).Resources("statefulsets", "statefulsets/status", "deployments", "deployments/scale", "deployments/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(autoscalingGroup).Resources("horizontalpodautoscalers", "horizontalpodautoscalers/status").RuleOrDie(),
// TODO do we still need scheduledjobs?
authorizationapi.NewRule(read...).Groups(batchGroup).Resources("jobs", "jobs/status", "scheduledjobs", "scheduledjobs/status", "cronjobs", "cronjobs/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("daemonsets", "daemonsets/status", "deployments", "deployments/scale",
"deployments/status", "horizontalpodautoscalers", "horizontalpodautoscalers/status", "ingresses", "ingresses/status", "jobs", "jobs/status",
"networkpolicies", "podsecuritypolicies", "replicasets", "replicasets/scale", "replicasets/status", "replicationcontrollers",
"replicationcontrollers/scale", "storageclasses", "thirdpartyresources").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(policyGroup).Resources("poddisruptionbudgets", "poddisruptionbudgets/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(rbacGroup).Resources("roles", "rolebindings", "clusterroles", "clusterrolebindings").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(settingsGroup).Resources("podpresets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(storageGroup).Resources("storageclasses").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(certificatesGroup).Resources("certificatesigningrequests", "certificatesigningrequests/approval", "certificatesigningrequests/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(authzGroup, legacyAuthzGroup).Resources("clusterpolicies", "clusterpolicybindings", "clusterroles", "clusterrolebindings",
"policies", "policybindings", "roles", "rolebindings", "rolebindingrestrictions").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("builds", "builds/details", "buildconfigs", "buildconfigs/webhooks", "builds/log").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs", "deploymentconfigs/scale", "deploymentconfigs/log",
"deploymentconfigs/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("images", "imagesignatures", "imagestreams", "imagestreamtags", "imagestreamimages",
"imagestreams/status").RuleOrDie(),
// pull images
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(oauthGroup, legacyOauthGroup).Resources("oauthclientauthorizations").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(projectGroup, legacyProjectGroup).Resources("projectrequests", "projects").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(quotaGroup, legacyQuotaGroup).Resources("appliedclusterresourcequotas", "clusterresourcequotas", "clusterresourcequotas/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(routeGroup, legacyRouteGroup).Resources("routes", "routes/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(networkGroup, legacyNetworkGroup).Resources("clusternetworks", "egressnetworkpolicies", "hostsubnets", "netnamespaces").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(securityGroup, legacySecurityGroup).Resources("securitycontextconstraints").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(templateGroup, legacyTemplateGroup).Resources("templates", "templateconfigs", "processedtemplates", "templateinstances").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(userGroup, legacyUserGroup).Resources("groups", "identities", "useridentitymappings", "users").RuleOrDie(),
// permissions to check access. These creates are non-mutating
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("localresourceaccessreviews", "localsubjectaccessreviews", "resourceaccessreviews",
"selfsubjectrulesreviews", "subjectrulesreviews", "subjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("selfsubjectaccessreviews", "subjectaccessreviews", "localsubjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthnGroup).Resources("tokenreviews").RuleOrDie(),
// permissions to check PSP, these creates are non-mutating
authorizationapi.NewRule("create").Groups(securityGroup, legacySecurityGroup).Resources("podsecuritypolicysubjectreviews", "podsecuritypolicyselfsubjectreviews", "podsecuritypolicyreviews").RuleOrDie(),
// Allow read access to node metrics
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("nodes/"+authorizationapi.NodeMetricsSubresource, "nodes/"+authorizationapi.NodeSpecSubresource).RuleOrDie(),
// Allow read access to stats
// Node stats requests are submitted as POSTs. These creates are non-mutating
authorizationapi.NewRule("get", "create").Groups(kapiGroup).Resources("nodes/" + authorizationapi.NodeStatsSubresource).RuleOrDie(),
{
Verbs: sets.NewString("get"),
NonResourceURLs: sets.NewString(authorizationapi.NonResourceAll),
},
// backwards compatibility
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("buildlogs").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("resourcequotausages").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterDebuggerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
{
Verbs: sets.NewString("get"),
NonResourceURLs: sets.NewString("/metrics", "/debug/pprof", "/debug/pprof/*"),
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: BuildStrategyDockerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources(authorizationapi.DockerBuildResource, authorizationapi.OptimizedDockerBuildResource).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: BuildStrategyCustomRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources(authorizationapi.CustomBuildResource).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: BuildStrategySourceRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources(authorizationapi.SourceBuildResource).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: BuildStrategyJenkinsPipelineRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources(authorizationapi.JenkinsPipelineBuildResource).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: StorageAdminRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("persistentvolumes").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(storageGroup).Resources("storageclasses").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("persistentvolumeclaims", "events").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: AdminRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user that has edit rights within the project and can change the project's membership.",
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("pods", "pods/attach", "pods/proxy", "pods/exec", "pods/portforward").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("replicationcontrollers", "replicationcontrollers/scale", "serviceaccounts",
"services", "services/proxy", "endpoints", "persistentvolumeclaims", "configmaps", "secrets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("limitranges", "resourcequotas", "bindings", "events",
"namespaces", "pods/status", "resourcequotas/status", "namespaces/status", "replicationcontrollers/status", "pods/log").RuleOrDie(),
authorizationapi.NewRule("impersonate").Groups(kapiGroup).Resources("serviceaccounts").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(autoscalingGroup).Resources("horizontalpodautoscalers").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(batchGroup).Resources("jobs", "scheduledjobs", "cronjobs").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(extensionsGroup).Resources("jobs", "horizontalpodautoscalers", "replicationcontrollers/scale",
"replicasets", "replicasets/scale", "deployments", "deployments/scale", "deployments/rollback").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("daemonsets").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(appsGroup).Resources("statefulsets", "deployments", "deployments/scale", "deployments/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(authzGroup, legacyAuthzGroup).Resources("roles", "rolebindings").RuleOrDie(),
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("localresourceaccessreviews", "localsubjectaccessreviews", "subjectrulesreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(securityGroup, legacySecurityGroup).Resources("podsecuritypolicysubjectreviews", "podsecuritypolicyselfsubjectreviews", "podsecuritypolicyreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("localsubjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(authzGroup, legacyAuthzGroup).Resources("policies", "policybindings", "rolebindingrestrictions").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(buildGroup, legacyBuildGroup).Resources("builds", "buildconfigs", "buildconfigs/webhooks").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("builds/log").RuleOrDie(),
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs/instantiate", "buildconfigs/instantiatebinary", "builds/clone").RuleOrDie(),
authorizationapi.NewRule("update").Groups(buildGroup, legacyBuildGroup).Resources("builds/details").RuleOrDie(),
// access to jenkins. multiple values to ensure that covers relationships
authorizationapi.NewRule("admin", "edit", "view").Groups(buildapi.GroupName).Resources("jenkins").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs", "generatedeploymentconfigs", "deploymentconfigs/scale").RuleOrDie(),
authorizationapi.NewRule("create").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigrollbacks", "deploymentconfigs/rollback", "deploymentconfigs/instantiate").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs/log", "deploymentconfigs/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams", "imagestreammappings", "imagestreamtags", "imagestreamimages", "imagestreams/secrets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams/status").RuleOrDie(),
// push and pull images
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreamimports").RuleOrDie(),
authorizationapi.NewRule("get", "patch", "update", "delete").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(quotaGroup, legacyQuotaGroup).Resources("appliedclusterresourcequotas").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(routeGroup, legacyRouteGroup).Resources("routes").RuleOrDie(),
// admins can create routes with custom hosts
authorizationapi.NewRule("create").Groups(routeGroup, legacyRouteGroup).Resources("routes/custom-host").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
// an admin can run routers that write back conditions to the route
authorizationapi.NewRule("update").Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(templateGroup, legacyTemplateGroup).Resources("templates", "templateconfigs", "processedtemplates", "templateinstances").RuleOrDie(),
// backwards compatibility
authorizationapi.NewRule(readWrite...).Groups(buildGroup, legacyBuildGroup).Resources("buildlogs").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("resourcequotausages").RuleOrDie(),
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("resourceaccessreviews", "subjectaccessreviews").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: EditRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user that can create and edit most objects in a project, but can not update the project's membership.",
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("pods", "pods/attach", "pods/proxy", "pods/exec", "pods/portforward").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("replicationcontrollers", "replicationcontrollers/scale", "serviceaccounts",
"services", "services/proxy", "endpoints", "persistentvolumeclaims", "configmaps", "secrets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("limitranges", "resourcequotas", "bindings", "events",
"namespaces", "pods/status", "resourcequotas/status", "namespaces/status", "replicationcontrollers/status", "pods/log").RuleOrDie(),
authorizationapi.NewRule("impersonate").Groups(kapiGroup).Resources("serviceaccounts").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(autoscalingGroup).Resources("horizontalpodautoscalers").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(batchGroup).Resources("jobs", "scheduledjobs", "cronjobs").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(extensionsGroup).Resources("jobs", "horizontalpodautoscalers", "replicationcontrollers/scale",
"replicasets", "replicasets/scale", "deployments", "deployments/scale", "deployments/rollback").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("daemonsets").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(appsGroup).Resources("statefulsets", "deployments", "deployments/scale", "deployments/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(buildGroup, legacyBuildGroup).Resources("builds", "buildconfigs", "buildconfigs/webhooks").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("builds/log").RuleOrDie(),
authorizationapi.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs/instantiate", "buildconfigs/instantiatebinary", "builds/clone").RuleOrDie(),
authorizationapi.NewRule("update").Groups(buildGroup, legacyBuildGroup).Resources("builds/details").RuleOrDie(),
// access to jenkins. multiple values to ensure that covers relationships
authorizationapi.NewRule("edit", "view").Groups(buildapi.GroupName).Resources("jenkins").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs", "generatedeploymentconfigs", "deploymentconfigs/scale").RuleOrDie(),
authorizationapi.NewRule("create").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigrollbacks", "deploymentconfigs/rollback", "deploymentconfigs/instantiate").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs/log", "deploymentconfigs/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams", "imagestreammappings", "imagestreamtags", "imagestreamimages", "imagestreams/secrets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams/status").RuleOrDie(),
// push and pull images
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreamimports").RuleOrDie(),
authorizationapi.NewRule("get").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(quotaGroup, legacyQuotaGroup).Resources("appliedclusterresourcequotas").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(routeGroup, legacyRouteGroup).Resources("routes").RuleOrDie(),
// editors can create routes with custom hosts
authorizationapi.NewRule("create").Groups(routeGroup, legacyRouteGroup).Resources("routes/custom-host").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(templateGroup, legacyTemplateGroup).Resources("templates", "templateconfigs", "processedtemplates", "templateinstances").RuleOrDie(),
// backwards compatibility
authorizationapi.NewRule(readWrite...).Groups(buildGroup, legacyBuildGroup).Resources("buildlogs").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("resourcequotausages").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ViewRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user who can view but not edit any resources within the project. They can not view secrets or membership.",
},
},
Rules: []authorizationapi.PolicyRule{
// TODO add "replicationcontrollers/scale" here
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("pods", "replicationcontrollers", "serviceaccounts",
"services", "endpoints", "persistentvolumeclaims", "configmaps").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("limitranges", "resourcequotas", "bindings", "events",
"namespaces", "pods/status", "resourcequotas/status", "namespaces/status", "replicationcontrollers/status", "pods/log").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(autoscalingGroup).Resources("horizontalpodautoscalers").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(batchGroup).Resources("jobs", "scheduledjobs", "cronjobs").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("jobs", "horizontalpodautoscalers", "replicasets", "replicasets/scale",
"deployments", "deployments/scale").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("daemonsets").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(appsGroup).Resources("statefulsets", "deployments", "deployments/scale").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("builds", "buildconfigs", "buildconfigs/webhooks").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("builds/log").RuleOrDie(),
// access to jenkins
authorizationapi.NewRule("view").Groups(buildapi.GroupName).Resources("jenkins").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs", "deploymentconfigs/scale").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs/log", "deploymentconfigs/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams", "imagestreammappings", "imagestreamtags", "imagestreamimages").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreams/status").RuleOrDie(),
// TODO let them pull images?
// pull images
// authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("get").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(quotaGroup, legacyQuotaGroup).Resources("appliedclusterresourcequotas").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(routeGroup, legacyRouteGroup).Resources("routes").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(templateGroup, legacyTemplateGroup).Resources("templates", "templateconfigs", "processedtemplates", "templateinstances").RuleOrDie(),
// backwards compatibility
authorizationapi.NewRule(read...).Groups(buildGroup, legacyBuildGroup).Resources("buildlogs").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("resourcequotausages").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: BasicUserRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user that can get basic information about projects.",
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get").Groups(userGroup, legacyUserGroup).Resources("users").Names("~").RuleOrDie(),
authorizationapi.NewRule("list").Groups(projectGroup, legacyProjectGroup).Resources("projectrequests").RuleOrDie(),
authorizationapi.NewRule("get", "list").Groups(authzGroup, legacyAuthzGroup).Resources("clusterroles").RuleOrDie(),
authorizationapi.NewRule("get", "list").Groups(storageGroup).Resources("storageclasses").RuleOrDie(),
authorizationapi.NewRule("list", "watch").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("selfsubjectrulesreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("selfsubjectaccessreviews").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: SelfAccessReviewerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("selfsubjectrulesreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("selfsubjectaccessreviews").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: SelfProvisionerRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user that can request projects.",
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("create").Groups(projectGroup, legacyProjectGroup).Resources("projectrequests").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: StatusCheckerRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "A user that can get basic cluster status information.",
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
{
Verbs: sets.NewString("get"),
NonResourceURLs: sets.NewString(
// Health
"/healthz", "/healthz/*",
),
},
authorizationapi.DiscoveryRule,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ImageAuditorRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get", "list", "watch", "patch", "update").Groups(imageGroup, legacyImageGroup).Resources("images").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ImagePullerRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "Grants the right to pull images from within a project.",
},
},
Rules: []authorizationapi.PolicyRule{
// pull images
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
},
},
{
// This role looks like a duplicate of ImageBuilderRole, but the ImageBuilder role is specifically for our builder service accounts
// if we found another permission needed by them, we'd add it there so the intent is different if you used the ImageBuilderRole
// you could end up accidentally granting more permissions than you intended. This is intended to only grant enough powers to
// push an image to our registry
ObjectMeta: metav1.ObjectMeta{
Name: ImagePusherRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "Grants the right to push and pull images from within a project.",
},
},
Rules: []authorizationapi.PolicyRule{
// push and pull images
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ImageBuilderRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "Grants the right to build, push and pull images from within a project. Used primarily with service accounts for builds.",
},
},
Rules: []authorizationapi.PolicyRule{
// push and pull images
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
// allow auto-provisioning when pushing an image that doesn't have an imagestream yet
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreams").RuleOrDie(),
authorizationapi.NewRule("update").Groups(buildGroup, legacyBuildGroup).Resources("builds/details").RuleOrDie(),
authorizationapi.NewRule("get").Groups(buildGroup, legacyBuildGroup).Resources("builds").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ImagePrunerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get", "list").Groups(kapiGroup).Resources("pods", "replicationcontrollers").RuleOrDie(),
authorizationapi.NewRule("list").Groups(kapiGroup).Resources("limitranges").RuleOrDie(),
authorizationapi.NewRule("get", "list").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs", "builds").RuleOrDie(),
authorizationapi.NewRule("get", "list").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs").RuleOrDie(),
authorizationapi.NewRule("delete").Groups(imageGroup, legacyImageGroup).Resources("images").RuleOrDie(),
authorizationapi.NewRule("get", "list").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreams").RuleOrDie(),
authorizationapi.NewRule("update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/status").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: ImageSignerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("create", "delete").Groups(imageGroup, legacyImageGroup).Resources("imagesignatures").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: DeployerRoleName,
Annotations: map[string]string{
oapi.OpenShiftDescription: "Grants the right to deploy within a project. Used primarily with service accounts for automated deployments.",
},
},
Rules: []authorizationapi.PolicyRule{
// "delete" is required here for compatibility with older deployer images
// (see https://github.com/openshift/origin/pull/14322#issuecomment-303968976)
// TODO: remove "delete" rule few releases after 3.6
authorizationapi.NewRule("delete").Groups(kapiGroup).Resources("replicationcontrollers").RuleOrDie(),
authorizationapi.NewRule("get", "list", "watch", "update").Groups(kapiGroup).Resources("replicationcontrollers").RuleOrDie(),
authorizationapi.NewRule("get", "list", "watch", "create").Groups(kapiGroup).Resources("pods").RuleOrDie(),
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("pods/log").RuleOrDie(),
authorizationapi.NewRule("create", "list").Groups(kapiGroup).Resources("events").RuleOrDie(),
authorizationapi.NewRule("update").Groups(imageGroup, legacyImageGroup).Resources("imagestreamtags").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: MasterRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("*").Groups("*").Resources("*").RuleOrDie(),
{
Verbs: sets.NewString(authorizationapi.VerbAll),
NonResourceURLs: sets.NewString(authorizationapi.NonResourceAll),
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: OAuthTokenDeleterRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("delete").Groups(oauthGroup, legacyOauthGroup).Resources("oauthaccesstokens", "oauthauthorizetokens").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: RouterRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("list", "watch").Groups(kapiGroup).Resources("endpoints").RuleOrDie(),
authorizationapi.NewRule("list", "watch").Groups(kapiGroup).Resources("services").RuleOrDie(),
authorizationapi.NewRule("list", "watch").Groups(routeGroup, legacyRouteGroup).Resources("routes").RuleOrDie(),
authorizationapi.NewRule("update").Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: RegistryRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("list").Groups(kapiGroup).Resources("limitranges", "resourcequotas").RuleOrDie(),
authorizationapi.NewRule("get", "delete").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreamtags").RuleOrDie(),
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreamimages", "imagestreams/secrets").RuleOrDie(),
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreams").RuleOrDie(),
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreammappings").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: NodeProxierRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
// Used to build serviceLister
authorizationapi.NewRule("list", "watch").Groups(kapiGroup).Resources("services", "endpoints").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: NodeAdminRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
// Allow read-only access to the API objects
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("nodes").RuleOrDie(),
// Allow all API calls to the nodes
authorizationapi.NewRule("proxy").Groups(kapiGroup).Resources("nodes").RuleOrDie(),
authorizationapi.NewRule("*").Groups(kapiGroup).Resources("nodes/proxy", "nodes/"+authorizationapi.NodeMetricsSubresource, "nodes/"+authorizationapi.NodeSpecSubresource, "nodes/"+authorizationapi.NodeStatsSubresource, "nodes/"+authorizationapi.NodeLogSubresource).RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: NodeReaderRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
// Allow read-only access to the API objects
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("nodes").RuleOrDie(),
// Allow read access to node metrics
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("nodes/"+authorizationapi.NodeMetricsSubresource, "nodes/"+authorizationapi.NodeSpecSubresource).RuleOrDie(),
// Allow read access to stats
// Node stats requests are submitted as POSTs. These creates are non-mutating
authorizationapi.NewRule("get", "create").Groups(kapiGroup).Resources("nodes/" + authorizationapi.NodeStatsSubresource).RuleOrDie(),
// TODO: expose other things like /healthz on the node once we figure out non-resource URL policy across systems
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: NodeRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
// Needed to check API access. These creates are non-mutating
authorizationapi.NewRule("create").Groups(kAuthnGroup).Resources("tokenreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("subjectaccessreviews", "localsubjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("subjectaccessreviews", "localsubjectaccessreviews").RuleOrDie(),
// Needed to build serviceLister, to populate env vars for services
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("services").RuleOrDie(),
// Nodes can register themselves
// TODO: restrict to creating a node with the same name they announce
authorizationapi.NewRule("create", "get", "list", "watch").Groups(kapiGroup).Resources("nodes").RuleOrDie(),
// TODO: restrict to the bound node once supported
authorizationapi.NewRule("update", "patch").Groups(kapiGroup).Resources("nodes/status").RuleOrDie(),
// TODO: restrict to the bound node as creator once supported
authorizationapi.NewRule("create", "update", "patch").Groups(kapiGroup).Resources("events").RuleOrDie(),
// TODO: restrict to pods scheduled on the bound node once supported
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("pods").RuleOrDie(),
// TODO: remove once mirror pods are removed
// TODO: restrict deletion to mirror pods created by the bound node once supported
// Needed for the node to create/delete mirror pods
authorizationapi.NewRule("get", "create", "delete").Groups(kapiGroup).Resources("pods").RuleOrDie(),
// TODO: restrict to pods scheduled on the bound node once supported
authorizationapi.NewRule("update").Groups(kapiGroup).Resources("pods/status").RuleOrDie(),
// TODO: restrict to secrets and configmaps used by pods scheduled on bound node once supported
// Needed for imagepullsecrets, rbd/ceph and secret volumes, and secrets in envs
// Needed for configmap volume and envs
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("secrets", "configmaps").RuleOrDie(),
// TODO: restrict to claims/volumes used by pods scheduled on bound node once supported
// Needed for persistent volumes
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("persistentvolumeclaims", "persistentvolumes").RuleOrDie(),
// TODO: restrict to namespaces of pods scheduled on bound node once supported
// TODO: change glusterfs to use DNS lookup so this isn't needed?
// Needed for glusterfs volumes
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("endpoints").RuleOrDie(),
// Nodes are allowed to request CSRs (specifically, request serving certs)
authorizationapi.NewRule("get", "create").Groups(certificates.GroupName).Resources("certificatesigningrequests").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: SDNReaderRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(read...).Groups(networkGroup, legacyNetworkGroup).Resources("egressnetworkpolicies", "hostsubnets", "netnamespaces").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("nodes", "namespaces").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(extensionsGroup).Resources("networkpolicies").RuleOrDie(),
authorizationapi.NewRule("get").Groups(networkGroup, legacyNetworkGroup).Resources("clusternetworks").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: SDNManagerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get", "list", "watch", "create", "delete").Groups(networkGroup, legacyNetworkGroup).Resources("hostsubnets", "netnamespaces").RuleOrDie(),
authorizationapi.NewRule("get", "create").Groups(networkGroup, legacyNetworkGroup).Resources("clusternetworks").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(kapiGroup).Resources("nodes").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: WebHooksRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get", "create").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs/webhooks").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: DiscoveryRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.DiscoveryRule,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: PersistentVolumeProvisionerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule("get", "list", "watch", "create", "delete").Groups(kapiGroup).Resources("persistentvolumes").RuleOrDie(),
// update is needed in addition to read access for setting lock annotations on PVCs
authorizationapi.NewRule("get", "list", "watch", "update").Groups(kapiGroup).Resources("persistentvolumeclaims").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(storageGroup).Resources("storageclasses").RuleOrDie(),
// Needed for watching provisioning success and failure events
authorizationapi.NewRule("create", "update", "patch", "list", "watch").Groups(kapiGroup).Resources("events").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: RegistryAdminRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("serviceaccounts", "secrets").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(imageGroup, legacyImageGroup).Resources("imagestreamimages", "imagestreammappings", "imagestreams", "imagestreams/secrets", "imagestreamtags").RuleOrDie(),
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreamimports").RuleOrDie(),
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(authzGroup, legacyAuthzGroup).Resources("rolebindings", "roles").RuleOrDie(),
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("localresourceaccessreviews", "localsubjectaccessreviews", "subjectrulesreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups(kAuthzGroup).Resources("localsubjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule(read...).Groups(authzGroup, legacyAuthzGroup).Resources("policies", "policybindings").RuleOrDie(),
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("namespaces").RuleOrDie(),
authorizationapi.NewRule("get", "delete").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
// backwards compatibility
authorizationapi.NewRule("create").Groups(authzGroup, legacyAuthzGroup).Resources("resourceaccessreviews", "subjectaccessreviews").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: RegistryEditorRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(readWrite...).Groups(kapiGroup).Resources("serviceaccounts", "secrets").RuleOrDie(),
authorizationapi.NewRule(readWrite...).Groups(imageGroup, legacyImageGroup).Resources("imagestreamimages", "imagestreammappings", "imagestreams", "imagestreams/secrets", "imagestreamtags").RuleOrDie(),
authorizationapi.NewRule("create").Groups(imageGroup, legacyImageGroup).Resources("imagestreamimports").RuleOrDie(),
authorizationapi.NewRule("get", "update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("namespaces").RuleOrDie(),
authorizationapi.NewRule("get").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: RegistryViewerRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
authorizationapi.NewRule(read...).Groups(imageGroup, legacyImageGroup).Resources("imagestreamimages", "imagestreammappings", "imagestreams", "imagestreamtags").RuleOrDie(),
authorizationapi.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/layers").RuleOrDie(),
authorizationapi.NewRule("get").Groups(kapiGroup).Resources("namespaces").RuleOrDie(),
authorizationapi.NewRule("get").Groups(projectGroup, legacyProjectGroup).Resources("projects").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: TemplateServiceBrokerClientRoleName,
Annotations: map[string]string{
roleSystemOnly: roleIsSystemOnly,
},
},
Rules: []authorizationapi.PolicyRule{
{
Verbs: sets.NewString("get", "put", "update", "delete"),
NonResourceURLs: sets.NewString(templateapi.ServiceBrokerRoot + "/*"),
},
},
},
}
// TODO check if we really need to do this
// we don't want to expose the resourcegroups externally because it makes it very difficult for customers to learn from
// our default roles and hard for them to reason about what power they are granting their users
for i := range roles {
for j := range roles[i].Rules {
roles[i].Rules[j].Resources = authorizationapi.NormalizeResources(roles[i].Rules[j].Resources)
}
}
return roles
}
func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
openshiftClusterRoles := GetOpenshiftBootstrapClusterRoles()
// dead cluster roles need to be checked for conflicts (in case something new comes up)
// so add them to this list.
openshiftClusterRoles = append(openshiftClusterRoles, GetDeadClusterRoles()...)
openshiftSAClusterRoles := InfraSAs.AllRoles()
kubeClusterRoles, err := GetKubeBootstrapClusterRoles()
// coder error
if err != nil {
panic(err)
}
kubeSAClusterRoles, err := GetKubeControllerBootstrapClusterRoles()
// coder error
if err != nil {
panic(err)
}
openshiftControllerRoles, err := GetOpenshiftControllerBootstrapClusterRoles()
// coder error
if err != nil {
panic(err)
}
// Eventually openshift controllers and kube controllers have different prefixes
// so we will only need to check conflicts on the "normal" cluster roles
// for now, deconflict with all names
openshiftClusterRoleNames := sets.NewString()
kubeClusterRoleNames := sets.NewString()
for _, clusterRole := range openshiftClusterRoles {
openshiftClusterRoleNames.Insert(clusterRole.Name)
}
for _, clusterRole := range openshiftSAClusterRoles {
openshiftClusterRoleNames.Insert(clusterRole.Name)
}
for _, clusterRole := range kubeClusterRoles {
kubeClusterRoleNames.Insert(clusterRole.Name)
}
conflictingNames := kubeClusterRoleNames.Intersection(openshiftClusterRoleNames)
extraRBACConflicts := conflictingNames.Difference(clusterRoleConflicts)
extraWhitelistEntries := clusterRoleConflicts.Difference(conflictingNames)
switch {
case len(extraRBACConflicts) > 0 && len(extraWhitelistEntries) > 0:
panic(fmt.Sprintf("kube ClusterRoles conflict with openshift ClusterRoles: %v and ClusterRole whitelist contains a extraneous entries: %v ", extraRBACConflicts.List(), extraWhitelistEntries.List()))
case len(extraRBACConflicts) > 0:
panic(fmt.Sprintf("kube ClusterRoles conflict with openshift ClusterRoles: %v", extraRBACConflicts.List()))
case len(extraWhitelistEntries) > 0:
panic(fmt.Sprintf("ClusterRole whitelist contains a extraneous entries: %v", extraWhitelistEntries.List()))