Skip to content

[SECURITY] apply_k8s_manifest executes the live kubectl apply before its AUTO_APPLY approval check #102

Closed

Description

@Nitjsefnie

Bug Description

With AUTO_APPLY=false and dry_run=false, K8sTools.apply_manifest executes the live kubectl apply before its approval check, so the cluster is mutated even though the caller is told the operation requires approval.

At tools/k8s_tools.py:56-59, when dry_run=False the command is built WITHOUT --dry-run=client and passed to executor.run() — the internal-call path that bypasses safety classification — before the not dry_run and not auto_apply approval branch at line 61 can return. The approval response is returned only after the live apply has already run.

Steps to Reproduce

  1. Set AUTO_APPLY=false.
  2. Call K8sTools.apply_manifest(manifest, dry_run=False, auto_apply=False, namespace="default", notifier=...).
  3. Observe the executed command and the returned dict.

Expected Behavior

With AUTO_APPLY=false, no mutating command runs; the method returns requires_approval with an approval payload BEFORE any kubectl apply reaches a cluster (same contract the other host-mutating tools follow).

Actual Behavior

The live apply runs first. Reproduced deterministically with the executor's external-command boundary replaced by a recorder (no cluster involved):

{
 "executed_commands": [
  ["exec", "kubectl apply -f /tmp/tmpfile.yaml -n default"]
 ],
 "live_apply_without_dry_run_flag": true,
 "returned_requires_approval": true,
 "returned_message": "Manifest validated (dry-run OK). Approval request sent to Slack."
}

The returned message "Manifest validated (dry-run OK)" is also inaccurate here: no dry-run validation ran.

Environment

  • Agent Version/Commit: 18261fe85007e50487427e266f9236602d88634f (current main, 2026-10-19)

Configuration

AUTO_APPLY=false

Additional Context

Discovered during our fix for #89/#70 (host-mutation approval gating); that PR is being opened in parallel and does not change tools/k8s_tools.py. Issue #69's "verification still pass without observing the target" is a different defect; this one is execution-before-approval inside apply_manifest itself. The same Slack value-size consideration noted for large manifests applies, though the defect here is the ordering, not the transport.

Possible Solution

Unverified: validate with the dry-run command first, and only build/execute the live apply after approval (or route the live apply through run_safe after the approval gate). Also fix the inaccurate success message when no dry-run validation ran.

Activity

  1. added a commit that references this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions