Repository navigation
perf(stacks): dedupe per-identity auth in nested terraform.state resolution - #2656
Andriy Knysh (aknysh) merged 2 commits into
Conversation
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a process-scoped ChangesNested AuthManager Deduplication
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 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)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/exec/terraform_nested_auth_cache_test.go (1)
23-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a table-driven layout for the multi-scenario keying test.
This test validates several distinct scenarios in one body; converting to table-driven cases will align with repo test conventions and make future additions safer.
As per coding guidelines, "
**/*_test.go: Use table-driven tests for testing multiple scenarios in Go."🤖 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 `@internal/exec/terraform_nested_auth_cache_test.go` around lines 23 - 55, Refactor TestBuildComponentAuthCacheKey to use table-driven testing by creating a test case struct containing the inputs (parent authentication manager and section data) and expected validation results, then define a slice of test cases covering all current scenarios (identical sections, different sections, same section with different parents, distinct parent chains, and unserializable sections), and finally replace the current inline assertion logic with a loop that iterates through the test cases and runs buildComponentAuthCacheKey with each case's inputs while validating the corresponding outputs.Source: Coding guidelines
🤖 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.
Inline comments:
In `@docs/fixes/2026-06-22-dedupe-nested-component-auth.md`:
- Around line 17-22: The fenced code block in the markdown file is missing a
language declaration on the opening backticks. To fix this, add a language
identifier (such as `text`) to the opening triple backticks of the code block
that contains the GetTerraformState function call hierarchy. Change the opening
from bare triple backticks to triple backticks followed by the language name.
---
Nitpick comments:
In `@internal/exec/terraform_nested_auth_cache_test.go`:
- Around line 23-55: Refactor TestBuildComponentAuthCacheKey to use table-driven
testing by creating a test case struct containing the inputs (parent
authentication manager and section data) and expected validation results, then
define a slice of test cases covering all current scenarios (identical sections,
different sections, same section with different parents, distinct parent chains,
and unserializable sections), and finally replace the current inline assertion
logic with a loop that iterates through the test cases and runs
buildComponentAuthCacheKey with each case's inputs while validating the
corresponding outputs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bc412463-661d-4877-88a6-1f4596e69cef
📒 Files selected for processing (5)
docs/fixes/2026-06-22-dedupe-nested-component-auth.mdinternal/exec/describe_stacks_component_processor.gointernal/exec/terraform_nested_auth_cache_test.gointernal/exec/terraform_nested_auth_helper.gointernal/exec/terraform_state_utils.go
…lution Extend the per-component AuthManager memoization beyond the top-level describe-stacks pass into the nested resolution path that runs while templates and YAML functions are evaluated. When a component references another via !terraform.state/!terraform.output, resolveAuthManagerForNestedComponent ran a full auth cycle (credential writes, file locks, keyring rebuilds) once per distinct target component, even when many targets share a single identity. The existing terraformStateCache only dedupes repeat reads of the same target. Add a process-scoped nestedAuthManagerCache keyed by parent chain + a deterministic JSON fingerprint of the auth section, extracted into a shared buildComponentAuthCacheKey so the processor and the nested path cannot drift. Only successful, non-nil results are cached; ResetStateCache clears it alongside the state cache. Reference docs/fixes/2026-06-22-dedupe-nested-component-auth.md. Related to cloudposse#2639.
c0eabf0 to
fac5b1e
Compare
|
Addressed the CodeRabbit review (amended into the single commit):
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2656 +/- ##
=======================================
Coverage 80.04% 80.05%
=======================================
Files 1361 1361
Lines 127499 127525 +26
=======================================
+ Hits 102059 102088 +29
+ Misses 19774 19771 -3
Partials 5666 5666
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
12f9e3d
into
cloudposse:main
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
These changes were released in v1.222.0-rc.8. |
…entity (#2712) * fix(auth): atmos.Component() nested lookups could lose or reuse the wrong identity Two defects in the v1.222.0 per-component/nested auth-caching work (#2652/#2656) could surface as "no valid credential sources found / no EC2 IMDS role found" under GitHub OIDC auth with no ambient AWS credentials: - authContextWrapper.GetChain() always returns an empty slice, which the nested-auth cache used to disambiguate parents. Two different real identities reaching a nested lookup via atmos.Component() or !terraform.state/!terraform.output could collide on the same cache key and silently reuse the wrong identity's AuthManager. Wrapper- rooted parents are now never cached. - atmos.Component() always fetched a target's terraform output using the enclosing component's credentials verbatim, unlike !terraform.state/!terraform.output, even when the target declared its own default-identity auth section. It now resolves the target's own auth via resolveAuthManagerForNestedComponent, falling back to the enclosing component's context as before. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(auth): !terraform.output never resolved the nested target's own identity The !terraform.output YAML function fetched a nested component's outputs using the enclosing component's authContext/authManager verbatim — the same defect just fixed for atmos.Component(). Only !terraform.state actually routed through resolveAuthManagerForNestedComponent; the target-aware resolution was lost when output fetching moved into pkg/terraform/output (which cannot call back into internal/exec). - defaultOutputGetter.GetOutput now resolves the target's own auth section via resolveNestedOutputAuth (target default identity wins; enclosing auth kept when the target has none, on resolver error, or when auth is disabled), mirroring GetTerraformState. - The YAML entry propagates AuthDisabled via authContextWrapper when no AuthManager exists, mirroring !terraform.state, so disabled-auth contexts never trigger target authentication. - Corrected the fix doc's false parity claim and recorded two audited same-class follow-ups (identity-less result-cache keys; store default-identity injection asymmetry). Tests: TestResolveNestedOutputAuth (8 sub-tests, written failing-first). Co-Authored-By: Claude Fable 5 <[email protected]> * test(auth): use generated MockAuthManager and cover AuthDisabled wrapper propagation Address PR #2712 review feedback and patch coverage: - Replace the hand-written fakeNestedOutputAuthManager stub with the mockgen-generated types.NewMockAuthManager, per the repo's mock-generation convention (CodeRabbit review). - Add TestAuthDisabledPropagatesWrapperToOutputGetter covering both branches of the new AuthDisabled wrapper propagation in processTagTerraformOutputWithContext — the uncovered lines behind the 60% patch coverage on yaml_func_terraform_output.go. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]> Co-authored-by: Andriy Knysh <[email protected]>
what
AuthManagermemoization introduced in fix(stacks): scope and cache per-component auth in describe stacks #2652 from the top-leveldescribe stackspass into the nested resolution path that runs while templates and YAML functions are evaluated (!terraform.state,!terraform.output,atmos.Component(...)).nestedAuthManagerCache, consulted byresolveAuthManagerForNestedComponent, keyed by the parent auth chain + a deterministic JSON fingerprint of the component's auth section.buildComponentAuthCacheKeyused by both the processor cache (fix(stacks): scope and cache per-component auth in describe stacks #2652) and this nested path, so the two keying strategies cannot drift.ResetStateCache()also clears the new cache (kept consistent with theterraformStateCacheit pairs with). Neither is reset in production.why
!terraform.statestill ran a full auth cycle (credential writes, file locks, keyring rebuilds) once per distinct target — even when every target resolves to the same identity.terraformStateCacheonly short-circuits a repeat read of the same target, not distinct targets that share an identity.Measured —
atmos describe stacks -s <stack>on a large real-world stack (credentials provided viaauth exec, 45s cap; only the binary under test varies):main(includes #2652)Output was verified equivalent to
main: the remaining run-to-run differences are pre-existingauto_provision_workdir_for_outputs/tofu outputprovisioning nondeterminism present on both builds (same identity resolved throughout, no new errors). A matched-output pair differed by fewer lines than themain-vs-mainnoise floor.The nested path is shared by
describe affected,list, andterraform --all/--query. On a large multi-component change, the full per-identity auth cycles duringdescribe affectedlikewise drop from scaling with the number of resolved components to roughly one-per-identity, with the rest served from the cache.test plan
go build ./... && go test ./internal/exec/...— new unit tests cover key behavior, dedupe-by-identity, parent-chain isolation, errors-not-cached, unserializable-section-not-cached, and theResetStateCachecoupling.custom-gcl run --new-from-rev=main→ 0 issues.references
atmos secret list -s <stack>(without-c) hangs: authenticates once per component across all stacks instead of scoping to the requested stack #2639docs/fixes/2026-06-22-dedupe-nested-component-auth.md