AWS S3 Access Logs

In this guide, you will configure Guardrails to enforce S3 access logging on every bucket within an AWS account. You'll set the access logging destination so logs are shipped to another bucket within the same account, and add a key prefix so log files are stored in a folder called Access-Logs/.

[!TIP] This configuration can also be deployed using Terraform. See the Guardrails Samples Repo for policy pack examples.

[!IMPORTANT] This guide is for account-owned S3 buckets. Guardrails deploys its own logging buckets to AWS accounts upon import if the policy AWS > Turbot > Logging > Bucket is set to Enforce: Configured. To enable access logging on Guardrails logging buckets, use the policy AWS > Turbot > Logging > Bucket > Access Logging (set to Enabled) along with AWS > Turbot > Logging > Bucket > Access Logging > Bucket and AWS > Turbot > Logging > Bucket > Access Logging > Bucket > Key Prefix, not the policies described in this guide.

Prerequisites

Step 1: Configure the Key Prefix

Click New Policy Setting in the top right of the Policies page to open the Create Policy Setting form.

For the Policy Type, search for access logging key prefix and select Key Prefix (AWS > S3 > Bucket > Access Logging > Key Prefix). For the Resource, select the AWS account where the setting will live. The setting affects all S3 buckets at this level and below in the policy hierarchy.

Because this policy is a free-text value, the Setting shows a text field. Enter the prefix for access logs. For this example, enter Access-Logs/ to store log files in a folder called Access-Logs.

Note the trailing slash. Without it, AWS appends the prefix text directly to the beginning of the log file name. For example, if the prefix is Access-Logs (no slash) and the log file is named aws-access-logs-123, the result is Access-Logsaws-access-logs-123. You can also use multiple slashes to create nested folders, such as Access-Logs/foo/bar/.

Click Create.

Create Policy Setting form for AWS S3 Bucket Access Logging Key Prefix set to Access-Logs/

Step 2: Configure the Destination Bucket

Click New Policy Setting again. For the Policy Type, search for access logging bucket and select Bucket (AWS > S3 > Bucket > Access Logging > Bucket). Select the same Resource scope.

In the Setting field, enter the name of the bucket that should receive the access logs (for example goliath-federal-access-logs). The destination bucket must already exist in the same account and region.

Click Create.

Create Policy Setting form for AWS S3 Bucket Access Logging Bucket set to goliath-federal-access-logs

Step 3: Enforce Access Logging

Click New Policy Setting. For the Policy Type, search for s3 access logging and select Access Logging (AWS > S3 > Bucket). Select the same Resource scope.

This policy is an enum, so the Setting shows the available values as radio buttons:

ValueBehavior
SkipAccess logging is not evaluated for S3 buckets.
Check: EnabledChecks whether access logging is enabled and raises an alarm if not, but makes no changes.
Check: Enabled to Access Logging > BucketAdditionally checks that logs are being sent to the destination bucket configured in Step 2.
Enforce: DisabledDisables access logging on buckets that have it enabled.
Enforce: Enabled to Access Logging > BucketEnables access logging on non-compliant buckets and configures the destination bucket and key prefix.

Select Enforce: Enabled to Access Logging > Bucket, then click Create.

Create Policy Setting form for AWS S3 Bucket Access Logging set to Enforce: Enabled to Access Logging > Bucket

Step 4: Verify the Configuration

Verify that the policy is taking effect by navigating to any S3 bucket that should now have access logging configured and checking its metadata. Alternatively, generate access logs by performing an action on an object in a bucket (such as viewing an object), then check the destination bucket to confirm that log files are being stored in the Access-Logs/ folder.

Navigate to Controls in the left sidebar and filter for AWS > S3 > Bucket > Access Logging to see the control states across all buckets in scope.

Next Steps