Files
floci/docs/services/cloudtrail.md
T
Priamo Germosen 215e37eb48 fix(cloudtrail): name S3 denials as CloudTrail records the operation's data event (#9460)
IamEnforcementFilter named the CloudTrail data event of a denied S3 request
from a hand-written table keyed by the IAM action, so a request checked
under another operation's action took that operation's name: HeadBucket
was recorded as ListObjects, CopyObject, UploadPart and UploadPartCopy as
PutObject, GetObjectTorrent as GetObject, ListBuckets as a data event,
and ListObjectVersions, ListParts, DeleteObjects, AbortMultipartUpload and
the legal hold and retention calls were not recorded.

A denial is now recorded under the data event of the operation the request
matched, from src/main/resources/aws/cloudtrail-s3-data-events.json, which
tools/aws/regen_cloudtrail_s3_data_events.py generates from botocore's S3
model, the S3 user guide's data events table and its sentence naming the
event a call is recorded with (vendored by
tools/aws/fetch_cloudtrail_s3_data_events.py), and AWS's S3 service
reference. An operation the table for general purpose buckets lists is
recorded under its name or the one the guide gives it (PutObjectRetention
as PutObjectLockRetention), a versioned one under the version-less name
the table lists (ListObjectsV2 as ListObjects), and an operation it does
not list records no data event. readOnly is the service reference's, by
the reading iam-action-resources.json's readOnlyActions are vendored by,
in place of CloudTrailService's hand-written list.

The IAM data drift workflow runs on a pull request touching any of the six
new files, so the online check covers a change to the table alone.
2026-11-25 15:10:24 -04:00

12 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, IAM API calls and selected Secrets Manager management writes 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 Returns the management events in the account's event history, newest first
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

Source address

sourceIPAddress is "the IP address that the request was made from" (CloudTrail record contents): the address of the connection Floci received the request on. An X-Forwarded-For header is not read on its own, since any client can send one. Behind a reverse proxy, Quarkus's own proxy settings make the address it forwards the source address, from the proxies they name only:

QUARKUS_HTTP_PROXY_PROXY_ADDRESS_FORWARDING=true
QUARKUS_HTTP_PROXY_ALLOW_X_FORWARDED=true
QUARKUS_HTTP_PROXY_TRUSTED_PROXIES=10.0.0.5   # the proxy's address or range

