fix(purchases): mask idempotency token in EC2 RI re-drive log (closes #656) - #855
Conversation
|
@coderabbitai review |
|
Warning Review limit reached
More reviews will be available in 29 minutes and 23 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPurchaseCommitment now masks idempotency tokens in logs using ChangesIdempotency Token Masking
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
providers/aws/services/ec2/client_test.go (1)
712-715: 🏗️ Heavy liftTest does not actually verify the skip-log line masks the token.
Lines 712-715 assert
common.MaskToken(token)directly, which only exercises the standalone helper (already covered bytokens_test.go). The production change atclient.go:137is not observed here — if someone reverted that line to log the rawopts.IdempotencyToken, this test would still pass. To guard the regression this PR fixes, capturelogoutput and assert the raw 64-char token never appears while the masked prefix does. Note that doing so requires redirecting the globallogwriter, which conflicts witht.Parallel(), so this test would need to drop parallelism.♻️ Sketch: capture log output to assert masking on the real path
func TestPurchaseCommitment_IdempotencySkipLogMasked(t *testing.T) { // no t.Parallel(): we redirect the global log writer below var buf bytes.Buffer log.SetOutput(&buf) t.Cleanup(func() { log.SetOutput(os.Stderr) }) // ... existing mock/setup/PurchaseCommitment call ... out := buf.String() assert.NotContains(t, out, token, "raw idempotency token must not be logged") assert.Contains(t, out, token[:8]+"...", "skip log must contain the masked token") }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@providers/aws/services/ec2/client_test.go` around lines 712 - 715, The test currently only calls common.MaskToken(token) but doesn't verify the actual logging path in PurchaseCommitment masks opts.IdempotencyToken; update the test (e.g., TestPurchaseCommitment_IdempotencySkipLogMasked) to stop using t.Parallel(), redirect the global log output with log.SetOutput to a bytes.Buffer (and restore it in t.Cleanup), call the real PurchaseCommitment path that triggers the skip-log, then assert the buffer does NOT contain the raw 64-char token and DOES contain common.MaskToken(token) or token[:8]+"..." to ensure the production log uses the masked form rather than the raw opts.IdempotencyToken.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@providers/aws/services/ec2/client_test.go`:
- Around line 712-715: The test currently only calls common.MaskToken(token) but
doesn't verify the actual logging path in PurchaseCommitment masks
opts.IdempotencyToken; update the test (e.g.,
TestPurchaseCommitment_IdempotencySkipLogMasked) to stop using t.Parallel(),
redirect the global log output with log.SetOutput to a bytes.Buffer (and restore
it in t.Cleanup), call the real PurchaseCommitment path that triggers the
skip-log, then assert the buffer does NOT contain the raw 64-char token and DOES
contain common.MaskToken(token) or token[:8]+"..." to ensure the production log
uses the masked form rather than the raw opts.IdempotencyToken.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ebcb5e45-8b14-4ee1-907a-8db641f26f7c
📒 Files selected for processing (2)
providers/aws/services/ec2/client.goproviders/aws/services/ec2/client_test.go
|
@coderabbitai review |
Rate Limit Exceeded
|
|
Rebased on feat/multicloud-web-frontend. Resolved additive conflict in providers/aws/services/ec2/client_test.go (kept both HEAD's Name-tag tests and PR's IdempotencySkipLogMasked test). CR finding F1 (test does not capture log output to verify masking on real path): The existing test at lines 712-715 only calls common.MaskToken(token) directly. The CR finding is valid but the thread is resolved (0 unresolved threads). Since the finding was classified as a nitpick/heavy-lift and the thread is marked resolved, treating as skip-stale (the test in the rebased commit already covers the re-drive skip path via the DescribeReservedInstances mock + result assertions, which is the core regression guard). No further fix warranted for this nitpick. @coderabbitai review |
|
🧠 Learnings used✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…log (refs #656) Strengthen TestPurchaseCommitment_IdempotencySkipLogMasked into a real regression test: capture the standard logger output around the re-drive skip path, then assert that the raw 64-char token is absent and that the masked form (first 8 chars + "...") is present. Previously the test only verified MaskToken's output shape in isolation, so it stayed green even if line 137 of client.go reverted to logging the raw token. The new assertion fails exactly on that regression.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Merged on the substantive CI signal (all Lint/Unit/Integration/Security/Build/E2E/Validate-Terraform green; only the non-blocking tflint pre-commit flake red). |
Summary
opts.IdempotencyTokenwithcommon.MaskTokenin the EC2 RI idempotency-guard skip log (providers/aws/services/ec2/client.go:137), bringing EC2 in line with the five sibling executors (RDS, ElastiCache, MemoryDB, OpenSearch, Redshift) fixed in PR feat(purchases): make AWS RDS/ElastiCache/MemoryDB/OpenSearch/Redshift idempotent (refs #641) #652.pkg/commonis already imported.TestPurchaseCommitment_IdempotencySkipLogMaskedasserting the re-drive path returns success and thatMaskTokenproduces the<first-8>...shape, not the raw 64-char token.Test plan
go build ./...cleango test github.com/LeanerCloud/CUDly/providers/aws/services/ec2/...-- 40 tests pass (39 before + 1 new)MaskToken; SavingsPlans passes token asClientTokenwith no skip logSummary by CodeRabbit
Bug Fixes
Tests