S3 Allows Authenticated Write Acp Remediation
Triage and Remediation
- Remediation
Remediation
Using Console
To remediate the "S3 Bucket Should Not Allow WRITE_ACP Access to Authenticated Users" misconfiguration in AWS, you can follow these steps using the AWS console:
-
Log in to the AWS Management Console.
-
Navigate to the S3 service.
-
Click on the name of the bucket that you want to remediate.
-
Click on the "Permissions" tab.
-
Click on the "Access control list (ACL)" button.
-
Under the "Grantee" column, find the row that has "Authenticated Users".
-
In the "Permission" column, find the "WRITE_ACP" permission.
-
Click on the "x" button to remove the "WRITE_ACP" permission for "Authenticated Users".
-
Click on the "Save" button to save the changes.
-
Verify that the "Authenticated Users" group no longer has the "WRITE_ACP" permission by checking the "Access control list (ACL)" again.
-
Repeat these steps for any other S3 buckets that have the same misconfiguration.
Note: You can also use AWS CLI or AWS SDKs to remediate this misconfiguration.
Using CLI
To remediate the misconfiguration "S3 Bucket Should Not Allow WRITE_ACP Access to Authenticated Users" for AWS using AWS CLI, follow these steps:
-
Open the AWS CLI on your local machine.
-
Run the following command to get a list of all S3 buckets in your AWS account:
aws s3api list-buckets -
Identify the S3 bucket that has WRITE_ACP access granted to authenticated users.
-
Run the following command to revoke WRITE_ACP access for authenticated users:
aws s3api put-bucket-acl --bucket bucket-name --grant-write-acp uri=http://acs.amazonaws.com/groups/global/AuthenticatedUsers --acl privateReplace "bucket-name" with the name of the S3 bucket that you want to remediate.
-
Verify that WRITE_ACP access for authenticated users has been revoked by running the following command:
aws s3api get-bucket-acl --bucket bucket-nameReplace "bucket-name" with the name of the S3 bucket that you want to remediate.
-
Repeat the above steps for all S3 buckets that have WRITE_ACP access granted to authenticated users.
By following these steps, you can remediate the misconfiguration "S3 Bucket Should Not Allow WRITE_ACP Access to Authenticated Users" for AWS using AWS CLI.
Using Python
To remediate the misconfiguration of allowing WRITE_ACP access to authenticated users in an AWS S3 bucket using Python, follow these steps:
- Create an AWS S3 client using the AWS SDK for Python (Boto3).
- Get the bucket policy using the
get_bucket_policy()method of the S3 client. - Parse the JSON policy to identify the statement that allows WRITE_ACP access to authenticated users.
- Remove the identified statement from the policy.
- Update the bucket policy using the
put_bucket_policy()method of the S3 client.
Here's the Python code to remediate the misconfiguration:
import boto3
import json
# Create an S3 client
s3 = boto3.client('s3')
# Get the bucket policy
bucket_name = 'your-bucket-name'
policy = s3.get_bucket_policy(Bucket=bucket_name)
# Parse the JSON policy
policy_json = json.loads(policy['Policy'])
statements = policy_json['Statement']
# Identify the statement that allows WRITE_ACP access to authenticated users
for statement in statements:
if 'Principal' in statement and statement['Principal'] == {'AWS': '*'}:
if 'Action' in statement and 's3:PutObjectAcl' in statement['Action']:
if 'Condition' in statement and 'Bool' in statement['Condition']:
if 'aws:SecureTransport' in statement['Condition']['Bool'] and statement['Condition']['Bool']['aws:SecureTransport'] == 'false':
# Remove the identified statement from the policy
policy_json['Statement'].remove(statement)
# Update the bucket policy
s3.put_bucket_policy(Bucket=bucket_name, Policy=json.dumps(policy_json))
This code will remove the statement that allows WRITE_ACP access to authenticated users from the S3 bucket policy.
Using Terraform
# Existing S3 bucket
resource "aws_s3_bucket" "this" {
bucket = "BUCKET_NAME" # replace with your bucket name
}
############################################
# Option 1 (matches put-bucket-acl --acl private)
# WARNING: This REPLACES the entire ACL; all existing grants are removed.
############################################
resource "aws_s3_bucket_acl" "this" {
bucket = aws_s3_bucket.this.id
acl = "private"
}
############################################
# Option 2 (matches put-bucket-ownership-controls with BucketOwnerEnforced)
# WARNING: This disables all ACLs; only IAM/bucket policies will control access.
# Recommended AWS best practice.
############################################
resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.this.id
rule {
object_ownership = "BucketOwnerEnforced"
}
}
Both changes are in-place on the existing bucket (no bucket replacement), but they can immediately impact who has access.
Verification with terraform plan:
- For Option 1, plan should show creation/update of
aws_s3_bucket_acl.thiswithacl = "private"and removal of any prior ACL configuration. - For Option 2, plan should show creation/update of
aws_s3_bucket_ownership_controls.thiswithobject_ownership = "BucketOwnerEnforced".