Files
floci/docs/services/cloudtrail.md
T
Priamo Germosen 37717537a4 fix(iam): record a denied browser PostObject in CloudTrail (#6030)
Under IAM enforcement a denied S3 request is recorded in CloudTrail as
the operation that was refused, but a browser POST upload left no
record. Its credential is only in the form fields, so S3Controller
authorizes it through IamEnforcementFilter.authorizeAdditionalResource,
which threw AccessDenied without going through the denial emitter.

The POST path now calls a new authorizePostObject, which checks
s3:PutObject as before and, when IAM refuses it, records the denial as
PostObject before refusing. AWS's S3 developer guide lists PostObject
among the object-level API actions logged as CloudTrail events; the
current user guide's data events table no longer names it. The
emitter's recording half is split out so both paths share it, and a
record it cannot write is logged as a warning.

The denial is recorded in the Region the form's credential names, as a
presigned URL's is in the one its query credential names, so a trail
that logs only that Region gets it.
2026-10-19 21:32:47 -05:00

108 lines
4.1 KiB
Markdown

# CloudTrail
**Protocol:** JSON 1.1 (`X-Amz-Target: com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.*`)
**Endpoint:** `POST http://localhost:4566/`
Floci emulates a CloudTrail trail's full life cycle and emits S3 data
events to the trail's destination bucket as gzipped JSON log files at the
AWS-shaped key path:
```
${prefix}AWSLogs/${accountId}/CloudTrail/${region}/yyyy/MM/dd/${accountId}_CloudTrail_${region}_${YYYYMMDDTHHMMZ}_${rand12}.json.gz
```
## Supported Actions
<!-- floci:actions:start -->
| Action | Description |
| --- | --- |
| `CreateTrail` | Creates a trail, optionally tagged via `TagsList`, and returns its ARN |
| `DescribeTrails` | Returns the settings for one or more trails |
| `DeleteTrail` | Deletes a trail |
| `UpdateTrail` | Updates the settings of an existing trail |
| `PutEventSelectors` | Configures the event selectors for a trail |
| `GetEventSelectors` | - |
| `StartLogging` | Starts logging for a trail |
| `StopLogging` | Stops logging for a trail |
| `GetTrailStatus` | Returns the logging status of a trail |
| `LookupEvents` | - |
| `ListTrails` | - |
| `AddTags` | Adds or overwrites tags on a trail, identified by ARN |
| `RemoveTags` | Removes the given tag keys from a trail, identified by ARN |
| `ListTags` | Returns the tags for one or more trails, identified by ARN |
<!-- floci:actions:end -->
Selector matching honors `ReadWriteType` (`All`, `ReadOnly`, `WriteOnly`)
and `AWS::S3::Object` data resource ARNs in any of these forms:
- `arn:aws:s3:::` — every bucket
- `arn:aws:s3:::bucket/` — every key in the bucket
- `arn:aws:s3:::bucket/prefix` — keys with the given prefix
- `arn:aws:s3:::bucket/prefix/key` — exact key match
## S3 Hook Coverage
Floci emits a CloudTrail data event whenever any of these S3 ops runs
against a bucket matched by an active trail's selectors:
- `PutObject`, `GetObject`, `HeadObject`, `DeleteObject`, `ListObjects`,
`GetObjectAcl`
Both success and `AwsException` paths emit; the latter populates
`errorCode` / `errorMessage` (`NoSuchKey`, `NoSuchBucketPolicy`, etc.).
If `floci.services.iam.enforcement-enabled` is set, IAM-deny responses also
emit records with `errorCode: "AccessDenied"`, named after the operation that
was refused. Besides the ops above, that covers the object ACL and tagging
operations, `PutObjectRetention`, `GetObjectAttributes`, and the `POST`
operations `CreateMultipartUpload`, `CompleteMultipartUpload`, `RestoreObject`
and `SelectObjectContent`. A `POST` is named from the request's
sub-resource, since `CreateMultipartUpload` and `CompleteMultipartUpload` are
both checked as `s3:PutObject` and `SelectObjectContent` as `s3:GetObject`. A request
refused for a permission it needs besides its own, such as
`s3:PutObjectTagging` for an upload that sets tags, is recorded as the
operation. A browser `POST` upload, whose credential is in its form fields, is
recorded as `PostObject` when IAM refuses it.
## Configuration
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_CLOUDTRAIL_ENABLED` | `true` | Enable or disable the service |
| `FLOCI_SERVICES_CLOUDTRAIL_FLUSH_INTERVAL_SECONDS` | `60` | How often the writer flushes buffered records into the destination bucket. Real CloudTrail delivers with ~5 minute latency; the local default is shorter for fast feedback loops. |
## Example
```bash
export AWS_ENDPOINT_URL=http://localhost:4566
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test
aws s3 mb s3://my-source
aws s3 mb s3://my-trail-logs
aws cloudtrail create-trail \
--name my-trail \
--s3-bucket-name my-trail-logs
aws cloudtrail put-event-selectors \
--trail-name my-trail \
--event-selectors '[{
"ReadWriteType": "All",
"IncludeManagementEvents": false,
"DataResources": [{
"Type": "AWS::S3::Object",
"Values": ["arn:aws:s3:::my-source/"]
}]
}]'
aws cloudtrail start-logging --name my-trail
# Drive some traffic
echo hello | aws s3 cp - s3://my-source/greeting.txt
aws s3 cp s3://my-source/greeting.txt -
# After ~60s, log files appear
aws s3 ls s3://my-trail-logs/AWSLogs/ --recursive
```