Skip to content

feat(infra): scoped read-only CloudTrail data events on the prod lake - #946

Merged
athvin merged 1 commit into
mainfrom
issue/554-scoped-cloudtrail
Nov 9, 2026
Merged

athvin merged 1 commit into
mainfrom
issue/554-scoped-cloudtrail

Conversation

@athvin

@athvin athvin commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #554

What

One event_selector on the account's one trail (aws_cloudtrail.org, envs/core/audit.tf): ReadOnly data events on AWS::S3::Object, scoped to the constructed prod-lake ARN, with include_management_events = true stated explicitly so the trail's management coverage cannot change by omission.

Why

§3.2's audit trail for the prod data plane: a read on the prod prefix must produce an event, a write must not, and a nonprod-bucket read must not. Writes are the engine's steady-state parquet churn at per-100k data-event pricing; reads are the exfiltration signal. Volume is near-zero until the engine's s3:// lake path lands. The ARN is constructed as a string because core cannot reference an envs/prod resource — the plan-safe pattern this repo already uses cross-stack; a wrong bucket surfaces as "no events arrive", which the probes then catch.

Proof

terraform validate on envs/core — Success (1.11.4); terraform fmt -check clean; tf-static-credentials-check.sh clean. Lifecycle readback, run against the live bucket now (aws s3api get-bucket-lifecycle-configuration --bucket er-prod-lake-797781631727): noncurrent-expiry Enabled, NoncurrentDays 30, AbortIncompleteMultipartUpload 7 — the issue's third checkbox, already satisfied by the lake module and verified from the API.

Risk & rollback

Risk: the selector could silently log nothing if the ARN were wrong — the post-merge probes exist precisely to catch that. Rollback: git revert <merge-sha>; removing the selector restores management-only logging.

Post-merge ledger

Closed by: agent · codex session on Athvins-MacBook-Pro · 2026-11-09T01:35:00Z

  • main is green with this change on it — merge b0c55d74; rust run 42543569780 success, frontend 42543569764 success, devcontainer 42543569769 success, infra 42543569816 success.
  • images correctly never ran — a terraform-only merge matches none of images.yml's push paths, and no images run exists for b0c55d74.
  • deploy n/a by the same mechanism — deploy is reachable only through images' workflow_run (deploy.yml header), and images never ran.
  • the push-only surface no pull request can pre-test — infra run 42543569816: apply (core) success at 01:07:08Z as an in-place 1 to change; the destroy guard passed with no ALLOW-DESTROY because the apply tier sets TF_VAR_cloudflare_account_id and the R2 pair's DESTROY is a plan-tier artifact of the opt-in. Last scheduled drift run 42453080846 green (daily 06:02Z cadence).
  • the board card — Prod lake + scoped CloudTrail #554 closed by the merge at 01:04:23Z via the body's Closes.
  • follow-ups — none owed; the acceptance probes were this change's own ledger items and are done below.
  • what was learned is written down — recorded here and on Prod lake + scoped CloudTrail #554: (1) S3 data events never appear in lookup-events; only the delivered log files carry them. (2) A selector change has a capture gap — round 1 at +1m45s after the apply never appeared, so probes must run after get-event-selectors confirms, or an absent event is ambiguous.

Specific to this change

  • terraform core apply ran green with the selector added in place — run 42543569816, apply (core) success 01:07:08Z; PR plan had shown 0 add / 1 change.
  • probe 1 — read produces an event: round-2 get-object on .cloudtrail-probe/probe2.txt at 01:22:28Z appears as GetObject at 01:22:29Z in ...T0130Z_GaEj7tqlPWWv0xA6.json.gz, principal dupezone, resources = the prod lake bucket + object ARN.
  • probe 2 — write does not: the paired round-2 put-object (01:22:27Z) is absent from that same delivered file, and zero PutObject/DeleteObject events exist across all seven delivered files (00:45Z-01:30Z). Object-level scan: exactly ONE data event in the whole trail — the probe-1 GetObject.
  • probe 3 — nonprod read does not: get-object on er-dev-lake (01:09:13Z and 01:22:29Z, both NoSuchKey) and list-objects-v2 (01:08:54Z) are all absent; the dev bucket appears only as management-plane GetBucket* calls from the drift workflow, which are global by design, not data events.
  • lifecycle readback (run pre-merge): get-bucket-lifecycle-configuration on er-prod-lake-797781631727 → noncurrent-expiry Enabled, NoncurrentDays 30, AbortIncompleteMultipartUpload 7.
