Skip to content

Commit 7a48deb

Browse files
authored
Merge pull request #15364 from deads2k/auth-22-fix-controller
remove old controller roles
2 parents ded9a03 + 67e8491 commit 7a48deb

File tree

8 files changed

+176
-325
lines changed

8 files changed

+176
-325
lines changed

pkg/cmd/server/bootstrappolicy/controller_policy.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,47 @@ import (
99
rbac "k8s.io/kubernetes/pkg/apis/rbac"
1010

1111
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
12+
13+
// we need the conversions registered for our init block
14+
_ "github.com/openshift/origin/pkg/authorization/apis/authorization/install"
1215
)
1316

1417
const saRolePrefix = "system:openshift:controller:"
1518

19+
const (
20+
InfraOriginNamespaceServiceAccountName = "origin-namespace-controller"
21+
InfraServiceAccountControllerServiceAccountName = "serviceaccount-controller"
22+
InfraServiceAccountPullSecretsControllerServiceAccountName = "serviceaccount-pull-secrets-controller"
23+
InfraServiceAccountTokensControllerServiceAccountName = "serviceaccount-tokens-controller"
24+
InfraServiceServingCertServiceAccountName = "service-serving-cert-controller"
25+
InfraBuildControllerServiceAccountName = "build-controller"
26+
InfraBuildConfigChangeControllerServiceAccountName = "build-config-change-controller"
27+
InfraDeploymentConfigControllerServiceAccountName = "deploymentconfig-controller"
28+
InfraDeploymentTriggerControllerServiceAccountName = "deployment-trigger-controller"
29+
InfraDeployerControllerServiceAccountName = "deployer-controller"
30+
InfraImageTriggerControllerServiceAccountName = "image-trigger-controller"
31+
InfraImageImportControllerServiceAccountName = "image-import-controller"
32+
InfraSDNControllerServiceAccountName = "sdn-controller"
33+
InfraClusterQuotaReconciliationControllerServiceAccountName = "cluster-quota-reconciliation-controller"
34+
InfraUnidlingControllerServiceAccountName = "unidling-controller"
35+
InfraServiceIngressIPControllerServiceAccountName = "service-ingress-ip-controller"
36+
InfraPersistentVolumeRecyclerControllerServiceAccountName = "pv-recycler-controller"
37+
InfraResourceQuotaControllerServiceAccountName = "resourcequota-controller"
38+
39+
// template instance controller watches for TemplateInstance object creation
40+
// and instantiates templates as a result.
41+
InfraTemplateInstanceControllerServiceAccountName = "template-instance-controller"
42+
43+
// template service broker is an open service broker-compliant API
44+
// implementation which serves up OpenShift templates. It uses the
45+
// TemplateInstance backend for most of the heavy lifting.
46+
InfraTemplateServiceBrokerServiceAccountName = "template-service-broker"
47+
48+
// This is a special constant which maps to the service account name used by the underlying
49+
// Kubernetes code, so that we can build out the extra policy required to scale OpenShift resources.
50+
InfraHorizontalPodAutoscalerControllerServiceAccountName = "horizontal-pod-autoscaler"
51+
)
52+
1653
var (
1754
// controllerRoles is a slice of roles used for controllers
1855
controllerRoles = []rbac.ClusterRole{}
@@ -296,6 +333,19 @@ func init() {
296333
},
297334
})
298335

336+
addControllerRole(rbac.ClusterRole{
337+
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraTemplateServiceBrokerServiceAccountName},
338+
Rules: []rbac.PolicyRule{
339+
rbac.NewRule("create").Groups(kAuthzGroup).Resources("subjectaccessreviews").RuleOrDie(),
340+
rbac.NewRule("create").Groups(authzGroup).Resources("subjectaccessreviews").RuleOrDie(),
341+
rbac.NewRule("get", "create", "update", "delete").Groups(templateGroup).Resources("brokertemplateinstances").RuleOrDie(),
342+
rbac.NewRule("get", "create", "delete", "assign").Groups(templateGroup).Resources("templateinstances").RuleOrDie(),
343+
rbac.NewRule("get", "list", "create", "delete").Groups(kapiGroup).Resources("secrets").RuleOrDie(),
344+
rbac.NewRule("list").Groups(kapiGroup).Resources("services", "configmaps").RuleOrDie(),
345+
rbac.NewRule("list").Groups(routeGroup).Resources("routes").RuleOrDie(),
346+
eventsRule(),
347+
},
348+
})
299349
}
300350

301351
// ControllerRoles returns the cluster roles used by controllers

pkg/cmd/server/bootstrappolicy/dead.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ func init() {
5656
addDeadClusterRole("system:build-controller")
5757
addDeadClusterRole("system:deploymentconfig-controller")
5858
addDeadClusterRole("system:deployment-controller")
59-
6059
}

pkg/cmd/server/bootstrappolicy/infra_sa_policy.go

Lines changed: 0 additions & 205 deletions
This file was deleted.