Quarkus takes the first address in X-Forwarded-For, so the proxy must set the header to the address its own connection came from, replacing any the client sent (nginx's proxy_set_header X-Forwarded-For $remote_addr). A proxy that appends to the client's header (nginx's $proxy_add_x_forwarded_for) leaves the client's choice first, and that is what gets recorded.

With floci.tls.enabled, Floci's own TCP proxy relays every connection to Quarkus, so the source address is the loopback address.

Encryption and CloudWatch Logs settings

CreateTrail and UpdateTrail record KmsKeyId, CloudWatchLogsLogGroupArn and CloudWatchLogsRoleArn, and DescribeTrails returns them, so a Terraform aws_cloudtrail with encryption or log delivery reads back what it declared. UpdateTrail with an empty value clears one, as on AWS. A log group without a role is refused with InvalidCloudWatchLogsRoleArnException, and a role without a log group with InvalidCloudWatchLogsLogGroupArnException. The settings are recorded only: log files are not encrypted, events are not delivered to the log group, and KmsKeyId is stored as sent (an alias is not resolved to the key ARN, and an unknown key is not refused).

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", for every operation CloudTrail records as a data event on an object of a general purpose bucket, named as CloudTrail names it and marked readOnly as it does. The operations, their names and their flags come from src/main/resources/aws/cloudtrail-s3-data-events.json, which make cloudtrail-s3-data-events-sync generates from botocore's S3 model, the S3 user guide's data events table (vendored by tools/aws/fetch_cloudtrail_s3_data_events.py) and AWS's S3 service reference. A request is named after the operation it matched, so HeadBucket, CopyObject, UploadPart and CreateMultipartUpload are recorded as themselves although they are checked as s3:ListBucket or s3:PutObject. ListObjectsV2 is recorded as ListObjects, the only name the guide lists for a general purpose bucket, and PutObjectRetention as PutObjectLockRetention, as the guide says. 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. An operation CloudTrail records as a management event, such as ListBuckets or GetBucketPolicy, is not recorded as a data event. A browser POST upload, whose credential is in its form fields, is recorded as PostObject when IAM refuses it.

IAM Coverage

Every IAM API call is recorded as a management event, as CloudTrail "logs all authenticated API requests to IAM": one IAM ran, one IAM answered with an error, and, with floci.services.iam.enforcement-enabled, one IAM enforcement refused.

  • eventSource is iam.amazonaws.com and awsRegion the Region IAM signs for in the request's partition (us-east-1 in aws). IAM is a global service, so only a trail with IncludeGlobalServiceEvents (the default) records its calls, and only a multi-Region trail or one whose home Region is that Region.
  • readOnly is true for the actions AWS's service reference (iam.json) gives the Read or List access level, vendored as readOnlyActions in iam-action-resources.json by make iam-action-resources-sync.
  • requestParameters holds the request's members, named with a lower first letter (userName, policyArn, tags: [{"key": ..., "value": ...}]), numbers and booleans typed as botocore's IAM model types them. A member the model marks sensitive (a password, a private key) is left out, and a request whose only members are sensitive (ChangePassword) has "requestParameters": null.
  • responseElements is null for a failed call and for a read-only one, as CloudTrail "redacts the responseElements information" of a read-only event. Otherwise it holds the call's result ({"accessKey": {...}} for CreateAccessKey), numbers, booleans and timestamps typed as the model types them, timestamps written as CloudTrail writes them (Oct 29, 2024 2:43:20 PM), and without the members the model marks sensitive (secretAccessKey, a service-specific credential's password or secret, a virtual MFA device's seed).
  • An error IAM models is recorded under its error shape's name: NoSuchEntity as NoSuchEntityException, DeleteConflict as DeleteConflictException, with IAM's message. A call IAM enforcement refuses, on its policies or because a GetSessionToken session without MFA cannot make it, is recorded as errorCode: "AccessDenied" and "requestParameters": null, with the message and the request ID the refusal answered with.
  • sourceIPAddress is the address the request came from and userAgent its User-Agent; requestID is the one IAM answered with. userIdentity is the caller as it was before the call ran, so a key that deletes itself is still recorded as its user's.
  • Like every management event, an IAM call also reaches the account's event history, which LookupEvents reads, whether or not a trail records it.

How each member is typed, which members are sensitive and each error's shape name are read from iam-cloudtrail-shapes.json, which make aws-data-sync generates from the pinned botocore.

Management Write Coverage

Successful Secrets Manager PutSecretValue and UpdateSecret API calls produce management records when a logging trail selects them. New trails include management events by default. Basic selectors honor IncludeManagementEvents, ReadWriteType (against each event's readOnly), and source exclusions. Advanced selectors evaluate eventCategory, eventSource, eventName, readOnly, eventType, and userIdentity.arn; unsupported fields do not match these records.

Records have eventCategory: Management and managementEvent: true; the Secrets Manager writes have readOnly: false. Sensitive secret values are omitted. Buffers and background S3 delivery retain the originating account, including when different accounts use the same trail name. Multi-region trails cover regions within their own partition.

These writes also reach EventBridge's default bus in the request's account and region. See Secrets Manager event delivery for prerequisites, the secret-specific event pattern, and the limits of this coverage.

Event History

LookupEvents reads the event history: every management event Floci records, in the caller's account and region, whether or not a trail is logging, as on AWS. Today those are the Secrets Manager PutSecretValue and UpdateSecret writes above. Events come back newest first, at most 50 a page with a NextToken for the rest (as on AWS, the token is accepted only with the same parameters), and can be narrowed by StartTime, EndTime and one LookupAttributes entry (EventId, EventName, EventSource, ReadOnly, Username or AccessKeyId). Each event carries CloudTrailEvent, the full record as a trail delivers it.

The history keeps 90 days and at most 10,000 events per account and region, in memory: it does not survive a restart, and an emulator reset empties it. Records name no resources, so Resources is empty and a ResourceType or ResourceName attribute matches nothing. Floci records no Insights events, so EventCategory: insight returns an empty page; any other category is refused with InvalidEventCategoryException.

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