Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the unrestricted PostgreSQL access issue in AWS, you can follow the below steps:
  1. Go to the AWS Management Console and navigate to the RDS dashboard.
  2. Select the RDS instance that has unrestricted PostgreSQL access.
  3. Click on the “Modify” button.
  4. In the “Network & Security” section, select the “Additional Configuration” tab.
  5. Under “Security Group Rules,” locate the rule that allows unrestricted PostgreSQL access.
  6. Remove the rule by clicking on the “x” icon next to it.
  7. Add a new rule that allows access only from trusted sources.
  8. Click on the “Save Changes” button.
By following these steps, you can remediate the unrestricted PostgreSQL access issue in AWS and ensure that your PostgreSQL database is only accessible from trusted sources.

To remediate unrestricted PostgreSQL access in AWS, you can follow these steps using AWS CLI:
  1. Open the AWS CLI and run the following command to get the security group ID of the security group associated with the PostgreSQL instance:
  2. Run the following command to get the ID of the security group:
  3. Run the following command to revoke the unrestricted access to PostgreSQL:
    This command will revoke the inbound rule that allows unrestricted access to PostgreSQL.
  4. Run the following command to verify that the unrestricted access has been revoked:
    This command will show the current inbound rules for the security group. You should see that the rule allowing unrestricted access to PostgreSQL has been removed.
By following these steps, you have successfully remediated the unrestricted PostgreSQL access in AWS.
To remediate the unrestricted PostgreSQL access issue in AWS, you can use Python to create a security group that allows access to the PostgreSQL instance only from a specific IP address or range of IP addresses. Here are the steps to do so:
  1. First, you need to create a new security group that will be used to restrict access to the PostgreSQL instance. You can do this using the boto3 library in Python. Here’s an example code snippet that creates a new security group:
  1. Once you’ve created the new security group, you need to assign it to the PostgreSQL instance. You can do this using the modify_db_instance method from the boto3 library. Here’s an example code snippet that assigns the new security group to the PostgreSQL instance:
  1. Finally, you can verify that the access to the PostgreSQL instance has been restricted by checking the security group rules associated with the instance. You can do this using the describe_db_instances method from the boto3 library. Here’s an example code snippet that checks the security group rules:
This code will print the security group rules associated with each security group, which should show that access to the PostgreSQL port (5432) is only allowed from the specific IP address or range of IP addresses that you specified in the security group rule.
This Terraform must not contain any ingress rule with from_port = 5432 / to_port = 5432 and cidr_blocks = ["0.0.0.0/0"] or ipv6_cidr_blocks = ["::/0"]; that matches the CLI revoke-security-group-ingress for those CIDRs.This change updates only the security group rules; it does not replace the security group resource itself, but the affected ingress rules will be destroyed and recreated with the new, restricted CIDRs. This is irreversible in the same sense as the CLI: once applied, the open rule is permanently removed and access will be limited to the trusted ranges you specify.Verification: terraform plan should show ~ (update) on aws_security_group.POSTGRES_SG with - removals of the 0.0.0.0/0 and/or ::/0 ingress rules on port 5432, and + additions (if you defined new restricted rules) for the trusted CIDRs.