S3 Bucket Public ACL Overridden By Public Access Block
- Query id: bf878b1a-7418-4de3-b13c-3a86cf894920
- Query name: S3 Bucket Public ACL Overridden By Public Access Block
- Platform: Terraform
- Severity: Low
- Category: Access Control
- URL: Github
Description¶
S3 bucket public access is overridden by S3 bucket Public Access Block when the following attributes are set to true - 'block_public_acls', 'block_public_policy', 'ignore_public_acls', and 'restrict_public_buckets'
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - tf file
provider "aws" {
region = "us-east-1"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
resource "aws_s3_bucket" "public-bucket" {
bucket = "bucket-with-public-acl-3"
acl = "public-read-write"
}
resource "aws_s3_bucket_public_access_block" "block_public_bucket_3" {
bucket = aws_s3_bucket.public-bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Positive test num. 2 - tf file
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "3.7.0"
bucket = "my-s3-bucket"
acl = "public-read-write"
versioning = {
enabled = true
}
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Positive test num. 3 - tf file
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.2.0"
}
}
}
provider "aws" {
# Configuration options
}
resource "aws_s3_bucket" "bu" {
bucket = "my-tf-test-bucket"
}
resource "aws_s3_bucket_acl" "example_bucket_acl" {
bucket = aws_s3_bucket.bu.id
acl = "public-read-write"
}
resource "aws_s3_bucket_public_access_block" "block_public_bucket_3" {
bucket = aws_s3_bucket.bu.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Code samples without security vulnerabilities¶
Negative test num. 1 - tf file
provider "aws" {
region = "us-east-1"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
resource "aws_s3_bucket" "public-bucket2" {
bucket = "bucket-with-public-acl-32"
acl = "public-read-write"
}
resource "aws_s3_bucket_public_access_block" "block_public_bucket_32" {
bucket = aws_s3_bucket.public-bucket2.id
block_public_acls = false
block_public_policy = true
ignore_public_acls = false
restrict_public_buckets = true
}
Negative test num. 2 - tf file
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "3.7.0"
bucket = "my-s3-bucket"
acl = "public-read-write"
versioning = {
enabled = true
}
block_public_acls = false
block_public_policy = true
ignore_public_acls = false
restrict_public_buckets = true
}
Negative test num. 3 - tf file
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.2.0"
}
}
}
provider "aws" {
# Configuration options
}
resource "aws_s3_bucket" "bu2" {
bucket = "my-tf-test-bucket"
}
resource "aws_s3_bucket_acl" "example_bucket_acl2" {
bucket = aws_s3_bucket.bu2.id
acl = "public-read-write"
}
resource "aws_s3_bucket_public_access_block" "block_public_bucket_322" {
bucket = aws_s3_bucket.bu2.id
block_public_acls = false
block_public_policy = true
ignore_public_acls = false
restrict_public_buckets = true
}