Repository navigation
Description
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:
- Support for Strongly Isolated / Namespace-Scoped ToolHive Operator Installations #2152: one operator per namespace, which hits the same
ClusterRolecollision. This issue is narrower: removing the cluster-scoped RBAC requirement forscope=namespace, independent of the multi-instance and CRD-versioning questions raised there. - Operator chart: release-qualify the RBAC object names so two releases can coexist #7058: release-qualified RBAC names. This proposal builds on it and should land after it, or be combined with it, since both change
templates/clusterrole/role.yamlandrolebinding.yaml.
Findings
From reading the code (not yet tested on a cluster):
- The only cluster-scoped rules are
customresourcedefinitionsandcustomresourcedefinitions/status, used by the StorageVersionMigrator controller. That feature already requiresscope=cluster(templates/validate-features.yaml). - All other
kubebuilder:rbacmarkers 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) isRo, neverClusterRole`. templates/clusterrole/role.yamlis 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 aRoleandRoleBindingin eachallowedNamespacesentry, and noClusterRoleorClusterRoleBinding. 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.Getin both theClusterRoleand the per-namespaceRoletemplates. 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 kubebuilderroleName, 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.yamlcomments 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.
Activity