Skip to content

Operator chart: no cluster-scoped RBAC needed with operator.rbac.scope=namespace #7112

Open

Description

@lucianstancu

Summary

With operator.rbac.scope=namespace, the operator chart still renders a ClusterRole (toolhive-operator-manager-role) and binds it with a RoleBinding in each allowedNamespaces entry. Installing the chart therefore requires permission to create cluster-scoped RBAC, even though the operator only needs namespaced access in this

Motivation

On OpenShift, and in other locked-down clusters, cluster-scoped resources are deployed separately by a cluster admin. A namespace admin can't create a ClusterRole, so the chart can't be installed even when the operator is meant to be namespace-scoped.

Related issues:

Findings

From reading the code (not yet tested on a cluster):

  • The only cluster-scoped rules are customresourcedefinitions and customresourcedefinitions/status, used by the StorageVersionMigrator controller. That feature already requires scope=cluster (templates/validate-features.yaml).
  • All other kubebuilder:rbac markers are for namespaced resources.
  • In namespace mode, the manager cache is limited to WATCH_NAMESPACE (cmd/thv-operator/app/app.go), and leader election uses the existing namespaced Role in the release namespace.
  • RBAC the operator creates at runtime (pkg/kubernetes/rbac/rbac.go, pkg/registryapi/rbac.go) is Ro, never ClusterRole`.
  • templates/clusterrole/role.yaml is written directly by controller-gen (cmd/thv-operator/Taskfile.yml), so it can't hold Helm templating. That is why the rules can't simply be reused in a second template today.

Proposal

  • scope=cluster: unchanged (ClusterRole + ClusterRoleBinding).
  • scope=namespace: render a Role and RoleBinding in each allowedNamespaces entry, and no ClusterRole or ClusterRoleBinding. The CRD rules stay in the cluster-scope output only.
  • Generate the rules to a non-template path (for example deploy/charts/operator/files/rbac), as the CRem with .Files.Get in both the ClusterRole and the per-namespace Role templates. This is the approach proposed in Operator chart: release-qualify the RBAC object names so two releases can coexist #7058 and keeps one source of truth for the rules.
  • Split the CRD rules out of the shared rule set so they never reach the namespaced Role (for example with a separate kubebuilder roleName, or by filtering by API group in the template).
  • Name the new objects with the release-qualified names from Operator chart: release-qualify the RBAC object names so two releases can coexist #7058.
  • Update the helm-unittest suites, the chainsaw assertions, the values.yaml comments and the generated chart README.

Trade-off: each allowed namespace gets its own copy of the rules.

CRDs are already in the separate operator-crds chart, so a namespace-scoped install would have no cluster-scoped objects of its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kubernetesItems related to Kubernetesneeds-triageIssue needs initial triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions