Skip to content

Commit 61d68da

Browse files
committed
router: assign system:auth-delegator role
Instead of adding more rules to the system:router role, this change reuses the existing system:auth-delegator role.
1 parent 6a90871 commit 61d68da

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

pkg/cmd/server/bootstrappolicy/policy.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,6 @@ func GetOpenshiftBootstrapClusterRoles() []rbac.ClusterRole {
564564
rbac.NewRule("list", "watch").Groups(kapiGroup).Resources("endpoints").RuleOrDie(),
565565
rbac.NewRule("list", "watch").Groups(kapiGroup).Resources("services").RuleOrDie(),
566566

567-
rbac.NewRule("create").Groups(kAuthnGroup).Resources("tokenreviews").RuleOrDie(),
568-
rbac.NewRule("create").Groups(kAuthzGroup).Resources("subjectaccessreviews").RuleOrDie(),
569-
570567
rbac.NewRule("list", "watch").Groups(routeGroup, legacyRouteGroup).Resources("routes").RuleOrDie(),
571568
rbac.NewRule("update").Groups(routeGroup, legacyRouteGroup).Resources("routes/status").RuleOrDie(),
572569
},

pkg/oc/admin/router/router.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,20 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
755755
Name: "system:router",
756756
},
757757
},
758+
&authapi.ClusterRoleBinding{
759+
ObjectMeta: metav1.ObjectMeta{Name: generateAuthRoleBindingName(cfg.Name)},
760+
Subjects: []kapi.ObjectReference{
761+
{
762+
Kind: "ServiceAccount",
763+
Name: cfg.ServiceAccount,
764+
Namespace: namespace,
765+
},
766+
},
767+
RoleRef: kapi.ObjectReference{
768+
Kind: "ClusterRole",
769+
Name: "system:auth-delegator",
770+
},
771+
},
758772
)
759773

760774
objects = append(objects, &appsapi.DeploymentConfig{
@@ -829,7 +843,7 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
829843

830844
levelPrefixFilter := func(e error) string {
831845
// Avoid failing when service accounts or role bindings already exist.
832-
if ignoreError(e, cfg.ServiceAccount, generateRoleBindingName(cfg.Name)) {
846+
if ignoreError(e, cfg.ServiceAccount, generateRoleBindingName(cfg.Name), generateAuthRoleBindingName(cfg.Name)) {
833847
return "warning"
834848
}
835849
return "error"
@@ -846,9 +860,9 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
846860
}
847861

848862
// ignoreError will return true if the error is an already exists status error and
849-
// 1. it is for a cluster role binding named roleBindingName, or
850-
// 2. it is for a service account name saName
851-
func ignoreError(e error, saName string, roleBindingName string) bool {
863+
// 1. it is for a cluster role binding matching in roleBindingNames, or
864+
// 2. it is for a service account named saName
865+
func ignoreError(e error, saName string, roleBindingNames ...string) bool {
852866
if !errors.IsAlreadyExists(e) {
853867
return false
854868
}
@@ -860,9 +874,17 @@ func ignoreError(e error, saName string, roleBindingName string) bool {
860874
if details == nil {
861875
return false
862876
}
863-
return (details.Kind == "serviceaccounts" && details.Name == saName) ||
864-
(details.Kind == "clusterrolebinding" /*pre-3.7*/ && details.Name == roleBindingName) ||
865-
(details.Kind == "clusterrolebindings" /*3.7+*/ && details.Name == roleBindingName)
877+
if details.Kind == "serviceaccounts" {
878+
return details.Name == saName
879+
}
880+
if details.Kind == "clusterrolebinding" /*pre-3.7*/ || details.Kind == "clusterrolebindings" /*3.7+*/ {
881+
for _, name := range roleBindingNames {
882+
if details.Name == name {
883+
return true
884+
}
885+
}
886+
}
887+
return false
866888
}
867889

868890
// generateRoleBindingName generates a name for the rolebinding object if it is
@@ -871,6 +893,10 @@ func generateRoleBindingName(name string) string {
871893
return fmt.Sprintf("router-%s-role", name)
872894
}
873895

896+
func generateAuthRoleBindingName(name string) string {
897+
return fmt.Sprintf("router-%s-auth-role", name)
898+
}
899+
874900
// generateStatsPassword creates a random password.
875901
func generateStatsPassword() string {
876902
rand := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))

test/testdata/bootstrappolicy/bootstrap_cluster_roles.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,18 +1764,6 @@ items:
17641764
verbs:
17651765
- list
17661766
- watch
1767-
- apiGroups:
1768-
- authentication.k8s.io
1769-
resources:
1770-
- tokenreviews
1771-
verbs:
1772-
- create
1773-
- apiGroups:
1774-
- authorization.k8s.io
1775-
resources:
1776-
- subjectaccessreviews
1777-
verbs:
1778-
- create
17791767
- apiGroups:
17801768
- ""
17811769
- route.openshift.io

test/testdata/bootstrappolicy/bootstrap_policy_file.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,20 +1934,6 @@ items:
19341934
verbs:
19351935
- list
19361936
- watch
1937-
- apiGroups:
1938-
- authentication.k8s.io
1939-
attributeRestrictions: null
1940-
resources:
1941-
- tokenreviews
1942-
verbs:
1943-
- create
1944-
- apiGroups:
1945-
- authorization.k8s.io
1946-
attributeRestrictions: null
1947-
resources:
1948-
- subjectaccessreviews
1949-
verbs:
1950-
- create
19511937
- apiGroups:
19521938
- ""
19531939
- route.openshift.io

0 commit comments

Comments
 (0)