Description: 

Security groups provide state full filtering of ingress/egress network traffic to AWS resources. It is recommended that no security group allows unrestricted ingress access to MySQL ports 3306.

If restricted ingress access to MySQL ports means we do not allow to access my database.


Rationale: 

Removing unfettered connectivity to remote console services, and nobody will access my internal database server or Oracle, reduces a database server’s exposure to risk. Ensure no security groups allow ingress from 0.0.0.0/0 or::/0 to MySQL port 3306.


Impact:

If we do not allow unrestricted ingress/inbound access to MySQL port 3306 It can have minimised the opportunities for malicious activity such as hacking, data loss, and all multiple types of attacks( brute-force attacks, Denial of Service (DoS) attacks, etc).

For updating an existing environment, care should be taken to ensure that administrators currently relying on an existing ingress from 0.0.0.0/0 have access to MySQL port 3306 through another security group. 


Default Value:

Inbound

Type

Protocol

Port Range

Source

Description

All traffic

All

All

Security Groupaws ec2 delete-security-group --group-id <security_group_id> ID
(e.g.:- sg-dedc3c97 / default)

For the associated instances, inbound traffic allows network interfaces that are assigned to the same security group.

Audit:

  1. Sign in to the AWS Management Console.

  2. Navigate to EC2 dashboard at https://console.aws.amazon.com/ec2/.

  3. Click on Security Groups, under NETWORK & SECURITY section, in the left navigation pane

  4. Verify the value in the Source column for any inbound rules with the Port Range set to 3306 have the source set to 0.0.0.0/0 or ::/0 (Anywhere), then the selected security group allows unrestricted data traffic on port 3306.


Remediation:

Pre-Requisite:

  1. Before start, the below implementation steps write all configuration which IP and which port in the inbound.

  2. Avoid the login through the Root user.

  3. Only authorized persons (i.e, admins) can access the Security Groups.

  4. You cannot delete the default security groups but you can edit and modify them but here so you can create security groups and create your own rules in them.

  5. Do not attach the default security group to any EC2 instance if you do not modify any default rules in inbound or outbound.

  6. When you will use the services MySQL Port 3306 as a database server.


Implementation Steps:

Step 1: Sign in to the AWS Management Console.

Step 2: Go to EC2 dashboard at https://console.aws.amazon.com/ec2/.

Step 3: Click on Security Groups, under NETWORK & SECURITY section, in the left navigation pane

Step 4: Select the appropriate security group (see Audit section to identify the right one(s)).

Step 5: Select the Inbound tab and click the Edit inbound rules button.

Step 6: In the Edit inbound rules dialog box, go to source column and perform one of the following actions to restrict the inbound traffic: Click on source dropdown

  1. Select My IP to allow inbound traffic only from your machine (i.e, from your IP address only).

  2. Select Custom and enter IP addresses or name or ID of another security group based on your access requirements


Step 7: Click Save to apply the changes.


Back out Plan:

If you want to proceed with previous settings go through the Implementation steps section and set all previous policies that you have written somewhere.

 

Or else you can delete the security group you created

Step 1:Sign in to the AWS Management Console.

Step 2:Go to EC2 dashboard at https://console.aws.amazon.com/ec2/.

Step 3: Click on Security Groups, under NETWORK & SECURITY section, in the left navigation pane

Step 4: Open the security group by clicking on security group ID

Step 5: Click on Actions dropdown and select Delete Security groups


Via CLI:

The following command is used to delete created security group id in the security_group_id enter the security group id which you show on your console.

aws ec2 delete-security-group --group-id <security_group_id>


Reference:

  1. https://docs.aws.amazon.com/cli/latest/reference/ec2/revoke-security-group-ingress.html

  2. https://docs.aws.amazon.com/cli/latest/reference/lightsail/get-instance-port-states.html

  3. https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html

  4. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-ingress.html