Review HTTPS enforcement for the S3 bucket

Block unencrypted HTTP requests to S3.

Description

To require HTTPS, deny requests with aws:SecureTransport set to false on both the bucket ARN and its object ARNs. An HTTPS-only allow leaves HTTP access granted by other policies in place.

Potential impact

Requests, uploads and downloads sent over HTTP can be read or altered in transit, even when the client is authorized.

Remediation

Configure clients for HTTPS and keep necessary permissions and network restrictions. AWS service-to-service calls can omit network context. Scope any needed service-principal exception with aws:PrincipalIsAWSService and verify both the integration and the HTTP denial.

Examples

Define aws_s3_bucket.b separately. The first statement denies the specified source IP. Retain required IP restrictions when adding HTTPS enforcement to your policy.

Before

hcl
resource "aws_s3_bucket_policy" "example" {
  bucket = aws_s3_bucket.b.id

  policy = <<EOF
{
    "Version": "2012-10-17",
    "Id": "MYBUCKETPOLICY",
    "Statement": [
      {
        "Sid": "IPAllow",
        "Effect": "Deny",
        "Principal": "*",
        "Action": "s3:*",
        "Resource": [
          "${aws_s3_bucket.b.arn}",
          "${aws_s3_bucket.b.arn}/*"
        ],
        "Condition": {
          "IpAddress": {
            "aws:SourceIp": "8.8.8.8/32"
          }
        }
      }
    ]
}
EOF
}

After

hcl
resource "aws_s3_bucket_policy" "example" {
  bucket = aws_s3_bucket.b.id

  policy = <<EOF
{
    "Version": "2012-10-17",
    "Id": "MYBUCKETPOLICY",
    "Statement": [
      {
        "Sid": "IPAllow",
        "Effect": "Deny",
        "Principal": "*",
        "Action": "s3:*",
        "Resource": [
          "${aws_s3_bucket.b.arn}",
          "${aws_s3_bucket.b.arn}/*"
        ],
        "Condition": {
          "Bool": {
            "aws:SecureTransport": "false"
          }
        }
      }
    ]
}
EOF
}

The second replaces the IP condition with a transport condition that denies HTTP to the bucket and its objects. HTTPS callers still need a separate grant.

References