Skip to content

Commit

Permalink
remove old controller SA registration
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jul 20, 2017
1 parent 181f498 commit 67e8491
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 296 deletions.
50 changes: 50 additions & 0 deletions pkg/cmd/server/bootstrappolicy/controller_policy.go
Expand Up @@ -9,10 +9,47 @@ import (
rbac "k8s.io/kubernetes/pkg/apis/rbac"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"

// we need the conversions registered for our init block
_ "github.com/openshift/origin/pkg/authorization/apis/authorization/install"
)

const saRolePrefix = "system:openshift:controller:"

const (
InfraOriginNamespaceServiceAccountName = "origin-namespace-controller"
InfraServiceAccountControllerServiceAccountName = "serviceaccount-controller"
InfraServiceAccountPullSecretsControllerServiceAccountName = "serviceaccount-pull-secrets-controller"
InfraServiceAccountTokensControllerServiceAccountName = "serviceaccount-tokens-controller"
InfraServiceServingCertServiceAccountName = "service-serving-cert-controller"
InfraBuildControllerServiceAccountName = "build-controller"
InfraBuildConfigChangeControllerServiceAccountName = "build-config-change-controller"
InfraDeploymentConfigControllerServiceAccountName = "deploymentconfig-controller"
InfraDeploymentTriggerControllerServiceAccountName = "deployment-trigger-controller"
InfraDeployerControllerServiceAccountName = "deployer-controller"
InfraImageTriggerControllerServiceAccountName = "image-trigger-controller"
InfraImageImportControllerServiceAccountName = "image-import-controller"
InfraSDNControllerServiceAccountName = "sdn-controller"
InfraClusterQuotaReconciliationControllerServiceAccountName = "cluster-quota-reconciliation-controller"
InfraUnidlingControllerServiceAccountName = "unidling-controller"
InfraServiceIngressIPControllerServiceAccountName = "service-ingress-ip-controller"
InfraPersistentVolumeRecyclerControllerServiceAccountName = "pv-recycler-controller"
InfraResourceQuotaControllerServiceAccountName = "resourcequota-controller"

// template instance controller watches for TemplateInstance object creation
// and instantiates templates as a result.
InfraTemplateInstanceControllerServiceAccountName = "template-instance-controller"

// template service broker is an open service broker-compliant API
// implementation which serves up OpenShift templates. It uses the
// TemplateInstance backend for most of the heavy lifting.
InfraTemplateServiceBrokerServiceAccountName = "template-service-broker"

// This is a special constant which maps to the service account name used by the underlying
// Kubernetes code, so that we can build out the extra policy required to scale OpenShift resources.
InfraHorizontalPodAutoscalerControllerServiceAccountName = "horizontal-pod-autoscaler"
)

var (
// controllerRoles is a slice of roles used for controllers
controllerRoles = []rbac.ClusterRole{}
Expand Down Expand Up @@ -296,6 +333,19 @@ func init() {
},
})

addControllerRole(rbac.ClusterRole{
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraTemplateServiceBrokerServiceAccountName},
Rules: []rbac.PolicyRule{
rbac.NewRule("create").Groups(kAuthzGroup).Resources("subjectaccessreviews").RuleOrDie(),
rbac.NewRule("create").Groups(authzGroup).Resources("subjectaccessreviews").RuleOrDie(),
rbac.NewRule("get", "create", "update", "delete").Groups(templateGroup).Resources("brokertemplateinstances").RuleOrDie(),
rbac.NewRule("get", "create", "delete", "assign").Groups(templateGroup).Resources("templateinstances").RuleOrDie(),
rbac.NewRule("get", "list", "create", "delete").Groups(kapiGroup).Resources("secrets").RuleOrDie(),
rbac.NewRule("list").Groups(kapiGroup).Resources("services", "configmaps").RuleOrDie(),
rbac.NewRule("list").Groups(routeGroup).Resources("routes").RuleOrDie(),
eventsRule(),
},
})
}