Context — plan, discoveries, measurements, files

Plan

  1. Add the scoped selector to aws_cloudtrail.org. 2. Validate + gates. 3. On merge, watch the core apply. 4. Run the three §3.2 probes against delivered logs (data events are not in lookup-events; allow for delivery lag). 5. Lifecycle readback — DONE, pre-merge (below).

Discoveries

  • The lake module (modules/lake/main.tf) already declares exactly the lifecycle §3.2 asks for, so that checkbox is a readback, not a change.
  • The trail had no selector at all: management events ride the implicit default. Adding the first event_selector with include_management_events = true keeps that coverage verbatim.
  • Data events are not returned by aws cloudtrail lookup-events; the probes must read the delivered log files in er-audit-archive-797781631727.

Measurements

  • aws s3api get-bucket-lifecycle-configuration --bucket er-prod-lake-797781631727 → NoncurrentDays 30, DaysAfterInitiation 7 (2026-11-09).
  • terraform -chdir=infra/terraform/envs/core validate → Success.

Files

  • infra/terraform/envs/core/audit.tf — the selector, with the why.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

terraform plan

0bc4e0d · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 1 2
dev 0 0 0
prod 0 0 0

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

Warning

This plan DESTROYS resources in: core. Merging applies it unattended.
The apply refuses to run unless the merge commit message carries
ALLOW-DESTROY. Retitling is not enough on a single-commit PR — GitHub
uses the commit message there, not the title. Merge with
gh pr merge <n> --squash --subject '<subject> ALLOW-DESTROY'.

core — 0 to add, 1 to change, 2 to DESTROY
data.aws_iam_policy_document.ci_tf_plan_state: Reading...
data.aws_iam_policy_document.ci_tf_plan_state: Read complete after 0s [id=2883378100]
data.aws_iam_policy_document.ci_tf_drift_refresh: Reading...
data.aws_caller_identity.current: Reading...
data.aws_iam_policy_document.ci_tf_drift_refresh: Read complete after 0s [id=2350222434]
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Reading...
module.identity_center.data.aws_ssoadmin_instances.this: Reading...
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Read complete after 0s [id=2395007408]
module.github_oidc.data.aws_iam_policy_document.trust: Reading...
data.aws_iam_policy_document.obs_pod_trust: Reading...
module.github_oidc.data.aws_iam_policy_document.trust: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.cur_delivery: Reading...
data.aws_iam_policy_document.obs_pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.cur_delivery: Read complete after 0s [id=2207400467]
data.aws_iam_policy_document.openobserve: Reading...
data.aws_iam_policy_document.openobserve: Read complete after 0s [id=2662704728]
data.aws_iam_policy_document.config_bucket: Reading...
data.aws_iam_policy_document.config_bucket: Read complete after 0s [id=4067691321]
data.aws_iam_policy_document.ci_tf_apply_trust: Reading...
data.aws_iam_policy_document.sccache_trust_read: Reading...
data.aws_iam_policy_document.ci_tf_plan_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_trust: Read complete after 0s [id=2538345208]
data.aws_iam_policy_document.sccache_trust_read: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.ci_tf_plan_trust: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.sccache_trust_write: Reading...
data.aws_iam_policy_document.ci_tf_drift_trust: Reading...
data.aws_iam_policy_document.ci_tf_drift_trust: Read complete after 0s [id=2357770959]
data.aws_iam_policy_document.sccache_write: Reading...
data.aws_iam_policy_document.sccache_trust_write: Read complete after 0s [id=4060172364]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
data.aws_iam_policy_document.sccache_read: Reading...
data.aws_iam_policy_document.sccache_write: Read complete after 0s [id=786296009]
module.github_oidc.data.aws_iam_policy_document.push: Reading...
data.aws_iam_policy_document.sccache_read: Read complete after 0s [id=2701062528]
module.github_oidc.data.aws_iam_policy_document.push: Read complete after 0s [id=2177873069]
data.aws_iam_policy_document.audit_bucket: Reading...
data.aws_iam_policy_document.audit_bucket: Read complete after 0s [id=3031279952]
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Read complete after 0s [id=3513372776]
module.identity_center.data.aws_ssoadmin_instances.this: Read complete after 1s [id=us-east-2]
module.identity_center.data.aws_identitystore_user.admin: Reading...
module.identity_center.data.aws_identitystore_user.admin: Read complete after 0s [id=b17b2500-e0b1-7046-405b-23c088cf392b]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
  - destroy

