Skip to main content

More Info:

There should not be an excessive number of security groups in the account. AWS applies the most permissive rule amongst all the Security Groups assigned to any EC2 instance.

Risk Level

Informational

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • 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)
  • Essential 8
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • 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 having an excessive number of security groups in AWS, you can follow these steps using the AWS Management Console:
  1. Identify Unused Security Groups:
    • Go to the AWS Management Console and navigate to the EC2 dashboard.
    • Click on the ‘Security Groups’ option in the left-hand menu to view all the security groups in your account.
    • Review each security group and identify the ones that are not associated with any EC2 instances or other resources.
  2. Remove Unused Security Groups:
    • Select the unused security groups that you want to delete by checking the box next to each one.
    • Click on the ‘Actions’ dropdown menu at the top, and select ‘Delete security group’.
    • Confirm the deletion when prompted.
  3. Update Security Group Rules:
    • Review the remaining security groups to ensure that they have the necessary and correct inbound and outbound rules.
    • Remove any unnecessary rules that are overly permissive or no longer needed.
  4. Consolidate Security Groups:
    • If you have multiple security groups with similar rules, consider consolidating them into fewer security groups to simplify management.
    • Update the security group associations for your resources to use the consolidated security groups.
  5. Implement Security Group Naming Conventions:
    • Establish a naming convention for your security groups to easily identify their purpose and associated resources.
    • Rename the security groups accordingly to maintain consistency and organization.
  6. Regularly Audit Security Groups:
    • Schedule periodic reviews of your security groups to identify and remove any unused or redundant ones.
    • Ensure that security groups are properly configured and adhere to your organization’s security policies.
By following these steps, you can remediate the issue of having an excessive number of security groups in AWS and improve the security posture of your cloud environment.

To remediate the excessive number of security groups in AWS using AWS CLI, you can follow these steps:
  1. List all Security Groups: First, you need to list all the existing security groups in your AWS account to identify the excessive ones. You can use the following AWS CLI command to list all security groups:
  1. Identify Excessive Security Groups: Review the list of security groups returned by the above command and identify the ones that are not necessary or are excessive.
  2. Delete Excessive Security Groups: To delete a security group, you can use the following AWS CLI command:
Replace YOUR_SECURITY_GROUP_ID with the actual ID of the security group you want to delete. Make sure to only delete the security groups that are not required and do not impact your existing resources.
  1. Repeat as Necessary: Repeat the above steps for each excessive security group that needs to be deleted.
  2. Monitor and Test: After deleting the excessive security groups, monitor your resources to ensure that the necessary security groups are in place and that the deletion of the excessive ones did not impact your applications or services.
By following these steps, you can remediate the issue of having an excessive number of security groups in your AWS account using AWS CLI.
To remediate the excessive number of security groups in AWS using Python, you can use the Boto3 library, which is the AWS SDK for Python. Below are the step-by-step instructions to identify and clean up the excessive security groups:
  1. Install the Boto3 library:
  1. Create a Python script (e.g., remediate_security_groups.py) with the following code:
  1. Run the Python script using the following command:
This script will identify security groups with more than one rule and delete them. Make sure you have the necessary permissions to delete security groups in your AWS account before running this script.
This change does not force replacement of the EC2 instance; Terraform will update the vpc_security_group_ids in-place, which immediately replaces the effective set of security groups and can break connectivity if the consolidated rules are incomplete. The manual analysis and staged-attachment warnings from the CLI remediation still apply.For verification, terraform plan should show:
  • A new aws_security_group.CONSOLIDATED_SG to be created (if it doesn’t already exist).
  • An in-place update to aws_instance.EC2_INSTANCE where vpc_security_group_ids changes from the previous list of many security groups to the new, consolidated list you specify.

Additional Reading: