Skip to content

Fix: Frequent AccessDenied requests against manifest bucket from foreign VPC (#8118) - #8228

Merged
nadove-ucsc merged 2 commits into
developfrom
issues/nadove-ucsc/8118-frequent-access-denied
Sep 12, 2026
Merged

nadove-ucsc merged 2 commits into
developfrom
issues/nadove-ucsc/8118-frequent-access-denied

Conversation

@nadove-ucsc

@nadove-ucsc nadove-ucsc commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Linked issues: #8118

Checklist

Author

  • PR is assigned to the author
  • Status of PR is In progress
  • PR is a draft
  • Target branch is develop
  • Name of PR branch matches issues/<GitHub handle of author>/<issue#>-<slug>
  • PR is linked to all issues it (partially) resolves
  • Status of linked issues is In progress
  • PR description links to linked issues
  • PR title matches1 that of a linked issue or comment in PR explains why they're different
  • PR title references all linked issues
  • For each linked issue, there is at least one commit whose title references that issue

1 when the issue title describes a problem, the corresponding PR
title is Fix: followed by the issue title

Author (partiality)

  • Added p tag to titles of partial commits
  • This PR is labeled partial or completely resolves all linked issues
  • This PR partially resolves each of the linked issues or does not have the partial label

Author (reindex)

  • Added r tag to commit title or the changes introduced by this PR will not require reindexing of any deployment
  • This PR is labeled reindex:dev or the changes introduced by it will not require reindexing of dev
  • This PR is labeled reindex:anvildev or the changes introduced by it will not require reindexing of anvildev
  • This PR is labeled reindex:anvilprod or the changes introduced by it will not require reindexing of anvilprod
  • This PR is labeled reindex:prod or the changes introduced by it will not require reindexing of prod
  • This PR is labeled reindex:partial and its description documents the specific reindexing procedure for dev, anvildev, anvilprod and prod or requires a full reindex or carries none of the labels reindex:dev, reindex:anvildev, reindex:anvilprod and reindex:prod

Author (mirror)

  • This PR is labeled mirror:dev or the changes introduced by it will not require mirroring of dev
  • This PR is labeled mirror:anvildev or the changes introduced by it will not require mirroring of anvildev
  • This PR is labeled mirror:anvilprod or the changes introduced by it will not require mirroring of anvilprod
  • This PR is labeled mirror:prod or the changes introduced by it will not require mirroring of prod
  • This PR is labeled mirror:partial and its description documents the specific mirroring procedure for dev, anvildev, anvilprod and prod or requires a full mirroring or carries none of the labels mirror:dev, mirror:anvildev, mirror:anvilprod and mirror:prod

Author (API changes)

  • This PR and its linked issues are labeled API or this PR does not modify a REST API
  • Added a (A) tag to commit title for backwards (in)compatible changes or this PR does not modify a REST API
  • Updated REST API version number in app.py or this PR does not modify a REST API

Author (upgrading deployments)

  • Ran make docker_images.json and committed the resulting changes or this PR does not modify azul_docker_images, or any other variables referenced in the definition of that variable
  • Documented upgrading of deployments in UPGRADING.rst or this PR does not require upgrading deployments
  • Added u tag to commit title or this PR does not require upgrading deployments
  • This PR is labeled upgrade or does not require upgrading deployments
  • This PR is labeled deploy:shared or does not modify docker_images.json, and does not require deploying the shared component for any other reason
  • This PR is labeled deploy:gitlab or does not require deploying the gitlab component
  • This PR is labeled deploy:runner or does not require deploying the runner image

Author (hotfixes)

  • Added F tag to main commit title or this PR does not include permanent fix for a temporary hotfix
  • Reverted the temporary hotfixes for any linked issues or the none of the stable branches (anvilprod and prod) have temporary hotfixes for any of the issues linked to this PR

Author (before every review)

  • Rebased PR branch on develop, squashed fixups from prior reviews
  • Ran make requirements_update or this PR does not modify Dockerfile, environment, requirements*.txt, common.mk, Makefile or environment.boot
  • Added R tag to commit title or this PR does not modify requirements*.txt
  • This PR is labeled reqs or does not modify requirements*.txt
  • make integration_test passes in personal deployment or this PR does not modify functionality that could affect the IT outcome
  • PR is awaiting requested review from a peer
  • Status of PR is Review requested
  • PR is assigned to only the peer and the author

Peer reviewer (after approval)

Note that after requesting changes, the PR must be assigned to only the author.

  • Actually approved the PR
  • PR is not a draft
  • PR is awaiting requested review from system administrator
  • Status of PR is Review requested
  • PR is assigned to only the system administrator and the author

System administrator (after approval)

  • Actually approved the PR
  • Labeled linked issues as demo or no demo
  • Commented on linked issues about demo expectations or all linked issues are labeled no demo
  • Decided if PR can be labeled no sandbox
  • A comment to this PR details the completed security design review
  • PR title is appropriate as title of merge commit
  • N reviews label is accurate
  • Status of PR is Approved
  • PR is assigned to only the operator and the author

Operator

  • Checked reindex:… labels and r commit title tag
  • Checked mirror:… labels
  • Checked that demo expectations are clear or all linked issues are labeled no demo
  • Squashed PR branch and rebased onto develop
  • Sanity-checked history
  • Pushed PR branch to GitHub

Operator (deploy .shared and .gitlab components)

  • Ran _select dev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unused or this PR is not labeled deploy:shared
  • Ran _select dev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab apply or this PR is not labeled deploy:gitlab
  • Ran _select anvildev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unused or this PR is not labeled deploy:shared
  • Ran _select anvildev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab apply or this PR is not labeled deploy:gitlab
  • Checked the items in the next section or this PR is labeled deploy:gitlab
  • PR is assigned to only the system administrator and the author or this PR is not labeled deploy:gitlab

System administrator (post-deploy of .gitlab component)

  • Background migrations for dev.gitlab are complete or this PR is not labeled deploy:gitlab
  • Background migrations for anvildev.gitlab are complete or this PR is not labeled deploy:gitlab
  • PR is assigned to only the operator and the author

Operator (deploy runner image)

  • Ran _select dev.gitlab && make -C terraform/gitlab/runner or this PR is not labeled deploy:runner
  • Ran _select anvildev.gitlab && make -C terraform/gitlab/runner or this PR is not labeled deploy:runner

Operator (sandbox build)

  • Added sandbox label or PR is labeled no sandbox
  • Pushed PR branch to GitLab dev or PR is labeled no sandbox
  • Pushed PR branch to GitLab anvildev or PR is labeled no sandbox
  • Build passes in sandbox deployment or PR is labeled no sandbox
  • Build passes in anvilbox deployment or PR is labeled no sandbox
  • Reviewed build logs for anomalies in sandbox deployment or PR is labeled no sandbox
  • Reviewed build logs for anomalies in anvilbox deployment or PR is labeled no sandbox
  • Applied upgrade instructions from UPGRADING.rst to sandbox or this PR is not labeled upgrade, or upgrade instructions do not apply to sandbox
  • Applied upgrade instructions from UPGRADING.rst to anvilbox or this PR is not labeled upgrade, or upgrade instructions do not apply to anvilbox
  • Deleted unreferenced indices in sandbox or this PR does not remove catalogs or otherwise causes unreferenced indices in sandbox
  • Deleted unreferenced indices in anvilbox or this PR does not remove catalogs or otherwise causes unreferenced indices in anvilbox
  • Started reindex in sandbox or this PR is not labeled reindex:dev
  • Started reindex in anvilbox or this PR is not labeled reindex:anvildev
  • Checked for failures in sandbox or this PR is not labeled reindex:dev
  • Checked for failures in anvilbox or this PR is not labeled reindex:anvildev
  • Started mirroring in sandbox or this PR is not labeled mirror:dev
  • Started mirroring in anvilbox or this PR is not labeled mirror:anvildev
  • Checked for failures in sandbox or this PR is not labeled mirror:dev
  • Checked for failures in anvilbox or this PR is not labeled mirror:anvildev

Operator (merge the branch)

  • All status checks passed and the PR is mergeable
  • The title of the merge commit starts with the title of this PR
  • Added PR # reference to merge commit title
  • Collected commit title tags in merge commit title but only included p if the PR is also labeled partial
  • Pushed merge commit to GitHub
  • Status of PR is Merged lower
  • Status of blocked issues is Triage or no issues are blocked on the linked issues

Operator (main build)

  • Pushed merge commit to GitLab dev
  • Pushed merge commit to GitLab anvildev
  • Build passes on GitLab dev
  • Reviewed build logs for anomalies on GitLab dev
  • Build passes on GitLab anvildev
  • Reviewed build logs for anomalies on GitLab anvildev
  • Applied upgrade instructions from UPGRADING.rst to dev or this PR is not labeled upgrade, or upgrade instructions do not apply to dev
  • Applied upgrade instructions from UPGRADING.rst to anvildev or this PR is not labeled upgrade, or upgrade instructions do not apply to anvildev
  • Notified developers to apply upgrade instructions from UPGRADING.rst to their personal deployments or this PR is not labeled upgrade, or upgrade instructions do not apply to personal deployments
  • Ran _select dev.shared && make -C terraform/shared apply or this PR is not labeled deploy:shared
  • Ran _select anvildev.shared && make -C terraform/shared apply or this PR is not labeled deploy:shared
  • Deleted PR branch from GitHub
  • PR is assigned to only the operator
  • Deleted PR branch from GitLab dev
  • Deleted PR branch from GitLab anvildev
  • Status of linked issues is Lower, or Triage, if PR is partial

Operator (reindex)

  • Deindexed all unreferenced catalogs in dev or this PR is neither labeled reindex:partial nor reindex:dev
  • Deindexed all unreferenced catalogs in anvildev or this PR is neither labeled reindex:partial nor reindex:anvildev
  • Deindexed specific sources in dev or this PR is neither labeled reindex:partial nor reindex:dev
  • Deindexed specific sources in anvildev or this PR is neither labeled reindex:partial nor reindex:anvildev
  • Indexed specific sources in dev or this PR is neither labeled reindex:partial nor reindex:dev
  • Indexed specific sources in anvildev or this PR is neither labeled reindex:partial nor reindex:anvildev
  • Started reindex in dev or this PR does not require reindexing dev
  • Started reindex in anvildev or this PR does not require reindexing anvildev
  • Checked for, triaged and possibly requeued messages in both fail queues in dev or this PR does not require reindexing dev
  • Checked for, triaged and possibly requeued messages in both fail queues in anvildev or this PR does not require reindexing anvildev
  • Emptied fail queues in dev or this PR does not require reindexing dev
  • Emptied fail queues in anvildev or this PR does not require reindexing anvildev
  • Restarted the Data Browser pipeline for the ucsc/hca/dev branch on GitLab in dev or this PR does not require reindexing dev
  • Restarted the Data Browser pipeline for the ucsc/lungmap/dev branch on GitLab in dev or this PR does not require reindexing dev
  • Restarted deploy_browser job in the GitLab pipeline for this PR in dev or this PR does not require reindexing dev
  • Restarted the Data Browser pipeline for the ucsc/anvil/anvildev branch on GitLab in anvildev or this PR does not require reindexing anvildev
  • Restarted deploy_browser job in the GitLab pipeline for this PR in anvildev or this PR does not require reindexing anvildev

Operator (mirroring)

  • Started mirroring in dev or this PR is not labelled mirror:dev
  • Started mirroring in anvildev or this PR is not labelled mirror:anvildev
  • Checked for, triaged and possibly requeued messages in mirror fail queue in dev or this PR is not labelled mirror:dev
  • Checked for, triaged and possibly requeued messages in mirror fail queue in anvildev or this PR is not labelled mirror:anvildev
  • Emptied mirror fail queue in dev or this PR is not labelled mirror:dev
  • Emptied mirror fail queue in anvildev or this PR is not labelled mirror:anvildev

Operator

  • Propagated the upgrade and API labels to the next promotion PRs or this PR carries neither of these labels
  • Propagated the deploy:shared, deploy:gitlab, deploy:runner, reindex:partial, reindex:anvilprod, reindex:prod, mirror:partial, mirror:anvilprod and mirror:prod labels to the next promotion PRs or this PR carries none of these labels
  • Propagated any specific instructions related to the deploy:shared, deploy:gitlab, deploy:runner, reindex:partial, reindex:anvilprod, reindex:prod, mirror:partial, mirror:anvilprod and mirror:prod labels, from the description of this PR to that of the next promotion PRs or this PR carries none of these labels
  • PR is assigned to no one

Shorthand for review comments

  • L line is too long
  • W line wrapping is wrong
  • Q bad quotes
  • F other formatting problem

@nadove-ucsc nadove-ucsc self-assigned this Aug 14, 2026
@nadove-ucsc nadove-ucsc added the deploy:shared [process] PR requires deploying `shared` component label Aug 14, 2026
@nadove-ucsc
nadove-ucsc marked this pull request as ready for review August 14, 2026 03:48
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.79%. Comparing base (f838a86) to head (41ff987).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8228   +/-   ##
========================================
  Coverage    84.79%   84.79%           
========================================
  Files          168      168           
  Lines        25191    25191           
========================================
  Hits         21360    21360           
  Misses        3831     3831           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coveralls

coveralls commented Aug 14, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 84.868%. remained the same — issues/nadove-ucsc/8118-frequent-access-denied into develop

@hannes-ucsc hannes-ucsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this tested?

_or(
'$.eventSource != "s3.amazonaws.com"',
'$.userIdentity.accountId != "anonymous"',
f'$.requestParameters.bucketName != "{aws.qualified_bucket_name("*")}"'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f'$.requestParameters.bucketName != "{aws.qualified_bucket_name("*")}"'
f'$.requestParameters.bucketName != "{aws.qualified_bucket_name('*')}"'

@hannes-ucsc hannes-ucsc removed their assignment Aug 14, 2026
@hannes-ucsc
hannes-ucsc force-pushed the issues/nadove-ucsc/8118-frequent-access-denied branch from 065b039 to fba81d3 Compare August 26, 2026 14:45
@hannes-ucsc

Copy link
Copy Markdown
Member

(Posted by Claude Code)

Test of the api_unauthorized metric filter

The pattern generated by terraform/shared/shared.tf.json.template.py at 065b039 was tested with aws logs test-metric-filter against nine real CloudTrail events from the dev account (122796619775), using the pattern as rendered for that account:

{(($.errorCode = "*UnauthorizedOperation") || ($.errorCode = "AccessDenied*")) && (($.userIdentity.invokedBy NOT EXISTS) || (($.userIdentity.invokedBy != "config.amazonaws.com") && ($.userIdentity.invokedBy != "resource-explorer-2.amazonaws.com"))) && (($.eventSource != "s3.amazonaws.com") || ($.userIdentity.accountId != "anonymous") || ($.requestParameters.bucketName != "edu-ucsc-gi-platform-hca-dev-*.us-east-1"))}

Four of the nine events match, exactly as intended:

# eventSource eventName Caller Matches
0 s3 HeadBucket IAM user in 652235167018 yes
1 s3 GetBucketObjectLockConfiguration IAM user in 652235167018 yes
2 s3 GetBucketVersioning IAM user in 652235167018 yes
3 ce ListCostCategoryDefinitions config.amazonaws.com no
4 macie2 ListCustomDataIdentifiers resource-explorer-2.amazonaws.com no
5 ce ListCostCategoryDefinitions config.amazonaws.com no
6 s3 ListObjects (…mirror-nadove) anonymous no
7 ecr BatchGetImage lambda.amazonaws.com yes
8 ce ListCostCategoryDefinitions config.amazonaws.com no

Event 6 is the anonymous foreign-VPC request this issue is about, and the new clause suppresses it. The service-linked callers in events 3, 4 and 5 remain suppressed by the pre-existing invokedBy clause. Events 0–2 (an authenticated cross-account IAM user denied in the console) and event 7 (an AWSService caller denied on ECR) fall outside the new clause and continue to alarm, as they should.

The test also confirms that the negated wildcard comparison on bucketName works: suppression takes effect only for bucket names matching edu-ucsc-gi-platform-hca-dev-*.us-east-1.

@hannes-ucsc

Copy link
Copy Markdown
Member

The events the pattern was tested against was produced using our canned api_unauthorized CW Logs query.

@hannes-ucsc hannes-ucsc added the 1 review [process] Lead requested changes once label Aug 26, 2026
@hannes-ucsc hannes-ucsc self-assigned this Aug 26, 2026
@hannes-ucsc

Copy link
Copy Markdown
Member

(Posted by Claude Code)

Security design review

  • Security design review completed; this PR does not
    • … affect authentication; for example:
      • OAuth 2.0 with the application (API or Swagger UI)
      • Authentication of developers with Google Cloud APIs
      • Authentication of developers with AWS APIs
      • Authentication with a GitLab instance in the system
      • Password and 2FA authentication with GitHub
      • API access token authentication with GitHub
      • Authentication with Terra
    • … affect the permissions of internal users like access to
      • Cloud resources on AWS and GCP
      • GitLab repositories, projects and groups, administration
      • an EC2 instance via SSH
      • GitHub issues, pull requests, commits, commit statuses, wikis, repositories, organizations
    • … affect the permissions of external users like access to
      • TDR snapshots
    • … affect permissions of service or bot accounts
      • Cloud resources on AWS and GCP
    • … affect audit logging in the system, like
      • adding, removing or changing a log message that represents an auditable event
      • changing the routing of log messages through the system
    • … affect monitoring of the system
    • … introduce a new software dependency like
      • Python packages on PYPI
      • Command-line utilities
      • Docker images
      • Terraform providers
    • … add an interface that exposes sensitive or confidential data at the security boundary
    • … affect the encryption of data at rest
    • … require persistence of sensitive or confidential data that might require encryption at rest
    • … require unencrypted transmission of data within the security boundary
    • … affect the network security layer; for example by
      • modifying, adding or removing firewall rules
      • modifying, adding or removing security groups
      • changing or adding a port a service, proxy or load balancer listens on
  • Documentation on any unchecked boxes is provided in comments below

Documentation of unchecked boxes

… affect monitoring of the system

This PR adds a third conjunct to the api_unauthorized CloudWatch Logs metric filter, suppressing the alarm for S3 AccessDenied events from userIdentity.accountId == "anonymous" against buckets matching edu-ucsc-gi-<account>-*.<region>. It narrows the coverage of the alarm implementing Security Hub CloudWatch.2 (CIS 4.1, unauthorized API calls), which is the sole security-relevant effect of the change. No other category is affected.

Note the distinction that carries most of the risk argument: CloudTrail still records these events, and the trail log group retains them for audit_log_retention_days = 365. Only the alarm's metric filter changes, so forensic and retroactive-query capability is fully intact — as the log mining on #8118 itself demonstrates. This is why the audit logging box above remains checked.

Findings below were verified empirically against aws logs test-metric-filter with synthetic CloudTrail records, rather than reasoned from the pattern text alone.

Finding 1 (medium): missing-field semantics silently widen the exception beyond anonymous callers

In CloudWatch JSON filter patterns, != on an absent field evaluates to false, not true. The existing pattern already encodes this knowledge for invokedBy, via the $.userIdentity.invokedBy NOT EXISTS disjunct; the new clause omits the equivalent guard.

userIdentity.accountId is absent for type: "AWSService" records, which carry only type and invokedBy. The only difference between the first two rows below is the presence of accountId:

synthetic event this PR with NOT EXISTS
AWSService (delivery.logs.amazonaws.com), accountId absent, our bucket suppressed alarm
AWSService, accountId present, our bucket alarm alarm
anonymous, our bucket (the intended target) suppressed suppressed

So AccessDenied on our own buckets invoked by any AWS service other than Config and Resource Explorer — log delivery failing to write ELB or CloudFront logs, replication, Athena — stops alarming. This matters because the log mining on #8118 shows denial traffic against the -logs, -shared and -awsconfig buckets, which is precisely the population most likely to be service-invoked.

Suggested fix, consistent with the idiom already used three lines above:

_or(
    '$.eventSource != "s3.amazonaws.com"',
    '$.userIdentity.accountId NOT EXISTS',
    '$.userIdentity.accountId != "anonymous"',
    '$.requestParameters.bucketName NOT EXISTS',
    f'$.requestParameters.bucketName != "{aws.qualified_bucket_name('*')}"'
)

Finding 2 (low): same root cause on bucketName

Anonymous AccessDenied with no requestParameters.bucketName — a denied ListAllMyBuckets, or requestParameters absent entirely — is suppressed regardless of target, since the bucket term is also false-on-absent. Verified. The bucketName NOT EXISTS disjunct in the snippet above covers this.

Finding 3 (low): scope is broader than the evidence in the issue

The exception is restricted neither to GetObject/readOnly nor to the storage bucket, so anonymous denied writes (PutObject, DeleteObject, PutBucketPolicy, PutBucketAcl) against any of our in-region buckets are now silent too.

My assessment is that this is an acceptable trade. A denied anonymous request is a non-event for confidentiality and integrity, and an anonymous request that succeeded carries no AccessDenied and was therefore never in this filter's scope to begin with. What is genuinely lost is early warning of internet-side enumeration of our buckets.

The compensating controls are in place and unaffected by this PR; all four were verified: the account-level aws_s3_account_public_access_block resource, the per-bucket aws_s3_bucket_public_access_block resources emitted by block_public_s3_bucket_access with block_public_acls and block_public_policy enabled, and the s3-account-level-public-access-blocks, s3-bucket-public-read-prohibited and s3-bucket-public-write-prohibited rules in the conformance pack.

Finding 4 (informational): no bypass via the wildcard

Two bypass shapes were probed and both still alarm, confirming that the wildcard is anchored at both ends and that the pattern is correctly account- and region-scoped:

  • edu-ucsc-gi-platform-anvil-dev-x.us-east-1.attacker → alarm, so the suffix cannot be extended
  • another Azul account's bucket, edu-ucsc-gi-platform-hca-prod-storage-prod.us-east-1 → alarm

Bucket-name squatting on the edu-ucsc-gi-<account>-* prefix is theoretically in-pattern but not reachable, since our trail only records S3 data events for buckets in our own account; an anonymous request against a third party's bucket never enters the log group. No action needed.

The failure direction is also safe: had * not been honored under !=, the exception would simply never fire and the alarm would keep alarming. It is honored, so this is moot.

Finding 5 (informational): the compliance deviation is undocumented

This alarm implements Security Hub CloudWatch.2 / CIS 4.1, and the file flags its first intentional deviation in a comment above the alarm. This PR adds a second deviation with no rationale. Recommend a short inline comment citing #8118, matching the existing style, so the deviation remains auditable.

Recommendation

Approve conditional on fixing finding 1. It is a small change that restores the intended scope, follows the idiom already present in the same expression, and was confirmed to preserve the suppression the issue actually asked for. Findings 3 and 5 are documentation asks, not blockers.

@hannes-ucsc hannes-ucsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify Claude's SDD findings 1 and 2.

I am not sure these fields can ever be missing.

We will accept 3.

@hannes-ucsc hannes-ucsc removed their assignment Aug 28, 2026
@nadove-ucsc

Copy link
Copy Markdown
Contributor Author

Finding 1 empirically confirmed as correct. Requests without userIdentiy.accountId are rare, at least on dev, but do exist:

CloudWatch Log Analytics Results
Region: us-east-1
Query:

SOURCE "arn:aws:logs:us-east-1:122796619775:log-group:azul-trail-dev" START=2025-12-01T08:00:00.000Z END=2025-12-14T04:25:12.000Z |
fields @timestamp, @message
| filter eventSource = "s3.amazonaws.com"
      and strcontains(errorCode, "AccessDenied")
      and not ispresent(userIdentity.accountId)
 | limit 1
@timestamp @message
2025-12-09 11:47:49.725 {"eventVersion":"1.11","userIdentity":{"type":"AWSService","invokedBy":"s3.amazonaws.com"},"eventTime":"2025-12-09T11:46:28Z","eventSource":"s3.amazonaws.com","eventName":"PutObject","awsRegion":"us-east-1","sourceIPAddress":"s3.amazonaws.com","userAgent":"s3.amazonaws.com","errorCode":"AccessDenied","errorMessage":"Access Denied","requestParameters":{"bucketName":"edu-ucsc-gi-platform-hca-dev-logs.us-east-1","Host":"edu-ucsc-gi-platform-hca-dev-logs.us-east-1.s3.us-east-1.amazonaws.com","x-amz-acl":"bucket-owner-full-control","key":"inventory/edu-ucsc-gi-platform-hca-dev-storage-dev.us-east-1/azul-inventory-dev/data/"},"responseElements":null,"additionalEventData":{"SignatureVersion":"SigV4","CipherSuite":"TLS_AES_128_GCM_SHA256","bytesTransferredIn":0,"AuthenticationMethod":"AuthHeader","x-amz-id-2":"MiWhC4zyQ4fDtN6SyDeVorRpMSSAO9WQ+licm3U25yZnfVzqHRU4AnaTXYun/cXt095WaRsfJmBaMqgZibBVhLN2T4qpytCLH3UDKxLfLY0=","bytesTransferredOut":275},"requestID":"9QB10PTN6AY1831S","eventID":"487f41b3-f0cb-35a2-bede-458e02b2fa0b","readOnly":false,"resources":[{"accountId":"122796619775","type":"AWS::S3::Bucket","ARN":"arn:aws:s3:::edu-ucsc-gi-platform-hca-dev-logs.us-east-1"},{"type":"AWS::S3::Object","ARN":"arn:aws:s3:::edu-ucsc-gi-platform-hca-dev-logs.us-east-1/inventory/edu-ucsc-gi-platform-hca-dev-storage-dev.us-east-1/azul-inventory-dev/data/"}],"eventType":"AwsApiCall","managementEvent":false,"recipientAccountId":"122796619775","sharedEventID":"eb1c22d8-d056-4297-b7db-6fd1c2d19fb9","vpcEndpointId":"s3.amazonaws.com","vpcEndpointAccountId":"s3.amazonaws.com","eventCategory":"Data"}

@nadove-ucsc

Copy link
Copy Markdown
Contributor Author

Finding 2 also empirically confirmed as correct: bucketName can be absent, and very frequently is (269 such events just today). There are no examples of such a request actually triggering an alarm, but since it's a real condition that can occur, it seems prudent to address it anyway.

@nadove-ucsc
nadove-ucsc force-pushed the issues/nadove-ucsc/8118-frequent-access-denied branch 2 times, most recently from 1d2c0f6 to 96bcea6 Compare September 10, 2026 09:09
@nadove-ucsc

Copy link
Copy Markdown
Contributor Author

(Contains content generated by Claude)

Re-test of the api_unauthorized metric filter after fixup

The pattern generated by terraform/shared/shared.tf.json.template.py at 96bcea6 was re-tested with aws logs test-metric-filter against nine real CloudTrail events from the dev account (122796619775), using the pattern as rendered for that account:

{(($.errorCode = "*UnauthorizedOperation") || ($.errorCode = "AccessDenied*")) && (($.userIdentity.invokedBy NOT EXISTS) || (($.userIdentity.invokedBy != "config.amazonaws.com") && ($.userIdentity.invokedBy != "resource-explorer-2.amazonaws.com"))) && (($.eventSource != "s3.amazonaws.com") || ($.userIdentity.accountId NOT EXISTS) || ($.userIdentity.accountId != "anonymous") || ($.requestParameters.bucketName NOT EXISTS) || ($.requestParameters.bucketName != "edu-ucsc-gi-platform-hca-dev-*.us-east-1"))}

Six of the nine events match, exactly as intended:

# eventSource eventName Caller develop 065b039 96bcea6
0 s3 HeadBucket (…shared) IAM user in 652235167018 yes yes yes
1 s3 ListObjects (…mirror-dev) anonymous yes no no
2 detective ListOrganizationAdminAccounts config.amazonaws.com no no no
3 macie2 ListFindingsFilters resource-explorer-2.amazonaws.com no no no
4 ecr BatchGetImage lambda.amazonaws.com, accountId absent yes yes yes
5 s3 PutObject (…logs) s3.amazonaws.com, accountId absent yes no yes
6 s3 GetObject (…hca-prod-logs) in-account role yes yes yes
7 logs GetLogGroupFields account 289950828509 yes yes yes
8 lambda GetFunction20150331v2 type Unknown yes yes yes

Event 1 remains the only event the new exception suppresses — the anonymous foreign-VPC request this issue is about. Every other event alarms exactly as it does on develop, so the fixup leaves the filter's coverage unchanged apart from the intended suppression.

Event 5 is what the NOT EXISTS guards restore. It is a real S3 inventory report delivery denied against the logs bucket, one of 65 such events in the retained year. Its userIdentity is {"type": "AWSService", "invokedBy": "s3.amazonaws.com"} with no accountId field at all; because != evaluates to false on an absent field, $.userIdentity.accountId != "anonymous" was false and the exception swallowed it at 065b039. Note that invokedBy is neither config.amazonaws.com nor resource-explorer-2.amazonaws.com, so the pre-existing exception does not cover it either.

The second guard was verified the same way: an anonymous AccessDenied carrying no requestParameters.bucketName matches at 96bcea6 and did not at 065b039. No such event occurs in the trail — all 178 anonymous S3 records in the retained year carry a bucket name — so this guard is defensive. It is included for symmetry with the accountId guard, and it cannot produce a false negative.

Both guards can only ever make the filter match more, never less, so the fixup cannot silence anything that alarms today. Relative to develop, alarming S3 AccessDenied events in dev over the retained year go 148 → 91, all 57 suppressed events being anonymous; at 065b039 they went 148 → 26. The fixup narrows the reduction to the one the issue asked for. (Counts are events rather than alarms; the alarm is Sum > 0 over a five-minute period, so several events collapse into one alarm.)

Event IDs
# eventTime eventID
0 2026-08-19T20:23:37Z 516e0d19-f874-30b9-bf50-468c160adaac
1 2026-09-09T04:26:55Z be4448ef-1407-3719-80f2-be16333e2831
2 2026-09-10T08:56:04Z 2d140a74-518a-4093-abc4-88c2d9afd55c
3 2026-09-04T04:44:35Z c9a3efe9-db02-4877-874b-d2fa9484fe47
4 2026-08-26T06:22:58Z c476c29b-5c83-3224-a077-1007241e22e6
5 2025-12-09T11:46:28Z 487f41b3-f0cb-35a2-bede-458e02b2fa0b
6 2026-06-04T21:22:25Z aa856f86-0d8a-36e2-bfae-744e8b3a0ef9
7 2026-09-02T04:55:00Z b003a860-99b2-31a1-82c4-3b195d10ae49
8 2026-02-25T01:21:00Z 39ee61bb-ce12-3e7d-aa88-2e853a64639f

@hannes-ucsc

Copy link
Copy Markdown
Member

(Posted by Claude Code)

Security design review, round 2 (head 96bcea6)

Follow-up to the security design review above. The checklist posted there still applies unchanged: … affect monitoring of the system remains the only affected category.

Findings 1 and 2 are fixed, and verified

The fixup adds exactly the two disjuncts proposed, in the proposed order. I re-ran an 18-case matrix through aws logs test-metric-filter against three patterns: base as it stands on develop, v1 as first reviewed, and head.

case base v1 head expected
AWSService, accountId absent, our bucket (finding 1) alarm alarm alarm
anonymous, requestParameters absent (finding 2) alarm alarm alarm
anonymous, bucketName absent, i.e. ListBuckets (finding 2) alarm alarm alarm
userIdentity absent entirely alarm alarm alarm
verbatim #8118 record, the intended suppression alarm suppress
anonymous, foreign bucket alarm alarm alarm alarm

All five cases that regressed under v1 are restored, and the intended suppression still holds. The last of those was confirmed against the record quoted verbatim in the body of #8118, not a reduced stand-in. The rendered pattern is 507 characters against a limit of 1024, and the longest added line is 103 characters against the project limit of 120, so make pep8 is unaffected.

Correction to the first review

I rated finding 1 medium, reasoning in part that the denials against the -logs, -shared and -awsconfig buckets in the tables on #8118 were most likely AWS-service-invoked. I have since checked the data rather than inferring it. Over 90 days and 11.7M records in azul-trail-dev, every S3 denial was userIdentity.type: AWSAccount with accountId present — 58 anonymous and 9 not — and none were AWSService-shaped. The scenario is therefore real in the logic of the filter but unobserved in dev, and medium overstated what the evidence supported. Since the fix is correct and costs nothing, this changes nothing about the outcome.

That evidence is thin by nature: dev sees 67 S3 denials per 90 days, whereas the events motivating this issue occurred in prod. Running the same queries against prod would firm this up considerably, and I'm happy to do so on request.

New observation (informational, no action recommended)

NOT EXISTS is false for an explicit JSON null, and so is !=, so an accountId or bucketName of null still suppresses. This is the same class as findings 1 and 2, one step further out, and it is not far-fetched in principle, since CloudTrail does emit explicit nulls for some fields — responseElements: null appears in the #8118 record itself.

IS NULL turns out to be accepted filter syntax, whereas = NULL, != NULL and IS NOT NULL are all rejected by the API. Adding two IS NULL disjuncts closes the residue with no regressions across the matrix, at 589 characters.

My recommendation is nevertheless to leave this alone. The same 90-day query found no S3 denial with a null accountId or bucketName, so there is no evidence CloudTrail ever emits nulls in those two positions, and seven disjuncts in one expression is a poor trade against readability for an unobserved shape. Recording it here so that the decision is explicit rather than overlooked.

Still open from the first review

Finding 5 is unaddressed: the comment above the alarm is unchanged, so the second deviation from Security Hub CloudWatch.2 remains undocumented. This is a documentation ask, not a blocker.

Recommendation

Approve. The blocking finding is fixed and verified, and nothing new blocks.

@hannes-ucsc hannes-ucsc removed their assignment Sep 11, 2026
@nadove-ucsc
nadove-ucsc force-pushed the issues/nadove-ucsc/8118-frequent-access-denied branch from 96bcea6 to 41ff987 Compare September 11, 2026 19:14
@nadove-ucsc nadove-ucsc added the sandbox [process] Resolution is being verified in sandbox deployment label Sep 11, 2026
@nadove-ucsc
nadove-ucsc merged commit 1db6317 into develop Sep 12, 2026
10 checks passed
@nadove-ucsc
nadove-ucsc deleted the issues/nadove-ucsc/8118-frequent-access-denied branch September 12, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 review [process] Lead requested changes once deploy:shared [process] PR requires deploying `shared` component sandbox [process] Resolution is being verified in sandbox deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frequent AccessDenied requests against manifest bucket from foreign VPC

3 participants