Skip to content

fix(aws): keep the regions cache per account - #10271

Open
groman92 wants to merge 1 commit into
mainfrom
fix/region-cache-per-account
Open

groman92 wants to merge 1 commit into
mainfrom
fix/region-cache-per-account

Conversation

@groman92

@groman92 groman92 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary of your changes

In organization mode, cloudbeat did not collect an opt-in region for a member account when the first account had that region disabled. This PR fixes it.

Cloudbeat makes the regional AWS clients from the result of ec2:DescribeRegions. This result holds only the regions that are enabled for the calling account. cachedRegionSelector kept this result in a process-wide cache with one fixed key (AllRegionSelectorCache) and a TTL of 720h. In organization mode, one cloudbeat process collects data for all member accounts. Thus the first account wrote the cache, and all the other accounts read its list.

The result for a member account that has a region enabled when the first account has it disabled:

  • S3 buckets in that region show Error: aws client not found, because ListBuckets is global.
  • EC2, RDS, Lambda, and the other multi-region fetchers skip that region and write no error.

This occurs in CSPM (aws_org_preset.go) and in Asset Discovery (initOrgFetchers).

The fix puts the access key ID of the credentials in the cache key. Each member account has its own assumed-role session, so each account gets its own region list. This change adds no API call. Retrieve returns the cached credentials, and the first DescribeRegions call needs these credentials anyway. If Retrieve fails, Regions returns the error, and the caller uses the same fallback to cfg.Region as before.

Screenshot/Data

TestCachedRegionSelector_CachePerAccount fails on main and passes on this branch:

expected: []string{"us-east-1", "eu-west-1"}
actual  : []string{"us-east-1"}

Related Issues

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary README/documentation (if appropriate)

The regions cache used one fixed key for all accounts. In organization
mode, the first account set the region list for all member accounts.
If that account had an opt-in region disabled, the other accounts got
no clients for that region. S3 logged "aws client not found", and the
other fetchers skipped the region with no error.

The cache key now includes the access key ID of the credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mergify

mergify Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @groman92? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@groman92
groman92 marked this pull request as ready for review November 30, 2026 16:25
@groman92
groman92 requested a review from a team as a code owner November 30, 2026 16:25
@mergify

mergify Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

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.

1 participant