diff --git a/.github/workflows/helm-dev-lint.yml b/.github/workflows/helm-dev-lint.yml index 9f70c322..7711d0a4 100644 --- a/.github/workflows/helm-dev-lint.yml +++ b/.github/workflows/helm-dev-lint.yml @@ -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 diff --git a/charts/nudgebee-agent/templates/runner-custom-resource-read.yaml b/charts/nudgebee-agent/templates/runner-custom-resource-read.yaml index 5a5d985c..c6278e67 100644 --- a/charts/nudgebee-agent/templates/runner-custom-resource-read.yaml +++ b/charts/nudgebee-agent/templates/runner-custom-resource-read.yaml @@ -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 `: 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: @@ -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 "*") }} + {{- 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 @@ -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 @@ -104,3 +92,4 @@ subjects: name: {{ include "nudgebee-agent.fullname" . }}-runner-service-account namespace: {{ .Release.Namespace }} {{- end }} +{{- end }} diff --git a/charts/nudgebee-agent/values.yaml b/charts/nudgebee-agent/values.yaml index 2226fdc9..38159488 100644 --- a/charts/nudgebee-agent/values.yaml +++ b/charts/nudgebee-agent/values.yaml @@ -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 `: 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