Allow read access to S3
The IAM roles used to create Terraform plans and deploying applications come with built-in restrictions by default. In some cases, it can be useful to relax some of these restrictions, for example if you have an S3 bucket containing non-sensitive configuration that your Terraform stack needs to fetch during plan/apply.
This optional guide shows how to allow CI/CD to read your S3 buckets. Skip it if the default access is enough.
Before you begin
cicd-commonis installed in the environment.- Familiarize yourself with the key points from the risk assessment analysis (ROS).
The tag-based mechanism is the recommended option, but if that's difficult for some reason, or you want to choose exactly which objects can be read, specify those objects instead. You can combine both option A and B.
Option A: Tag the bucket
The bucket needs the TerraformAutomationReadAccess = "true" tag and ABAC enabled. Golden Path stacks set the Environment tag on every resource. If you create the bucket some other way, set the Environment tag yourself.
For a bucket made with the public terraform-aws-modules/s3-bucket module, add the TerraformAutomationReadAccess tag and enable ABAC yourself.
module "bucket" {
# ...
tags = {
TerraformAutomationReadAccess = "true"
}
}
resource "aws_s3_bucket_abac" "bucket" {
bucket = module.bucket.s3_bucket_id
abac_status {
status = "Enabled"
}
}
ABAC changes how the bucket is tagged
Once ABAC is enabled, S3 refuses PutBucketTagging and DeleteBucketTagging on the bucket, and tags change only through TagResource and UntagResource.
Option B: Allow specific S3 buckets
Grant read access to a bucket explicitly by adding S3 object ARN patterns:
locals {
s3_read_exemptions = [
"arn:aws:s3:::my-team-data/*", # (1)!
"arn:aws:s3:::my-team-config/settings/*", # (2)!
"arn:aws:s3:::my-team-config/settings/application-settings.json", # (3)!
]
}
- Every object in the bucket.
- Only objects under one prefix. Keep the grant as narrow as the read needs.
- Only a single object. The grant is as narrow as possible.
Each entry names one bucket and a key pattern.