Repository navigation
feat(chart): make runner.customResourceRead groups configurable, read-only - #729
RamanKharchee wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the runner.customResourceRead configuration in the Helm chart from a boolean to a map structure, allowing users to toggle the built-in view ClusterRole binding and dynamically configure API groups and resources to read. The review feedback points out two important issues: first, the type check for runner.customResourceRead will incorrectly fail when explicitly set to false or nil to disable the feature; second, a validation check is needed to ensure that the resources specified under groups are lists rather than strings to prevent template rendering errors.
| {{- if not (kindIs "map" $cr) }} | ||
| {{- fail "runner.customResourceRead is a map: set runner.customResourceRead.enabled=true (not runner.customResourceRead=true)" }} | ||
| {{- end }} | ||
| {{- if $cr.enabled }} |
There was a problem hiding this comment.
The current check {{- if not (kindIs "map" $cr) }} will trigger a template rendering failure even if runner.customResourceRead is explicitly set to false or nil (e.g., to disable the feature or override values). This is because kindIs "map" false is false.
To prevent false positives and allow users to explicitly disable the feature using false or nil, we should only fail if the value is truthy and not a map (such as true or a string). We also need to guard the .enabled check to avoid evaluating it on non-map values.
{{- if and (not (kindIs "map" $cr)) $cr }}
{{- fail "runner.customResourceRead is a map: set runner.customResourceRead.enabled=true (not runner.customResourceRead=true)" }}
{{- end }}
{{- if and (kindIs "map" $cr) $cr.enabled }}There was a problem hiding this comment.
Fixed. Reproduced it first: customResourceRead: false (via -f and --set) and null both failed with the "is a map" message. Now only a truthy non-map (true, a string) fails, and the .enabled check runs only on a map. Re-rendered: false, null and the default render nothing, true still fails with the hint, and enabled=true renders the same 3 objects.
| {{- if $resources }} | ||
| {{- if or (eq $group "") (eq $group "*") }} |
There was a problem hiding this comment.
If a user misconfigures runner.customResourceRead.groups by providing a single string instead of a list of resources (e.g., monitoring.coreos.com: alertmanagers), Go's template engine will range over the string's characters, resulting in invalid resource names like a, l, e, r, t...
We should add a validation check to ensure that $resources is a list/slice before iterating over it.
{{- if $resources }}
{{- if not (kindIs "slice" $resources) }}
{{- fail (printf "runner.customResourceRead.groups.%s must be a list of resources" $group) }}
{{- end }}
{{- if or (eq $group "") (eq $group "*") }}There was a problem hiding this comment.
Added the kindIs "slice" guard. One correction: with traefik.io: ingressroutes, the template doesn't iterate characters. Helm fails the render with only a position (runner-custom-resource-read.yaml:47:12). It now fails with runner.customResourceRead.groups.traefik.io must be a list of resources.
…-only Follow-up to #728. The VictoriaMetrics and prometheus-operator kinds were hardcoded in the template, so a CRD outside `view` (Traefik, for example) needed a chart release, and the only other route, runner.customClusterRoleRules, accepts any verb. runner.customResourceRead becomes a map (unreleased, so no shim): - enabled (default false): the opt-in; CRD list read - viewRole (default true): the built-in `view` binding - groups: API group -> resources, always get/list/watch. A map so an install adds a group without repeating the defaults (Helm merges maps, replaces lists) and drops one with `<group>: null`. The core group, "*" and "secrets" fail the render, since the CI Secrets gate only sees the chart's own values. The enabled render's rules are unchanged from #728. Suggested-by: mayankpande88 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ba4a1b2 to
71a4a65
Compare
Summary
This follows up #728, as suggested in its review. The CRDs tab's extra read grants were hardcoded in the template, so reading another CRD (Traefik, for example) needed a chart release. The only other route was a custom rule, which accepts any verb. Now an install can list extra API groups in values. Those grants are always read-only, and any group or resource that would reach Secrets fails the install.
Decision:
runner.customResourceReadbecomes a map (enabled,viewRole,groups) in place of a bool. It is a map rather than a list because Helm merges maps but replaces lists, so adding one group keeps the defaults. The bool has not shipped in any release or rc, so it is replaced outright, with no compatibility code. Setting the oldrunner.customResourceRead=truenow fails with a message naming the new key.Look at: the guards at the top of
runner-custom-resource-read.yaml. The rules rendered when enabled are identical to #728's.Type of change
Chart version
Test plan
helm templatewith--set runner.customResourceRead.enabled=true --set-json 'runner.customResourceRead.groups={"traefik.io":["ingressroutes"]}'. The role readstraefik.ioand still reads the VictoriaMetrics and prometheus-operator groups.--set-json 'runner.customResourceRead.groups={"x.io":["secrets"]}'. The render fails with "is not allowed".--set runner.customResourceRead=true. The render fails and namesrunner.customResourceRead.enabled=true.helm lint charts/nudgebee-agentpassesct lint(left to CI)helm templateoutput reviewed (detail below)Engineering detail
Renders checked locally:
enabled=true, standard and read-only modeenabled=true+--set-json groups={"traefik.io":[...]}apiextensions.k8s.io,monitoring.coreos.com,operator.victoriametrics.com,traefik.io-fwithgroups.monitoring.coreos.com: nullmonitoring.coreos.comdropped, the rest keptviewRole=falseviewbinding"","*", resource"*", resourcesecrets... is not allowedrunner.customResourceRead: falseornull... must be a list of resourcesrunner.customResourceRead=true(via--setand-f)runner.customResourceRead is a map: set runner.customResourceRead.enabled=true .... Without this guard, Helm failed with only a template position.CI Secrets gate script: no grants for the default,
enableWritePermissions,customResourceRead.enabled, andcustomResourceRead.enabled+readOnlyrenders. The gate's two opt-in cases now use.enabled=true.The nudgebee-enterprise UI banner pointed at
runner.customResourceRead: true. That text is updated in the companion app PR.🤖 Generated with Claude Code