Terraform will perform the following actions:

  # aws_cloudtrail.org will be updated in-place
  ~ resource "aws_cloudtrail" "org" {
        id                            = "arn:aws:cloudtrail:us-east-2:797781631727:trail/er-org-trail"
        name                          = "er-org-trail"
        tags                          = {}
        # (16 unchanged attributes hidden)

      + event_selector {
          + include_management_events = true
          + read_write_type           = "ReadOnly"

          + data_resource {
              + type   = "AWS::S3::Object"
              + values = [
                  + "arn:aws:s3:::er-prod-lake-797781631727/",
                ]
            }
        }
    }

  # cloudflare_r2_bucket.sccache[0] will be destroyed
  # (because index [0] is out of range for count)
  - resource "cloudflare_r2_bucket" "sccache" {
      - account_id    = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
      - creation_date = "2026-11-08T20:59:18.644Z" -> null
      - id            = "er-ci-sccache" -> null
      - jurisdiction  = "default" -> null
      - location      = "ENAM" -> null
      - name          = "er-ci-sccache" -> null
      - storage_class = "Standard" -> null
    }

  # cloudflare_r2_bucket_lifecycle.sccache[0] will be destroyed
  # (because index [0] is out of range for count)
  - resource "cloudflare_r2_bucket_lifecycle" "sccache" {
      - account_id   = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
      - bucket_name  = "er-ci-sccache" -> null
      - jurisdiction = "default" -> null
      - rules        = [
          - {
              - abort_multipart_uploads_transition = {
                  - condition = {
                      - max_age = 86400 -> null
                      - type    = "Age" -> null
                    } -> null
                } -> null
              - conditions                         = {
                    # (1 unchanged attribute hidden)
                } -> null
              - delete_objects_transition          = {
                  - condition = {
                      - max_age = 1209600 -> null
                      - type    = "Age" -> null
                    } -> null
                } -> null
              - enabled                            = true -> null
              - id                                 = "expire-cache-objects" -> null
            },
        ] -> null
    }

Plan: 0 to add, 1 to change, 2 to destroy.

Changes to Outputs:
  - r2_sccache_bucket         = "er-ci-sccache" -> null
  - r2_sccache_endpoint       = "https://9eefbe6bc92d11b2bb4e962494765a4c.r2.cloudflarestorage.com" -> null

Warning: Resource Destruction Considerations

  with cloudflare_r2_bucket_lifecycle.sccache[0],
  on r2.tf line 96, in resource "cloudflare_r2_bucket_lifecycle" "sccache":
  96: resource "cloudflare_r2_bucket_lifecycle" "sccache" {

Applying this resource destruction will remove the resource from the
Terraform state but will not change it in the API. If you would like to
destroy or reset this resource in the API, refer to the documentation for how
to do it manually.

@athvin
athvin marked this pull request as ready for review November 9, 2026 01:03
@athvin
athvin merged commit b0c55d7 into main Nov 9, 2026
41 checks passed
@athvin athvin mentioned this pull request Nov 9, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prod lake + scoped CloudTrail

2 participants