Triage and Remediation
Remediation
Using Console
Using Console
Sure, here are the steps to remediate the issue of EC2 AMIs being public in AWS using the AWS console:
- Login to your AWS console.
- Go to the EC2 dashboard.
- Click on the “AMIs” option in the left-hand menu.
- Select the AMI that you want to remediate.
- Click on the “Modify Image Permissions” button.
- In the “Modify Image Permissions” dialog box, select “Private” as the new permission.
- Click on the “Save” button to apply the new permission.
- Repeat the above steps for all the public AMIs that you want to remediate.
- Once you have changed the permissions for all the public AMIs, verify that they are no longer public by checking the “Permissions” column in the AMIs dashboard.
- If any AMIs are still public, repeat the above steps for those AMIs.
Using CLI
Using CLI
To remediate the misconfiguration “EC2 AMIs Should Not Be Public” for AWS using AWS CLI, follow these steps:
- Log in to your AWS account and open the AWS CLI.
-
Run the following command to check if there are any public AMIs in your AWS account:
-
If there are any public AMIs, you can make them private by running the following command:
Replace
<image-id>
with the ID of the AMI you want to make private. -
After running the command, verify that the AMI is no longer public by running the following command:
Replace
<image-id>
with the ID of the AMI you just made private. - Repeat steps 3-4 for all public AMIs in your AWS account.
-
Once you have made all the necessary AMIs private, you can prevent future public AMIs by setting the default AMI permissions to private. Run the following command:
Replace
ami-00000000000000000
with the ID of any private AMI in your account. -
After running the command, verify that the default AMI permissions have been set to private by running the following command:
Replace
ami-00000000000000000
with the ID of the AMI you used in step 6.
Using Python
Using Python
To remediate the issue of EC2 AMIs being public in AWS using Python, you can follow the below steps:Step 1: Identify the public EC2 AMIs in your AWS account using boto3 library in Python.Step 2: Deregister the public EC2 AMIs using the Step 3: Modify the EC2 AMI permissions to make them private using the Note: Before making any changes to your AWS account, it is recommended to test the code in a non-production environment and ensure that it is working as expected.
deregister_image()
method.modify_image_attribute()
method.