Skip to content

fix: require approval for host-mutating tools when AUTO_APPLY is disabled (#89, #70) - #103

Merged
OkiriGabriel merged 7 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/auto-apply-host-mutations
Oct 20, 2026
Merged

OkiriGabriel merged 7 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/auto-apply-host-mutations

Conversation

@Nitjsefnie

@Nitjsefnie Nitjsefnie commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

With AUTO_APPLY=false, six host-mutating tools could be driven live by the model's own dry_run=false input (and nginx apply/restart had no gate at all), because their dispatches bypassed the approval flow used by other gated tools. This gates the six host-mutating tools behind the repository's existing approval-response contract, adds the agent-level emergency-stop regression #70 asked for, and adds a bounded, single-use approval-reference store so the approved operation stays deliverable and safe after approval. Approved replays run with the agent's own interpreter, and the replay exit code reflects operation success rather than attempted application.

Related Issues

Fixes #89
Closes #70

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • New platform/collector support

Platform/Component

  • Core Agent
  • Kubernetes
  • CI/CD (specify: ____________)
  • Cloud Provider (specify: ____________)
  • ArgoCD
  • Docker
  • API Server
  • Tools/Executor
  • Tests

Testing

  • New tests/test_host_mutation_approval.py (131 cases): with AUTO_APPLY=false, the six host-mutating tools return the existing requires_approval response with zero commands executed (recording runner, forbid-all); AUTO_APPLY=true behavior unchanged; dispatch/registration reconciliation so a future mutating tool missing from MUTATING_AGENT_TOOLS fails; emergency stop blocks all 28 mutating names at execute_tool for both AUTO_APPLY values ([BUG] AGENT_EMERGENCY_STOP does not block several mutating tools #70 regression); approved replays run with the agent's own shell-quoted interpreter (quoting pinned against a shell-sensitive interpreter path); approved cleanup replays exit nonzero when a journal-vacuum or delete command fails, while protected/skipped paths stay a distinct non-error success.
  • New tests/test_approval_lifecycle.py (75 cases): bounded approval references (Slack button ≤2000 chars), TTL fail-closed, atomic single-use consumption, stale-reader/clock-skew fencing, per-backend (memory/S3/MinIO/GCS/Azure) reclamation and bounded admission; production-only revert proofs retained per fix.
  • Covering files re-run locally at the round heads (136 + 75 passing; 206 together in independent review); fork CI green on the exact head SHA 95a9ae1a46d4fdeb0336c6eb73398edb323ba485 (10/10 jobs, Security Scan included); the same SHA is green on upstream CI (all jobs success; deploy skipped by design). No full suite or build was run locally.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes

None at the API level. By design (the requested fix), with AUTO_APPLY=false the six host-mutating tools now return requires_approval instead of executing live; AUTO_APPLY=true behavior is unchanged.

Additional Notes

Design summary: dispatch routes the six host mutations through a shared operation gate; with approval required it returns SafeExecutor.run_safe's existing response keys with a bounded agent-approval: reference (stored via the selected StorageProvider, TTL 1h, ≤256/org/hour, ≤256 KiB, single-use with atomic consumption and stale-reader fencing) instead of an oversized inline command. Approved consumption fences on a conditional transition of the stored payload itself, so a stale reader cannot recreate execution authority. restart_cloud_resource / scale_cloud_service are intentionally untouched (gated by emergency stop per #70's scope).

Bugs Discovered:

Generated by GLM-5.3-Flash (brief, review), GPT-6.1 Sol (implementation, testing), GPT-6 Astra (review, testing)

@OkiriGabriel OkiriGabriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nitjsefnie, this is a careful fix for #89 and #70. Replaying the whole helper (validation, rollback, nginx -t gate) after approval, instead of approving its individual shell commands, is the right design. The bounded single-use reference keeps Slack's 2,000-character limit safe. The tests that check every name in MUTATING_AGENT_TOOLS is gated mean the next mutating tool can't slip through. Thanks also for filing #102.

Blocking: the approved operation runs with whatever python3 is on PATH

_execute_host_mutation builds python3 -c '<script>', and SafeExecutor._exec runs it through the shell. The documented systemd deployment (BUILD_AND_USAGE.md) uses ExecStart=/opt/devops-ai-agent/venv/bin/devops-agent serve, so the venv isn't on PATH. There, python3 is the system interpreter without httpx/structlog, and every approved nginx, cleanup, cert or security-update action fails with ModuleNotFoundError. It fails safely, but approval never works in that setup.

Fix: use the agent's own interpreter:

f"{shlex.quote(sys.executable)} -c {shlex.quote(script)}"

The from tools.… import … in the script also relies on the subprocess's working directory being the repo root (or the package being installed). It's fine for both documented setups, but adding cwd handling or a comment would make that assumption explicit.

Non-blocking

  • apply_nginx_config has no dry_run, so with AUTO_APPLY=false it always needs approval. That's correct; I'm just noting it for anyone reading the PR.
  • The checklist says the docs weren't updated. One line in SECURITY_GUARANTEES.md saying these six tools now require approval when AUTO_APPLY=false would help operators.

With the interpreter fix I'll approve and merge. CI is green, and the rest looks good.

Nitjsefnie and others added 7 commits October 20, 2026 09:23
…pen-devops-agent#89)

Gate complete host operations before running their helpers, preserve dry runs and enabled auto apply, and cover all mutating agent tools under emergency stop.

Co-Authored-By: GPT-6.1 Sol <[email protected]>
Keep exact operations in org-scoped storage, resolve approval references before execution, and preserve failed helper exit status. Cover Slack transport limits, rollback failures, binding, and strict dry-run command checks.

Co-Authored-By: GPT-6.1 Sol <[email protected]>
Expire host approvals after one hour, reclaim executed payloads, and bound admission state by window and record size. Use atomic backend claims without unsafe S3 fallbacks and cover concurrent reuse, expiry, and reclamation.

Co-Authored-By: GPT-6.1 Sol <[email protected]>
Require locked memory consumption or a conditional cloud object transition before granting execution. Reject stale readers after cleanup regardless of their clock, and test revocation at the conditional write boundary.

Co-Authored-By: GPT-6.1 Sol <[email protected]>
@Nitjsefnie
Nitjsefnie marked this pull request as draft October 20, 2026 08:00
@Nitjsefnie
Nitjsefnie force-pushed the fix/auto-apply-host-mutations branch from 63ac08d to 95a9ae1 Compare October 20, 2026 08:00
@Nitjsefnie
Nitjsefnie marked this pull request as ready for review October 20, 2026 08:04
@Nitjsefnie

Copy link
Copy Markdown
Contributor Author

All three asks are in: the approved operation now runs with the agent's own shell-quoted interpreter (sys.executable), the cwd/import assumption is documented right at the script construction, and SECURITY_GUARANTEES.md notes the six tools require approval when AUTO_APPLY=false. While re-reviewing the whole branch we also found a failed approved cleanup could still report success, so the replay exit code now reflects operation success rather than attempted application. CI is green on the pushed head.

@OkiriGabriel OkiriGabriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nitjsefnie, all addressed: the replay runs under the shell-quoted sys.executable (with a test pinning the quoting), the cwd/import assumption is documented at the script construction, and SECURITY_GUARANTEES.md notes the approval requirement. Good catch on cleanup reporting success after a failed command; the replay exit code now reflects real success. CI is green. Approving and merging.

@OkiriGabriel
OkiriGabriel merged commit 4f4462f into open-devops-agent:main Oct 20, 2026
12 checks passed
OkiriGabriel added a commit to Nitjsefnie-OSC/DevOps-AI-Agent that referenced this pull request Oct 20, 2026
With AUTO_APPLY=false and dry_run=false, apply_manifest ran the live
`kubectl apply` first and only then returned requires_approval (open-devops-agent#102).
The approval it sent was also unusable: it pointed at the temp manifest
file, which was deleted before anyone could approve it.

Now, without AUTO_APPLY, only `kubectl apply --dry-run=client` runs. If
validation fails, no approval is requested. Otherwise the live command
carries the manifest as base64 piped into `kubectl apply -f -` and is
retained as a single-use approval reference (CommandApprovalStore, from
open-devops-agent#103), so it fits in a Slack button and can be executed once approved.
Namespace and paths are shell-quoted.

Fixes open-devops-agent#102

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants