Repository navigation
fix(agent): refuse Secret access through the agent and make Secrets RBAC opt-in - #714
Merged
Merged
Conversation
…BAC opt-in The runner's ClusterRole granted get/list/watch on every Secret in the cluster, and kubectl_command_executor accepted `get secret` as a read, so anything able to reach the agent could read every credential in the cluster. Agent: - kubectl_command_executor refuses secret-bearing kinds (secrets, sealed, external, store and provider-class kinds, all spellings), --raw paths to them, file-backed output formats (-o *-file, templatefile), mounted credential paths and `create token`. Enforced in read-only and write mode. - get_resource / get_resource_yaml blank Secret values and drop the last-applied-configuration annotation; key names are kept. - New list_helm_releases action: decodes Helm release Secrets in the agent and returns chart metadata only (name, revision, status, chart, version, appVersion, kubeVersion). Release values never leave the cluster. Chart: - No Secrets rules in the default, write-mode or read-only render. - runner.scannerAutoCopyPullSecrets now defaults to false. When on it grants get (no list/watch) on secrets cluster-wide plus create/update/patch/delete in the release namespace. - New runner.helmReleaseDiscovery (default false) grants cluster-wide list on secrets for list_helm_releases. - CI asserts no Secrets grant exists outside the two opt-ins.
There was a problem hiding this comment.
Code Review
This pull request restricts the agent's default Kubernetes Secret access by making secret-copying opt-in, removing cluster-wide Secret permissions from the base service account, and introducing a strict secret-access policy for kubectl commands and resource retrieval. It also adds an opt-in Helm release discovery feature that lists Helm release metadata without leaking release values. The review feedback highlights a path traversal bypass vulnerability in the --raw command validation, a potential nil pointer dereference in Helm release decoding, and opportunities to improve path validation robustness and test coverage.
- --raw paths are checked as written and after path.Clean, so dot segments and doubled slashes (serviceaccounts/sa/./token) cannot dodge the check. - Mounted-secret patterns drop the leading slash so relative spellings (../var/run/secrets/...) match. - list_helm_releases skips a release blob that decodes to no release name.
blue4209211
approved these changes
Nov 8, 2026
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The runner's ClusterRole granted
get/list/watchon every Secret in the cluster, andkubectl_command_executoracceptedkubectl get secretas a read. Anything that could send the agent an action could read every credential in the cluster. This PR closes that in the agent itself and removes the cluster-wide grant from the chart.secret,sealedsecret,externalsecret/es,secretstore/ss,clustersecretstore/css,secretproviderclass/spc.--rawpaths that reach them, including percent-encoded ones.-o jsonpath-file=,go-template-file,custom-columns-file,templatefile). These read a file from the agent pod and echo it on a parse error./var/run/secrets…) andcreate token.get_resource/get_resource_yamlblank Secret values. Key names are kept, andlast-applied-configurationis dropped because it carries the values in plain text.list_helm_releasesaction. It reads Helm release Secrets inside the agent and returns metadata only: name, namespace, revision, status, chart, version, appVersion, kubeVersion and last deployed. Release values and manifests stay in the cluster.runner.scannerAutoCopyPullSecretsnow defaults to false. When on, it grantsgeton secrets in every namespace (no list or watch) and create/update/patch/delete in the release namespace only.runner.helmReleaseDiscovery, new, default false. When on, it grants cluster-wideliston secrets forlist_helm_releases. RBAC can't narrow this to Helm's Secrets.helm-dev-lintfails if any render grants a Secrets verb outside those two opt-ins.Type of change
Upgrading changes behavior in three ways:
runner.scannerAutoCopyPullSecrets=trueis set.get_resourceon Secrets fails with Forbidden unless an opt-in grantslist.kubectl get secrets -l owner=helmmust move tolist_helm_releasesand setrunner.helmReleaseDiscovery=true.Chart version
Test plan
make validateinrunner/(fmt, vet,go test -race ./...)helm lint charts/nudgebee-agentpasseshelm templatereviewed for default, write mode, read-only and each opt-in. The new CI step passes locally.Engineering detail
secretpolicy_test.go: 34 refused commands, run in both modes; secret mutations in write mode; names that only contain "secret" are still allowed; redaction throughget_resourceand the YAML path.helm_list_test.go: latest revision only, release values never returned, Forbidden mapped to the opt-in error.validateSegment, sorunner.enableWritePermissionsdoes not lift it.secrets,esorssis refused. That is accepted: a false refusal is a clear error, a miss is a leak.list_helm_releasespages at 50 Secrets, so a large cluster's release blobs are never held at once. It returns a clear "not enabled" error when the list is forbidden.pods/execcluster-wide, so exec-based actions can still read a pod's environment or mounted files.Local e2e: on a kind cluster, the chart's rendered RBAC was applied and the agent's code ran with the runner ServiceAccount's token, using real kubectl and the real API server. Default render:
auth can-iget/list/create secrets all returnedno. The executor refused all 7 Secret-reading commands in both modes (get secrets,get secret … -o jsonpath={.data…},--raw …/secrets,--raw …/%73ecrets,-o jsonpath-file=…/token,create token), andget podsran.get_resourceon secrets returned Forbidden, andlist_helm_releasesreturned the "not enabled" error. WithhelmReleaseDiscovery=true: list allowed, get and watch denied.list_helm_releasesreturned revision 3 of a test release (name, chart 1.2.3, kubeVersion), andget_resourcereturned blank values. None of the planted Secret or Helm values appeared in any output. WithscannerAutoCopyPullSecrets=true: get allowed in the workload namespace, list denied, and create only in the release namespace. A realschedule_k8s_jobcopied only thedockerconfigjsonpull secret (an Opaque Secret listed on the same pod was skipped). The copy was owned by the Job, and the Job resumed.