- Create a security group with an intentionally insecure inbound SSH rule (
0.0.0.0/0). - Add the AWS Config managed rule
restricted-sshscoped 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.
Step 1 — Create an insecure security group
- Open the EC2 console → Security Groups.
- Create a new security group (e.g., name
config-sg) in your default VPC. - Add an inbound rule:
- Type: SSH (TCP 22)
- Source:
0.0.0.0/0(Anywhere-IPv4)

- Create the security group and keep the Security Group details open — you will need the Group ID (for example:
sg-07a079928389d2f42).
- Open the AWS Config console in the same Region.
- 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.
- In AWS Config → Rules → Add rule.
- Search for and select the managed rule
restricted-ssh. This managed rule checks for security groups that allow unrestricted incoming SSH (port 22 from0.0.0.0/0).

- Click Next. Give the rule a friendly name such as
ssh-security-restriction-operation. - Scope: keep default (Resources).
- 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.
- Resource type:
- Frequency: leave at default (24 hours). We will re-evaluate manually for immediate checking. Save the rule.


- In AWS Config → Rules list, find
ssh-security-restriction-operation. - Select it, then choose Actions → Re-evaluate to trigger an immediate evaluation.

- In the Rules list select your rule and choose Actions → Manage remediation.
- Choose Automatic remediation to allow the Config rule to invoke a remediation action without manual steps.

- 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 from0.0.0.0/0).


- 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.
- Open the IAM console → Roles → Create role.
- Trusted entity: AWS service → choose Systems Manager (
ssm.amazonaws.com). - 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.
- Name the role (for example
NewConfigAutomaticRemediationRole) and create it. - Copy the role ARN and paste it into the
AutomationAssumeRoleparameter on the Config remediation action, then Save the remediation.



- 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.
- Open Systems Manager → Automation → Automation executions to view the runbook execution. You should see an execution for
AWS-DisablePublicAccessForSecurityGroupwith a status such as Success or Failed.

- 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.

- Re-evaluate the Config rule once more. The rule should now report the resource as Compliant.
- AWS Config detects misconfigurations (for example, a security group allowing
0.0.0.0/0for 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.