Skip to main content
In this lesson you’ll configure AWS Config to detect a deliberately insecure EC2 security group (SSH open to the world) and automatically remediate it using a Systems Manager Automation runbook. Overview
  • Create a security group with an intentionally insecure inbound SSH rule (0.0.0.0/0).
  • Add the AWS Config managed rule restricted-ssh scoped to that security group.
  • Attach an automatic remediation action that runs the Systems Manager Automation runbook AWS-DisablePublicAccessForSecurityGroup.
  • Create an IAM role that Automation assumes to remove the public SSH rule.
  • Re-evaluate the rule to trigger remediation and verify the security group becomes compliant.
All steps must be performed in the same AWS Region. This example uses US East (Ohio) us-east-2. Make sure EC2, Config, Systems Manager, and IAM are set to the same Region while following along.
Quick reference — artifacts created in this demo: Step 1 — Create an insecure security group
  1. Open the EC2 console → Security Groups.
  2. Create a new security group (e.g., name config-sg) in your default VPC.
  3. Add an inbound rule:
    • Type: SSH (TCP 22)
    • Source: 0.0.0.0/0 (Anywhere-IPv4)
This intentionally allows SSH from anywhere so AWS Config can detect the misconfiguration.
A screenshot of the AWS EC2 "Create security group" page showing an inbound rule for SSH (TCP port 22) with the source set to 0.0.0.0/0 (Anywhere-IPv4). The rule details and buttons like Delete/Add rule are visible.
  1. Create the security group and keep the Security Group details open — you will need the Group ID (for example: sg-07a079928389d2f42).
Step 2 — Confirm AWS Config is recording
  1. Open the AWS Config console in the same Region.
  2. In Settings, ensure the configuration recorder is ON. AWS Config must record the resource before it can evaluate it.
    • If recording was off when you created the security group, either recreate the SG or modify it after enabling recording so Config will capture the change.
Step 3 — Add the AWS-managed rule Restricted SSH
  1. In AWS Config → Rules → Add rule.
  2. Search for and select the managed rule restricted-ssh. This managed rule checks for security groups that allow unrestricted incoming SSH (port 22 from 0.0.0.0/0).
A screenshot of the AWS Management Console on the AWS Config "Add rule" page showing a rule named "restricted-ssh" with columns for Name, Resource types, Trigger type, and Description. The page footer shows "Cancel" and an orange "Next" button.
  1. Click Next. Give the rule a friendly name such as ssh-security-restriction-operation.
  2. Scope: keep default (Resources).
  3. Under Resources:
    • Resource type: AWS::EC2::SecurityGroup
    • Resource identifier: paste the Security Group ID you copied from the EC2 console so the rule evaluates only that SG.
  4. Frequency: leave at default (24 hours). We will re-evaluate manually for immediate checking. Save the rule.
A screenshot of the AWS EC2 console showing the Security Group details page for "ConfigSG" (sg-07a079928389d2f42), including owner ID, inbound/outbound rule counts and the associated VPC ID.
A screenshot of the AWS Management Console showing the AWS Config "Add rule" page. It shows an AWS EC2 SecurityGroup selected with resource identifier sg-07a079928389d2f42 and the frequency set to 24 hours.
Step 4 — Re-evaluate the rule to see non-compliance
  1. In AWS Config → Rules list, find ssh-security-restriction-operation.
  2. Select it, then choose Actions → Re-evaluate to trigger an immediate evaluation.
Wait a short time for evaluation. The rule should report the security group as Noncompliant because the SSH rule is open to the internet.
A screenshot of the AWS Config console displaying a list of Config Rules with columns for remediation action, type, evaluation mode, and compliance status. Several AWS-managed rules and status icons (compliant, noncompliant) are visible.
Step 5 — Configure automatic remediation
  1. In the Rules list select your rule and choose Actions → Manage remediation.
  2. Choose Automatic remediation to allow the Config rule to invoke a remediation action without manual steps.
