feat(kube): allow mutating kubectl when write permissions enabled - #475
Merged
Conversation
kubectl_command_executor enforced a read-only verb allowlist unconditionally, so scale/patch/set/delete were rejected even on installs that grant the runner write RBAC. Gate the allowlist on the existing runner.enableWritePermissions chart flag (the same switch that grants the write ClusterRole) via a new KUBECTL_ALLOW_WRITE env. Default stays read-only; when enabled, mutating verbs run and the API server's RBAC is the enforcement boundary. Same unsigned, relay-secret-gated posture as pod_script_run_enricher. Also fix verb resolution to skip leading global flags: `kubectl -n ns get pods` was rejected as verb "-n". firstVerb() now skips -n/--namespace/ --context/-o/etc. before validating, so read commands with global flags work and mutating verbs behind a flag are still caught.
There was a problem hiding this comment.
Code Review
This pull request introduces the KUBECTL_ALLOW_WRITE configuration option (gated by runner.enableWritePermissions in the Helm chart) to lift the read-only restriction on the kubectl command executor. It also adds logic to parse the actual command verb past any leading global flags. The review feedback points out that several common global flags (such as -v and --v for verbosity) are missing from the verbFlagsWithValue map, which would cause the parser to incorrectly identify their values as the command verb. It is recommended to add these missing flags and include a test case to verify this behavior.
Address review: -v/--v (verbosity), --username/--password/--as-uid/ --vmodule also consume a following token. Without them, `kubectl -v 6 get pods` resolved "6" as the verb and failed validation.
Contributor
|
📦 Image Tags Updated |
RamanKharchee
approved these changes
Jun 12, 2026
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.
Problem
kubectl_command_executorenforced a read-only verb allowlist unconditionally. On installs that grant the runner write RBAC (runner.enableWritePermissions: true), mutating commands were still rejected:The legacy robusta executor ran these via
KUBECTL_ALLOW_CRUD(defaulted on); the Go rewrite made the allowlist a hard gate with no escape hatch.Changes
runner.enableWritePermissions. NewKUBECTL_ALLOW_WRITEenv, emitted by the chart from the same flag that grants the write ClusterRole — so the runner allowlist and cluster RBAC move together. Defaultfalsekeeps kubectl strictly read-only; mutations still route to the signedpkg/mutateactions. Whentrue, mutating verbs run and the API server's RBAC becomes the enforcement boundary.kubectl -n ns get podswas rejected as verb-n.firstVerb()now skips-n/--namespace/--context/-o/--kubeconfig/etc. before validating. Mutating verbs hidden behind a flag (-n default scale ...) are still caught when write mode is off.Security posture
When write mode is on, mutating kubectl flows over the unsigned, relay-secret-gated light-action path — the same posture as the existing
pod_script_run_enricher. The operator who setsenableWritePermissions: true(granting write RBAC) is explicitly opting into cluster writes. Default-off installs are unchanged and strictly read-only.Tests
Added coverage for: reads behind global flags, rejection of mutations behind flags (no bypass),
AllowWritepermitting mutations, and flags-only input.go test ./pkg/kube/ ./pkg/config/passes; chart rendersKUBECTL_ALLOW_WRITE: "false"by default.