Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/helm-dev-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ jobs:
check ''
check '' --set runner.enableWritePermissions=true
check '' --set runner.readOnly=true
check '' --set runner.customResourceRead=true
check '' --set runner.customResourceRead=true --set runner.readOnly=true
check '' --set runner.customResourceRead.enabled=true
check '' --set runner.customResourceRead.enabled=true --set runner.readOnly=true
check 'ClusterRole/nudgebee-agent-runner-scanner-pullsecrets-read:get Role/nudgebee-agent-runner-scanner-pullsecrets:create,delete,patch,update' \
--set runner.scannerAutoCopyPullSecrets=true
check 'ClusterRole/nudgebee-agent-runner-helm-releases:list' --set runner.helmReleaseDiscovery=true
Expand Down
97 changes: 43 additions & 54 deletions charts/nudgebee-agent/templates/runner-custom-resource-read.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
{{- /*
Opt-in (runner.customResourceRead): read access behind the UI's CRDs tab,
which lists the cluster's CRDs and, per CRD, its objects (get_resource,
Opt-in (runner.customResourceRead.enabled): read access behind the UI's CRDs
tab, which lists the cluster's CRDs and, per CRD, its objects (get_resource,
all namespaces). Read-only and rendered in both standard and read-only mode.

- customresourcedefinitions: the CRD list itself.
- The built-in `view` ClusterRole: read on built-in kinds plus every CRD
whose operator labels its roles aggregate-to-view (cert-manager, Argo,
Elastic, ...). The default `view` grants no Secrets; anything a cluster
later aggregates into `view` is granted to the runner too.
- Named VictoriaMetrics and prometheus-operator kinds, whose operators do
not aggregate to `view` and which Nudgebee itself runs. Named, not `*`:
vmusers (password/bearerToken may be inline) and vmalertmanagers
(configRawYaml may embed receiver credentials) are left out on purpose.
- viewRole: a binding to the built-in `view` ClusterRole, which reads
built-in kinds plus every CRD whose operator labels its roles
aggregate-to-view (cert-manager, Argo, Elastic, ...). The default `view`
grants no Secrets; anything a cluster later aggregates into `view` is
granted to the runner too.
- groups: API group -> resources, always get/list/watch, so values cannot
widen the verbs. A map, not a list, 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` are refused at
render time: the CI Secrets gate only sees the chart's own values.

CRDs outside these stay unreadable; grant them with
runner.customClusterRoleRules. Secret-bearing kinds are refused by the
runner itself (pkg/kube/secretpolicy.go) whatever RBAC allows.
The default groups name VictoriaMetrics and prometheus-operator kinds, whose
operators do not aggregate to `view`. Named, not `*`: vmusers
(password/bearerToken may be inline) and vmalertmanagers (configRawYaml may
embed receiver credentials) are left out on purpose. Secret-type kinds are
also refused by the runner itself (pkg/kube/secretpolicy.go).
*/}}
{{- if .Values.runner.customResourceRead }}
{{- $cr := .Values.runner.customResourceRead }}
{{- if and $cr (not (kindIs "map" $cr)) }}
{{- fail "runner.customResourceRead is a map: set runner.customResourceRead.enabled=true (not runner.customResourceRead=true)" }}
{{- end }}
{{- if and (kindIs "map" $cr) $cr.enabled }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -31,52 +39,31 @@ rules:
- get
- list
- watch
{{- range $group, $resources := $cr.groups }}
{{- 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 "*") }}
Comment on lines +43 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 "*") }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

{{- fail (printf "runner.customResourceRead.groups: %q is not allowed; use runner.customClusterRoleRules for core or wildcard grants" $group) }}
{{- end }}
{{- range $resources }}
{{- if or (eq . "*") (eq . "secrets") }}
{{- fail (printf "runner.customResourceRead.groups.%s: %q is not allowed" $group .) }}
{{- end }}
{{- end }}
- apiGroups:
- "operator.victoriametrics.com"
resources:
- vlagents
- vlclusters
- vlogs
- vlsingles
- vmagents
- vmalertmanagerconfigs
- vmalerts
- vmanomalies
- vmanomalyconfigs
- vmauths
- vmclusters
- vmdistributed
- vmnodescrapes
- vmpodscrapes
- vmprobes
- vmrules
- vmscrapeconfigs
- vmservicescrapes
- vmsingles
- vmstaticscrapes
- vtclusters
- vtsingles
verbs:
- get
- list
- watch
- apiGroups:
- "monitoring.coreos.com"
- {{ $group | quote }}
resources:
- alertmanagerconfigs
- alertmanagers
- podmonitors
- probes
- prometheusagents
- prometheuses
- prometheusrules
- scrapeconfigs
- servicemonitors
- thanosrulers
{{- range $resources }}
- {{ . }}
{{- end }}
verbs:
- get
- list
- watch
{{- end }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -90,6 +77,7 @@ subjects:
- kind: ServiceAccount
name: {{ include "nudgebee-agent.fullname" . }}-runner-service-account
namespace: {{ .Release.Namespace }}
{{- if $cr.viewRole }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -104,3 +92,4 @@ subjects:
name: {{ include "nudgebee-agent.fullname" . }}-runner-service-account
namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}
56 changes: 50 additions & 6 deletions charts/nudgebee-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,56 @@ runner:
# cluster. Off by default: the upgrade check then reports Helm release
# compatibility as unknown. Also applies under runner.readOnly.
helmReleaseDiscovery: false
# Read access for the UI's CRDs tab: the CRD list, the built-in `view`
# ClusterRole (no Secrets by default), and named VictoriaMetrics / prometheus-operator
# kinds. Read-only; also applies under runner.readOnly. Off by default: the
# CRDs tab then shows "not allowed" until this is enabled. See
# templates/runner-custom-resource-read.yaml for what is left out and why.
customResourceRead: false
# Read access for the UI's CRDs tab. Read-only (get/list/watch); also
# applies under runner.readOnly. Off by default: the CRDs tab then shows
# "not allowed" until enabled. See templates/runner-custom-resource-read.yaml
# for what is left out and why.
customResourceRead:
enabled: false
# Bind the built-in `view` ClusterRole (no Secrets by default): built-in
# kinds plus every CRD whose operator aggregates to `view`.
viewRole: true
# API group -> resources to read. A map so an install can add a group
# without repeating these (Helm merges maps), e.g.
# --set-json 'runner.customResourceRead.groups={"traefik.io":["ingressroutes"]}'
# and drop one with `<group>: null`. The core group, "*" and "secrets"
# fail the render.
groups:
# vmusers and vmalertmanagers are left out: they can carry credentials inline.
operator.victoriametrics.com:
- vlagents
- vlclusters
- vlogs
- vlsingles
- vmagents
- vmalertmanagerconfigs
- vmalerts
- vmanomalies
- vmanomalyconfigs
- vmauths
- vmclusters
- vmdistributed
- vmnodescrapes
- vmpodscrapes
- vmprobes
- vmrules
- vmscrapeconfigs
- vmservicescrapes
- vmsingles
- vmstaticscrapes
- vtclusters
- vtsingles
monitoring.coreos.com:
- alertmanagerconfigs
- alertmanagers
- podmonitors
- probes
- prometheusagents
- prometheuses
- prometheusrules
- scrapeconfigs
- servicemonitors
- thanosrulers
customClusterRoleRules: []
imagePullSecrets: []
# Extra volumes on the runner pod. The common use is trusting a private CA
Expand Down
Loading