// ControllerRoles returns the cluster roles used by controllers
Expand Down
180 changes: 0 additions & 180 deletions pkg/cmd/server/bootstrappolicy/infra_sa_policy.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/cmd/server/bootstrappolicy/policy.go
Expand Up @@ -959,7 +959,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
// 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 {
Expand All @@ -984,9 +983,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
for _, clusterRole := range openshiftClusterRoles {
openshiftClusterRoleNames.Insert(clusterRole.Name)
}
for _, clusterRole := range openshiftSAClusterRoles {
openshiftClusterRoleNames.Insert(clusterRole.Name)
}
for _, clusterRole := range kubeClusterRoles {
kubeClusterRoleNames.Insert(clusterRole.Name)
}
Expand All @@ -1005,7 +1001,6 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {

finalClusterRoles := []authorizationapi.ClusterRole{}
finalClusterRoles = append(finalClusterRoles, openshiftClusterRoles...)
finalClusterRoles = append(finalClusterRoles, openshiftSAClusterRoles...)
finalClusterRoles = append(finalClusterRoles, openshiftControllerRoles...)
finalClusterRoles = append(finalClusterRoles, kubeSAClusterRoles...)
for i := range kubeClusterRoles {
Expand Down
13 changes: 4 additions & 9 deletions pkg/cmd/server/bootstrappolicy/web_console_role_test.go
Expand Up @@ -46,7 +46,6 @@ var rolesToHide = sets.NewString(
"system:node-proxier",
"system:node-reader",
"system:oauth-token-deleter",
"system:openshift:template-service-broker",
"system:openshift:templateservicebroker-client",
"system:persistent-volume-provisioner",
"system:registry",
Expand Down Expand Up @@ -75,15 +74,11 @@ func TestSystemOnlyRoles(t *testing.T) {
}

if !show.Equal(rolesToShow) || !hide.Equal(rolesToHide) {
shouldNotShow := show.Difference(rolesToShow).List()
shouldNotHide := hide.Difference(rolesToHide).List()
t.Error("The list of expected end user roles has been changed. Please discuss with the web console team to update role annotations.")
if len(shouldNotShow) > 0 {
t.Errorf("These roles are visible but not in rolesToShow: %v", shouldNotShow)
}
if len(shouldNotHide) > 0 {
t.Errorf("These roles are hidden but not in rolesToHide: %v", shouldNotHide)
}
t.Logf("These roles are visible but not in rolesToShow: %v", show.Difference(rolesToShow).List())
t.Logf("These roles are hidden but not in rolesToHide: %v", hide.Difference(rolesToHide).List())
t.Logf("These roles are in rolesToShow but are missing from the visible list: %v", rolesToShow.Difference(show).List())
t.Logf("These roles are in rolesToHide but are missing from the hidden list: %v", rolesToHide.Difference(hide).List())
}
}

Expand Down
29 changes: 11 additions & 18 deletions pkg/cmd/server/origin/ensure.go
Expand Up @@ -54,15 +54,7 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {
return
}

roleAccessor := policy.NewClusterRoleBindingAccessor(c.ServiceAccountRoleBindingClient())
for _, saName := range bootstrappolicy.InfraSAs.GetServiceAccounts() {
_, err := c.KubeClientsetInternal().Core().ServiceAccounts(ns).Create(&kapi.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: saName}})
if err != nil && !kapierror.IsAlreadyExists(err) {
glog.Errorf("Error creating service account %s/%s: %v", ns, saName, err)
}

role, _ := bootstrappolicy.InfraSAs.RoleFor(saName)

for _, role := range bootstrappolicy.ControllerRoles() {
reconcileRole := &policy.ReconcileClusterRolesOptions{
RolesToReconcile: []string{role.Name},
Confirmed: true,
Expand All @@ -73,16 +65,17 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {
if err := reconcileRole.RunReconcileClusterRoles(nil, nil); err != nil {
glog.Errorf("Could not reconcile %v: %v\n", role.Name, err)
}

addRole := &policy.RoleModificationOptions{
RoleName: role.Name,
RoleBindingAccessor: roleAccessor,
Subjects: []kapi.ObjectReference{{Namespace: ns, Name: saName, Kind: "ServiceAccount"}},
}
for _, roleBinding := range bootstrappolicy.ControllerRoleBindings() {
reconcileRoleBinding := &policy.ReconcileClusterRoleBindingsOptions{
RolesToReconcile: []string{roleBinding.RoleRef.Name},
Confirmed: true,
Union: true,
Out: ioutil.Discard,
RoleBindingClient: c.PrivilegedLoopbackOpenShiftClient.ClusterRoleBindings(),
}
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error { return addRole.AddRole() }); err != nil {
glog.Errorf("Could not add %v service accounts to the %v cluster role: %v\n", saName, role.Name, err)
} else {
glog.V(2).Infof("Added %v service accounts to the %v cluster role: %v\n", saName, role.Name, err)
if err := reconcileRoleBinding.RunReconcileClusterRoleBindings(nil, nil); err != nil {
glog.Errorf("Could not reconcile %v: %v\n", roleBinding.Name, err)
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/testdata/bootstrappolicy/bootstrap_cluster_role_bindings.yaml
Expand Up @@ -918,6 +918,20 @@ items:
namespace: kube-system
userNames:
- system:serviceaccount:kube-system:horizontal-pod-autoscaler
- apiVersion: v1
groupNames: null
kind: ClusterRoleBinding
metadata:
creationTimestamp: null
name: system:openshift:controller:template-service-broker
roleRef:
name: system:openshift:controller:template-service-broker
subjects:
- kind: ServiceAccount
name: template-service-broker
namespace: openshift-infra
userNames:
- system:serviceaccount:openshift-infra:template-service-broker
- apiVersion: v1
groupNames:
- system:masters
Expand Down

0 comments on commit 67e8491

Please sign in to comment.