Skip to content

Commit 5d7f483

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 3231b87 commit 5d7f483

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
@@ -759,6 +759,20 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
759759
Name: "system:router",
760760
},
761761
},
762+
&authapi.ClusterRoleBinding{
763+
ObjectMeta: metav1.ObjectMeta{Name: generateAuthRoleBindingName(cfg.Name)},
764+
Subjects: []kapi.ObjectReference{
765+
{
766+
Kind: "ServiceAccount",
767+
Name: cfg.ServiceAccount,
768+
Namespace: namespace,
769+
},
770+
},
771+
RoleRef: kapi.ObjectReference{
772+
Kind: "ClusterRole",
773+
Name: "system:auth-delegator",
774+
},
775+
},
762776
)
763777

764778
objects = append(objects, &appsapi.DeploymentConfig{
@@ -833,7 +847,7 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
833847

834848
levelPrefixFilter := func(e error) string {
835849
// Avoid failing when service accounts or role bindings already exist.
836-
if ignoreError(e, cfg.ServiceAccount, generateRoleBindingName(cfg.Name)) {
850+
if ignoreError(e, cfg.ServiceAccount, generateRoleBindingName(cfg.Name), generateAuthRoleBindingName(cfg.Name)) {
837851
return "warning"
838852
}
839853
return "error"
@@ -850,9 +864,9 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
850864
}
851865

852866
// ignoreError will return true if the error is an already exists status error and
853-
// 1. it is for a cluster role binding named roleBindingName, or
854-
// 2. it is for a service account name saName
855-
func ignoreError(e error, saName string, roleBindingName string) bool {
867+
// 1. it is for a cluster role binding matching in roleBindingNames, or
868+
// 2. it is for a service account named saName
869+
func ignoreError(e error, saName string, roleBindingNames ...string) bool {
856870
if !errors.IsAlreadyExists(e) {
857871
return false
858872
}
@@ -864,9 +878,17 @@ func ignoreError(e error, saName string, roleBindingName string) bool {
864878
if details == nil {
865879
return false
866880
}
867-
return (details.Kind == "serviceaccounts" && details.Name == saName) ||
868-
(details.Kind == "clusterrolebinding" /*pre-3.7*/ && details.Name == roleBindingName) ||
869-
(details.Kind == "clusterrolebindings" /*3.7+*/ && details.Name == roleBindingName)
881+
if details.Kind == "serviceaccounts" {
882+
return details.Name == saName
883+
}
884+
if details.Kind == "clusterrolebinding" /*pre-3.7*/ || details.Kind == "clusterrolebindings" /*3.7+*/ {
885+
for _, name := range roleBindingNames {
886+
if details.Name == name {
887+
return true
888+
}
889+
}
890+
}
891+
return false
870892
}
871893

872894
// generateRoleBindingName generates a name for the rolebinding object if it is
@@ -875,6 +897,10 @@ func generateRoleBindingName(name string) string {
875897
return fmt.Sprintf("router-%s-role", name)
876898
}
877899

900+
func generateAuthRoleBindingName(name string) string {
901+
return fmt.Sprintf("router-%s-auth-role", name)
902+
}
903+
878904
// generateStatsPassword creates a random password.
879905
func generateStatsPassword() string {
880906
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)