Repository navigation
Conversation
Cost Explorer returns linked-account recommendations to a payer, but a purchase call buys in the caller's own account. The purchase path never compared rec.Account with the credentials' account, so a payer run could commit the payer account to a linked account's usage. Both purchase entry points now resolve the caller account with STS GetCallerIdentity (failing the run if it cannot) and validatePurchasePreconditions rejects a recommendation whose account differs, on dry runs too. Refs #2191 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reached
This review includes 7 billable files and costs up to $1.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 45 minutes for your next included review. View limit details
Comment |
Member
Author
|
Superseded by #2196 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2191
What
Recommendations are fetched with linked-account scope, so a payer run gets rows for other accounts, but
PurchaseCommitmentbuys in the caller's own account. Nothing comparedrec.Accountwith the credentials' account, so a purchase would commit the payer account to a linked account's usage (audit: rows for under credentials for ).withCallerAccountresolves the account with STSGetCallerIdentityand stores it inConfig.CallerAccountID. It runs in both purchase entry points (runPurchaseAndReport,runToolFromCSV), on dry runs too, and fails the run if the account cannot be resolved.validatePurchasePreconditions(used by the main pipeline and the CSV loop) now rejects a recommendation whoseAccountdiffers, withrecommendation is for account X but the credentials are for account Y; cross-account purchases are not supported, so run with credentials for account X. The row is recorded as a failed result and audit entry; other rows proceed. Rows with an empty account (CSV may omit it) are not compared.go.mod:service/stsmoves from indirect to direct (already in the module graph).Tests (mocks only; no purchase API is called anywhere)
TestCheckPurchaseAccount,TestPurchaseSingleRec_RefusesOtherAccountsRecommendation(dry and real),TestProcessPurchaseLoop_RefusesOtherAccountsRecommendationWithoutPurchasing(mock client sees exactly onePurchaseCommitment, for the caller's own row),TestWithCallerAccount.TestMainstubs the STS fetcher to return an empty account, which switches the check off for existing tests that do not setCallerAccountID.Fail before (guard body neutered):
After:
go test ./cmdpasses (35s, skippingTestQueryMajorEngineVersions_ErrorHandling, which hangs locally in this session on a goroutine atmulti_service_engine_versions_test.go:814independent of this change; it passed in an earlier full run).go vetclean; golangci-lint panics locally on this toolchain, pre-commit hooks (gofmt, vet, gocyclo) pass.Live dry run (read-only, no
--purchase), profile shift-prd ()cudly --services ec2 --regions us-east-1 --term 1 --payment no-upfront --coverage 100:The CSV row has
Success=falseand that error. Before this change the same row was reported as a successful dry-run purchase.Overlap
cli#2186 (merged) and cli#2145 (CSV loader,
multi_service_csv*.go) touch none of these lines. Same files as cli#2192 (fetch errors), different functions.🤖 Generated with Claude Code