Skip to main content

More Info:

Non-default security groups were defined which were unused and may not be required. This being the case, their existence in the configuration increases the risk that they may be inappropriately assigned. The unused security groups should be reviewed and removed if no longer required.

Risk Level

Low

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • AWS Startup Security Baseline
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • Cloudanix Best Practice
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • ISO/IEC 27017
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

To remediate the issue of unused security groups in AWS, follow these steps using the AWS Management Console:
  1. Sign in to the AWS Management Console: Go to https://aws.amazon.com/ and sign in to your AWS account.
  2. Navigate to the EC2 Dashboard: Click on the “Services” dropdown menu at the top of the page, select “EC2” under the Compute section.
  3. View Security Groups: In the EC2 Dashboard, locate the “Security Groups” option in the navigation pane on the left and click on it.
  4. Identify Unused Security Groups: Review the list of security groups to identify the ones that are not associated with any running instances or resources. You can check the “Description” tab of each security group to see if it is actively being used.
  5. Check Rules and Dependencies: Before deleting a security group, ensure that there are no dependencies on it. Check if any other resources are using the security group for inbound/outbound rules.
  6. Delete Unused Security Groups: To delete a security group, select the checkbox next to the security group(s) you want to remove, click on the “Actions” dropdown menu, and select “Delete security group”.
  7. Confirm Deletion: A confirmation dialog will appear asking you to confirm the deletion. Review the security group details once more and click “Yes, Delete” to confirm.
  8. Verify Deletion: Once the security group is deleted, verify that it has been removed from the list of security groups. Also, ensure that there are no adverse effects on any resources due to the deletion.
  9. Repeat if Necessary: Repeat the above steps for any other unused security groups that need to be removed.
By following these steps, you can identify and remove unused security groups in AWS using the AWS Management Console. This helps in maintaining a clean and secure environment by reducing the attack surface and minimizing the risk of misconfigurations.

To remediate the issue of unused security groups in AWS using AWS CLI, follow these steps:
  1. List all the security groups that are not associated with any EC2 instances:
  1. Identify the security group that you want to delete from the list obtained in the previous step.
  2. Delete the unused security group using the following command:
Make sure to replace YOUR_SECURITY_GROUP_ID with the actual ID of the security group you want to delete.
  1. Confirm the deletion by listing the security groups again:
By following these steps, you can remediate the issue of unused security groups in AWS using AWS CLI.
To remediate the issue of unused security groups in AWS using Python, you can follow these steps:
  1. Install the Boto3 library:
  1. Use the following Python script to identify and delete unused security groups:
  1. Replace the AWS credentials in the AWS CLI configuration file located at ~/.aws/credentials or use an IAM role that has the necessary permissions to list and delete security groups.
  2. Run the Python script to identify and delete the unused security groups.
Please ensure that you have the necessary permissions to delete security groups before running this script.
Removing the aws_security_group block from Terraform corresponds to running aws ec2 delete-security-group for that group: on terraform plan you should see a - destroy action for each unused security group resource that you removed from the configuration and no changes for the ones you kept.

Additional Reading: