All articles
Automation
Remediation
Security Operations

Automated Remediation Without the Fear: Reversible Response on AWS

Most security teams detect problems in seconds and fix them in hours, because nobody wants an automation to break production. Here is how to design automated response on AWS that you can trust — and undo.

Trust Partners Security Team 6 min read

Ask a cloud security team whether they detect a security group opened to the internet, and the answer is almost always yes. Ask whether they close it automatically, and the answer is almost always no.

The reason is not technical. Closing a port takes one API call. The reason is fear: the one time an automation revokes a rule that a production load balancer needed, the security team loses the right to automate for a year. So the alert goes into a queue, and the port stays open for hours or days while someone finds the owner.

This article describes five design principles that make automated response safe enough to switch on, with a worked example and a rollout plan.

The cost of manual response

Attackers automate. Scanners find a newly exposed SSH port or database within minutes. A leaked key is tried within minutes. Crypto-mining instances start as soon as the attacker has RunInstances.

Manual response does not work at that speed. A realistic manual path is: alert fires, on-call engineer acknowledges, finds the resource, finds the owner, asks whether the change was intended, waits for an answer, makes the fix. Even a good team measures that in hours. The gap between "detected" and "fixed" is where incidents happen.

Principle 1: Every action must know its inverse

The fear of automation is really the fear of a change you cannot take back. So make every automated action record exactly how to undo it, at the moment it runs:

Action Inverse What must be captured
Revoke a security group ingress rule Authorize the same rule Protocol, port range, CIDR, description
Stop an EC2 instance Start the instance Instance ID
Attach a deny policy to an IAM user or role Detach the policy Policy ARN, principal
Deactivate an access key Activate the key Key ID, user
Terminate an instance None

The last row is the important one. Some actions have no inverse. Do not automate them. Prefer stop over terminate, deactivate over delete, and deny policy over delete user. You lose almost nothing in containment strength and you keep the undo button.

Principle 2: Gate on context, not only on the event

An event tells you what happened. It does not tell you whether it matters. A security group opened to 0.0.0.0/0 on port 443 and attached to a public load balancer is normal. The same rule on port 5432 attached to a database in a private subnet is an incident.

Before acting, look up the resource in your inventory and check its context:

  • Which subnet, VPC and account is it in? Is the subnet public or private?
  • Which instances, load balancers or databases use this security group?
  • What tags does it carry (environment, owner, exposure=public)?

Then act only when the context matches: "revoke 0.0.0.0/0 ingress unless the group is tagged exposure=public", or "stop the instance only if it is in a private subnet".

One important rule: if the context lookup fails, fail open. A missing or stale inventory snapshot must never suppress a real detection. Fire the alert, skip the automatic action, and say why.

Principle 3: Notify first, then earn automation

Do not switch a new rule straight to automatic remediation. Run it in stages, and use data to decide when to move on:

  1. Observe. The rule only records matches. Nobody is paged.
  2. Notify. Matches send alerts. Every false positive becomes a scope change.
  3. Human in the loop. Alerts carry a one-click action link — contain this identity, revoke this rule — that expires after a short time and works once.
  4. Automatic. The rule acts on its own and notifies after the fact.

A rule moves to the next stage when a week passes with no false positives at the current stage. A rule that never gets there tells you something useful about your environment.

Principle 4: Humans stay in control of the undo

Automatic action is only safe if reversal is fast and does not need special access. The engineer who gets the "your security group rule was revoked" message at 16:00 must be able to restore it in one click, without an IAM ticket, and see who or what changed it and why.

That means one place that lists every action taken — automatic or manual — with its target, the rule that triggered it, its status, and a rollback control. Rolling back should itself be recorded as an action, linked to the original, never by deleting history.

Principle 5: Measure trust

Three numbers tell you whether your automated response is working:

  • Time to containment. From the triggering event to the action. For automated rules this should be seconds to a few minutes, dominated by CloudTrail delivery time.
  • Automation coverage. The share of high-severity detections that were contained automatically or with one click.
  • Rollback rate. The share of automated actions that were rolled back. A low rate means rules are well scoped. A rising rate on one rule means that rule needs a tighter gate — not that automation is a bad idea.

Worked example: a database port opened to the internet

  1. A developer adds an ingress rule 0.0.0.0/0 on TCP 5432 to a security group while debugging.
  2. CloudTrail records AuthorizeSecurityGroupIngress. The detection matches an open-ingress rule.
  3. The resource gate checks the inventory: the group is attached to an RDS instance in a private subnet, and it has no exposure=public tag. The gate passes.
  4. The runbook revokes exactly that rule and records the captured rule as the inverse.
  5. The developer and the security channel get a message: what was revoked, why, and a link to roll it back.
  6. The developer rolls back? The same rule is re-authorized from the captured definition and the original action is marked reverted. Nobody else is involved. More likely, the developer uses a bastion or VPN instead.

Total exposure: a few minutes instead of an afternoon.

Where to start

Pick five detections with a clear inverse and low false positive risk:

Detection Automatic action Inverse
Security group ingress opened to 0.0.0.0/0 on non-web ports Revoke rule Re-authorize
CloudTrail logging stopped Re-enable logging — (restores a safe state)
Instance launched outside approved types or regions Stop instance Start instance
Mass S3 delete by one identity Contain identity Release
Repeated AccessDenied from one identity One-click containment link Release

How AWS Cloud Governance helps

AWS Cloud Governance is built around these principles and runs entirely inside your AWS account:

  • Reversible by design. Each action records its inverse; the Actions page lists every action with a Rollback button and marks it Reverted once undone. Terminate is available but clearly not reversible.
  • Inventory-gated rules. A resource gate evaluates the triggering resource against the inventory graph — subnet, tags, related resources — and fails open with a warning.
  • Staged rollout. Start rules notify-only, add single-use 24-hour containment links to alerts, then add containment or remediation steps to the runbook when you trust the rule.
  • Execution history. Every rule run is recorded as Detected, Notified, Remediated or Partial, with an investigation report.

See pricing or start a free 3-month trial at https://trustpartners.tech.