fix(helm): namespaceScope RBAC (avoid ClusterRole)#2595
fix(helm): namespaceScope RBAC (avoid ClusterRole)#2595peterbueschel wants to merge 8 commits intografana:masterfrom
Conversation
|
Hi, |
theSuess
left a comment
There was a problem hiding this comment.
LGTM from my side but would appreciate it if @Baarsgaard or @weisdd also take a glance as I never trust myself when it comes to helm templates 😅
|
I'll render and install the manifests later today and approve when I've tested it 😄 |
Baarsgaard
left a comment
There was a problem hiding this comment.
Had a small stumble while testing, otherwise this works great
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: {{ include "grafana-operator.fullname" $ }} |
There was a problem hiding this comment.
I tried toggling rbac.useClusterRole on/off and it failed with:
Error: UPGRADE FAILED: cannot patch "grafana-operator" with kind RoleBinding: RoleBinding.rbac.authorization.k8s.io "grafana-operator" is invalid: roleRef: Invalid value: {"APIGroup":"rbac.authorization.k8s.io","Kind":"ClusterRole","Name":"grafana-operator"}: cannot change roleRef
Evidently, roleRef does not allow updates. Meaning I had to either uninstall the chart entirely or disable namespaceScope and re-enable it alongside rbac.useClusterRole.
One way to fix this is to create distinct RoleBindings depending on rbac.useClusterRole requiring Helm to delete the old one and create one with a different name.
| name: {{ include "grafana-operator.fullname" $ }} | |
| name: {{ include "grafana-operator.fullname" $ }}-{{ ternary "cluster-role" "role" $useClusterRole }}{{- /* Allows toggling rbac.useClusterRole without re-install or disabling namespaceScope */}} |
If there's a better way, I'm open to suggestions but this is pretty simple and identical to the ternary deciding the roleRef.kind
Description
Fixes #2594
The chart currently always creates a
ClusterRoleeven whennamespaceScope=true. While binding aClusterRolevia aRoleBindingis namespace-scoped, creating theClusterRoleitself requires cluster-scoped RBAC and therefore breaks upgrades/installs in restricted clusters.This PR introduces an explicit chart option:
rbac.useClusterRole=true(default): preserve existing behaviour (createClusterRoleand bind it either cluster-wide or via per-namespaceRoleBindings whennamespaceScope=true)rbac.useClusterRole=false+namespaceScope=true: render namespacedRole+RoleBindinginstead (noClusterRole/ClusterRoleBinding)Note:
watchNamespaceSelectorrequires cluster-scoped permission to list namespaces and therefore requiresrbac.useClusterRole=true.Verification
Local render checks