Screenshot of the AWS Config console on a rule page (ssh-security-restriction-operation) showing a red error banner that says "There was an error rendering this widget." Below, the "Resources in scope" panel lists an EC2 security group (sg-07a07...) marked as Noncompliant.
  1. For the remediation action, select the Systems Manager Automation runbook AWS-DisablePublicAccessForSecurityGroup. This runbook will remove rules that allow public access (for example, port 22 from 0.0.0.0/0).
Screenshot of the AWS Config console on the "Edit: Remediation action" page showing options to select a remediation method, with "Automatic remediation" selected and "Manual remediation" as the alternative. The page includes explanatory text about retries and costs for auto-remediation.
A screenshot of the AWS Management Console (AWS Config → Rules → Manage remediation) showing a search box and a dropdown list of built-in remediation actions (e.g., AWS-DeleteEbsVolumeSnapshots, AWS-DeleteCloudFormationStack). The browser UI, account name, and footer toolbar (CloudShell, Agent Toolkit for AWS) are also visible.
  1. Parameters to configure:
    • GroupId: paste the security group ID.
    • AutomationAssumeRole: paste the ARN of an IAM role Systems Manager Automation can assume to change the security group.
Step 6 — Create an IAM role for Systems Manager Automation The runbook requires permission to modify your EC2 security group. Create an IAM role that SSM Automation can assume and attach the required policies.
  1. Open the IAM console → Roles → Create role.
  2. Trusted entity: AWS service → choose Systems Manager (ssm.amazonaws.com).
  3. Attach these demo policies:
    • AmazonSSMAutomationRole — enables Automation execution actions.
    • AmazonEC2FullAccess — used here for simplicity. In production, replace with a least-privilege policy scoped to only required EC2 actions.
  4. Name the role (for example NewConfigAutomaticRemediationRole) and create it.
  5. Copy the role ARN and paste it into the AutomationAssumeRole parameter on the Config remediation action, then Save the remediation.
A screenshot of the AWS Console showing the AWS Config "Manage remediation" page for an ssh-security-restriction-operation. It displays parameter fields with GroupId filled (sg-07a079928389d2f42) and empty entries for IpAddressToBlock and AutomationAssumeRole.
A screenshot of the AWS IAM console on the "Create role" page showing the "Permissions policies" section with AmazonEC2FullAccess selected. The search field shows "AmazonEC2Full" and one matching policy is displayed.
A screenshot of the AWS Identity and Access Management (IAM) console showing the role "NewConfigAutomaticRemediationRole" and its summary details (creation date, ARN, session duration). The left sidebar shows IAM navigation items like Roles, Policies, and IAM users.
Step 7 — Re-evaluate and verify remediation execution
  1. In AWS Config → Rules, re-select your rule and choose Actions → Re-evaluate. If the resource is Noncompliant, Config will trigger the configured automatic remediation using the Automation role you supplied.
  2. Open Systems Manager → Automation → Automation executions to view the runbook execution. You should see an execution for AWS-DisablePublicAccessForSecurityGroup with a status such as Success or Failed.
A screenshot of the AWS Systems Manager Automation console showing the "Automation executions" tab with a list of runbook executions (e.g., AWS-DisablePublicAccessForSecurityGroup) and action buttons like "Create runbook" and "Execute runbook."
  1. Verify in EC2 → Security Groups that the inbound public SSH rule has been removed by the runbook. In this demo the runbook removed all inbound rules.
A screenshot of the AWS EC2 Security Groups console showing the "Inbound rules" tab for a security group (no rules found). The page header shows the owner account ID and options to edit inbound rules.
  1. Re-evaluate the Config rule once more. The rule should now report the resource as Compliant.
Summary
  • AWS Config detects misconfigurations (for example, a security group allowing 0.0.0.0/0 for SSH).
  • AWS Config can trigger Systems Manager Automation runbooks to automatically remediate those misconfigurations.
  • Automation requires an IAM role with the appropriate permissions; follow the principle of least privilege when granting permissions for production.
When creating the Automation assume role, follow the principle of least privilege. The demo used AmazonEC2FullAccess for simplicity, but for production you should scope the role to only the specific EC2 actions required by the runbook.

Watch Video