pkg/cmd/server/bootstrappolicy/policy.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
959959
// dead cluster roles need to be checked for conflicts (in case something new comes up)
960960
// so add them to this list.
961961
openshiftClusterRoles = append(openshiftClusterRoles, GetDeadClusterRoles()...)
962-
openshiftSAClusterRoles := InfraSAs.AllRoles()
963962
kubeClusterRoles, err := GetKubeBootstrapClusterRoles()
964963
// coder error
965964
if err != nil {
@@ -984,9 +983,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
984983
for _, clusterRole := range openshiftClusterRoles {
985984
openshiftClusterRoleNames.Insert(clusterRole.Name)
986985
}
987-
for _, clusterRole := range openshiftSAClusterRoles {
988-
openshiftClusterRoleNames.Insert(clusterRole.Name)
989-
}
990986
for _, clusterRole := range kubeClusterRoles {
991987
kubeClusterRoleNames.Insert(clusterRole.Name)
992988
}
@@ -1005,7 +1001,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
10051001

10061002
finalClusterRoles := []authorizationapi.ClusterRole{}
10071003
finalClusterRoles = append(finalClusterRoles, openshiftClusterRoles...)
1008-
finalClusterRoles = append(finalClusterRoles, openshiftSAClusterRoles...)
10091004
finalClusterRoles = append(finalClusterRoles, openshiftControllerRoles...)
10101005
finalClusterRoles = append(finalClusterRoles, kubeSAClusterRoles...)
10111006
for i := range kubeClusterRoles {
@@ -1264,9 +1259,6 @@ var clusterRoleConflicts = sets.NewString(
12641259
// TODO this should probably be re-swizzled to be the delta on top of the kube role
12651260
"system:discovery",
12661261

1267-
// TODO deconflict this
1268-
"system:node-bootstrapper",
1269-
12701262
// TODO these should be reconsidered
12711263
"cluster-admin",
12721264
"system:node",

pkg/cmd/server/bootstrappolicy/web_console_role_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ var rolesToHide = sets.NewString(
4646
"system:node-proxier",
4747
"system:node-reader",
4848
"system:oauth-token-deleter",
49-
"system:openshift:template-service-broker",
5049
"system:openshift:templateservicebroker-client",
5150
"system:persistent-volume-provisioner",
5251
"system:registry",
@@ -75,15 +74,11 @@ func TestSystemOnlyRoles(t *testing.T) {
7574
}
7675

7776
if !show.Equal(rolesToShow) || !hide.Equal(rolesToHide) {
78-
shouldNotShow := show.Difference(rolesToShow).List()
79-
shouldNotHide := hide.Difference(rolesToHide).List()
8077
t.Error("The list of expected end user roles has been changed. Please discuss with the web console team to update role annotations.")
81-
if len(shouldNotShow) > 0 {
82-
t.Errorf("These roles are visible but not in rolesToShow: %v", shouldNotShow)
83-
}
84-
if len(shouldNotHide) > 0 {
85-
t.Errorf("These roles are hidden but not in rolesToHide: %v", shouldNotHide)
86-
}
78+
t.Logf("These roles are visible but not in rolesToShow: %v", show.Difference(rolesToShow).List())
79+
t.Logf("These roles are hidden but not in rolesToHide: %v", hide.Difference(rolesToHide).List())
80+
t.Logf("These roles are in rolesToShow but are missing from the visible list: %v", rolesToShow.Difference(show).List())
81+
t.Logf("These roles are in rolesToHide but are missing from the hidden list: %v", rolesToHide.Difference(hide).List())
8782
}
8883
}
8984

pkg/cmd/server/origin/ensure.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {
5454
return
5555
}
5656

57-
roleAccessor := policy.NewClusterRoleBindingAccessor(c.ServiceAccountRoleBindingClient())
58-
for _, saName := range bootstrappolicy.InfraSAs.GetServiceAccounts() {
59-
_, err := c.KubeClientsetInternal().Core().ServiceAccounts(ns).Create(&kapi.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: saName}})
60-
if err != nil && !kapierror.IsAlreadyExists(err) {
61-
glog.Errorf("Error creating service account %s/%s: %v", ns, saName, err)
62-
}
63-
64-
role, _ := bootstrappolicy.InfraSAs.RoleFor(saName)
65-
57+
for _, role := range bootstrappolicy.ControllerRoles() {
6658
reconcileRole := &policy.ReconcileClusterRolesOptions{
6759
RolesToReconcile: []string{role.Name},
6860
Confirmed: true,
@@ -73,16 +65,17 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {
7365
if err := reconcileRole.RunReconcileClusterRoles(nil, nil); err != nil {
7466
glog.Errorf("Could not reconcile %v: %v\n", role.Name, err)
7567
}
76-
77-
addRole := &policy.RoleModificationOptions{
78-
RoleName: role.Name,
79-
RoleBindingAccessor: roleAccessor,
80-
Subjects: []kapi.ObjectReference{{Namespace: ns, Name: saName, Kind: "ServiceAccount"}},
68+
}
69+
for _, roleBinding := range bootstrappolicy.ControllerRoleBindings() {
70+
reconcileRoleBinding := &policy.ReconcileClusterRoleBindingsOptions{
71+
RolesToReconcile: []string{roleBinding.RoleRef.Name},
72+
Confirmed: true,
73+
Union: true,
74+
Out: ioutil.Discard,
75+
RoleBindingClient: c.PrivilegedLoopbackOpenShiftClient.ClusterRoleBindings(),
8176
}
82-
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error { return addRole.AddRole() }); err != nil {
83-
glog.Errorf("Could not add %v service accounts to the %v cluster role: %v\n", saName, role.Name, err)
84-
} else {
85-
glog.V(2).Infof("Added %v service accounts to the %v cluster role: %v\n", saName, role.Name, err)
77+
if err := reconcileRoleBinding.RunReconcileClusterRoleBindings(nil, nil); err != nil {
78+
glog.Errorf("Could not reconcile %v: %v\n", roleBinding.Name, err)
8679
}
8780
}
8881

0 commit comments

Comments
 (0)