Files
floci/docs/services/cloudtrail.md
T
Priamo Germosen 401f5ce2d7 fix(iam): name a denied S3 POST in CloudTrail (#5942)
Under IAM enforcement a denied S3 request is recorded in CloudTrail as
the operation that was refused, but a denied POST on an object was not
recorded at all. CreateMultipartUpload and CompleteMultipartUpload are
both checked as s3:PutObject and SelectObjectContent as s3:GetObject,
so the action alone could not say which operation ran, and
RestoreObject had no name.

A denied POST is now named from the sub-resource that chose its action:
?uploads is CreateMultipartUpload, an uploadId CompleteMultipartUpload,
?restore RestoreObject and ?select SelectObjectContent, with ?uploads
ahead of an uploadId as S3Controller runs them. The S3 user guide lists
all four among the object data events CloudTrail logs. A POST naming
none of them still gets no name rather than a wrong one.

SelectObjectContent and GetObjectAttributes were missing from the
read-only events, so a trail logging only reads dropped their denials
and other trails recorded them as writes. CloudTrail counts an event
that changes no resource as read-only, and neither one changes the
object.
2026-10-18 20:43:25 -05:00

4.0 KiB

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

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

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.

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

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