Preventing S3 Infinite Logging Loops
Abstract
Amazon Simple Storage Service (Amazon S3) provides two distinct observability mechanisms for auditing bucket operations: S3 Server Access Logging and AWS CloudTrail S3 Data Events. While CloudTrail records IAM identity attribution for AWS API requests, S3 Server Access Logging delivers low-latency, HTTP-level request diagnostics including detailed HTTP status codes, byte turnarounds, TLS cipher suites, and bucket-owner access records without incurring per-event CloudTrail Data Event fees.
However, enabling S3 Server Access Logging without strict architectural isolation introduces one of the most catastrophic misconfigurations in cloud security: the infinite recursive logging loop. If a bucket is configured to deliver its access logs to itself, or if server access logging is enabled on a bucket designated as the target for central CloudTrail trails, every single log delivery triggers a new access event. This spawns an exponential chain reaction resulting in millions of micro-objects, API throttling, and severe billing escalation within hours.
This article details the mechanics of S3 recursive logging loops, defines a tag-driven selective logging framework, and provides production-tested Service Control Policies (SCPs) and Terraform baselines as codified in AWS-DATA-004: Secure S3 Audit Trails and CloudTrail Loop Prevention.
1. Anatomy of an Infinite Recursive Logging Loop
An infinite logging loop occurs when the act of writing an audit log generates a new event that must itself be audited. In AWS S3, this takes three distinct forms:
1.1 The Self-Targeting Bucket Loop
An administrator enables server access logging on s3://app-data-prod and specifies TargetBucket: app-data-prod.
- An application reads an object:
GET /data.csv. - The S3 logging engine batches this event and delivers a log object:
PUT /s3-access-logs/2026-08-22-12-00-00-UUID. - The delivery of
2026-08-22-12-00-00-UUIDis an S3REST.PUT.OBJECTAPI call onapp-data-prod. - The logging engine records this
REST.PUT.OBJECTcall and schedules another log delivery:PUT /s3-access-logs/2026-08-22-12-05-00-UUID. - Each subsequent log delivery generates more log lines, creating an exponential proliferation of micro-files that grows indefinitely until logging is disabled.
1.2 The CloudTrail Log Bucket Collision Loop
A central bucket s3://org-cloudtrail-logs-central is configured to receive organizational CloudTrail audit trails from 50 AWS accounts. If an administrator subsequently enables S3 Server Access Logging on s3://org-cloudtrail-logs-central:
- Every management and data event delivered by CloudTrail from any member account triggers an S3
REST.PUT.OBJECT. - The server access logging engine records the CloudTrail write and writes an access log.
- The access log write is recorded as another event.
- The bucket experiences continuous write amplification, overwhelming S3 partition prefix limits and inflating data storage charges.
1.3 Financial and Operational Consequences
- S3 Request Cost Explosion: S3 charges $0.005 per 1,000
PUTrequests. In an unchecked loop with multiple active prefixes, millions of micro-log files are written per hour, accumulating substantial API request charges. - S3 Partition Throttling: S3 supports 3,500
PUT/POST/DELETErequests per second per prefix. A runaway logging loop can exhaust prefix throughput, causing503 Slow Downthrottling errors that disrupt production applications sharing the bucket. - Management Overhead: Cleaning up hundreds of millions of micro-objects from an S3 bucket requires running S3 Batch Operations or aggressive S3 Lifecycle expiration rules, both of which incur additional processing costs.
2. Architecture of a Secure Log Landing Zone
To achieve comprehensive audit visibility without risking recursive loops, organizations must decouple workload storage from log aggregation.
2.1 Central Log Bucket Policy
The central bucket in the Log Archive account must permit log deliveries from the S3 logging service across the AWS Organization while locking down write permissions with condition keys:
3. Tag-Driven Selective Logging Strategy
Enabling server access logging on every temporary bucket, scratch space, and development container registry generates unnecessary log volume. A tag-driven selective logging strategy focuses compliance and forensic resources on sensitive workloads.
3.1 Sensitivity Classification Standard
Organizations should mandate standardized bucket tags enforced during IaC provisioning:
SecuritySensitivity = HighDataClassification = Confidential | Restricted | Regulated
3.2 Automated Compliance Audit Script
The following Bash script evaluates all S3 buckets in an account, verifying that high-sensitivity buckets have active server access logging while ensuring that CloudTrail archive buckets remain loop-free:
4. Preventative Landing Zone Enforcement (SCPs & Terraform)
To prevent misconfigurations across decentralized engineering teams, security guardrails must be enforced using AWS Organizations Service Control Policies (SCPs) and immutable Terraform modules.
The following SCP blocks any IAM principal (including AdministratorAccess) from enabling server access logging on designated CloudTrail buckets across the organization:
Summary Architecture Checklist
- Never target a bucket to itself: Verify that
TargetBucket != SourceBucketon all S3 logging configurations. - Isolate CloudTrail storage: Strictly prohibit
s3:PutBucketLoggingon all CloudTrail log archive buckets via SCP. - Use prefix partitioning: Structure log targets using
s3-access-logs/<account-id>/<bucket-name>/to prevent partition hot-spotting and maintain clear access boundaries. - Enforce tag-driven governance: Apply
SecuritySensitivity: Hightags to mission-critical buckets and use AWS Config rules to monitor compliance automatically.
For the full machine-readable specification, detection rules, and remediation scripts, refer to:
š AWS-DATA-004: Secure S3 Audit Trails and CloudTrail Loop Prevention.