Ensure S3 Bucket Policy is set to deny HTTP requests
Description
At the Amazon S3 bucket level, permissions can be configured through a bucket policy to ensure objects are accessible only through HTTPS.
Rationale
By default, Amazon S3 allows both HTTP and HTTPS requests. To ensure that access to S3 objects is only permitted through HTTPS, you must explicitly deny HTTP requests. Bucket policies that allow HTTPS requests without explicitly denying HTTP requests do not meet this requirement.
Impact
If HTTP access is not explicitly denied, data transmitted to and from S3 buckets may be exposed to interception or man-in-the-middle attacks.
Audit Procedure
Using AWS Console
- Login to the AWS Management Console and open the Amazon S3 console using https://console.aws.amazon.com/s3/
- Select the target bucket
- Select the 'Permissions' tab
- Select
Bucket policy - Ensure a policy exists that explicitly denies HTTP requests using one of the following conditions:
Option 1: Deny non-HTTPS requests
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::<bucket_name>/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
Option 2: Enforce minimum TLS version
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::<bucket_name>", "arn:aws:s3:::<bucket_name>/*"],
"Condition": {
"NumericLessThan": {
"s3:TlsVersion": "1.2"
}
}
}
- Repeat for all S3 buckets
Using AWS CLI
- List all of the S3 Buckets:
aws s3 ls
- For each bucket, run:
aws s3api get-bucket-policy --bucket <bucket_name> | grep aws:SecureTransport
or
aws s3api get-bucket-policy --bucket <bucket_name> | grep s3:TlsVersion
Verify the policy includes either:
"aws:SecureTransport": "false"with"Effect": "Deny"- or a TLS version restriction using
"s3:TlsVersion"
If no policy is returned, the bucket allows both HTTP and HTTPS requests by default
Expected Result
Each S3 bucket should have a bucket policy that explicitly denies HTTP requests either by using the aws:SecureTransport condition set to false with a Deny effect, or by enforcing a minimum TLS version using the s3:TlsVersion condition.
Remediation
Using AWS Console
- Sign in to the AWS Management Console and open the Amazon S3 console
- Select the bucket
- Select the
Permissionstab - Select
Bucket policy - Add one of the following statements to the policy
Deny HTTP requests:
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::<bucket_name>/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
Enforce TLS version:
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::<bucket_name>", "arn:aws:s3:::<bucket_name>/*"],
"Condition": {
"NumericLessThan": {
"s3:TlsVersion": "1.2"
}
}
}
- Save the policy
- Repeat for all relevant buckets
Using AWS Policy Generator:
- Repeat steps 1-4 above
- Click on
Policy Generatorat the bottom of the Bucket Policy editor - Select
S3 Bucket Policyas the policy type - Configure the statement:
Effect= DenyPrincipal= *AWS Service= Amazon S3Actions= *Amazon Resource Name=
- Select
Generate Policy - Copy the generated policy and add it to the bucket policy
Using AWS CLI
- Export the existing policy, if one exists:
aws s3api get-bucket-policy --bucket <bucket_name> --query Policy --output text > policy.json
If the bucket does not already have a policy, create a new policy.json file containing a valid bucket policy document.
- Modify
policy.jsonto include one of the following deny statements within theStatementarray.
Option 1: Deny HTTP requests
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::<bucket_name>/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
Option 2: Enforce minimum TLS version
{
"Sid": "<optional>",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::<bucket_name>", "arn:aws:s3:::<bucket_name>/*"],
"Condition": {
"NumericLessThan": {
"s3:TlsVersion": "1.2"
}
}
}
- Apply the modified policy back to the S3 bucket:
aws s3api put-bucket-policy --bucket <bucket_name> --policy file://policy.json
Default Value
By default, Amazon S3 accepts both HTTP and HTTPS requests. No bucket policy is applied to deny unencrypted (HTTP) access unless explicitly configured.
References
- https://aws.amazon.com/premiumsupport/knowledge-center/s3-bucket-policy-for-config-rule/
- https://aws.amazon.com/blogs/security/how-to-use-bucket-policies-and-apply-defense-in-depth-to-help-secure-your-amazon-s3-data/
- https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-bucket-policy.html
CIS Controls
| Controls Version | Control | IG 1 | IG 2 | IG 3 |
|---|---|---|---|---|
| v8 | 3.10 Encrypt Sensitive Data in Transit | x | x | |
| v7 | 14.4 Encrypt All Sensitive Information in Transit | x | x |
MITRE ATT&CK Mappings
| Techniques / Sub-techniques | Tactics | Mitigations |
|---|---|---|
| T1040 | TA0006, TA0007 | M1041 |
Profile
Level 2 | Automated