Repository navigation
fix(stacks): scope and cache per-component auth in describe stacks - #2652
Andriy Knysh (aknysh) merged 1 commit into
Conversation
In processComponentEntry, per-component authentication ran before the stack and component filters and was never memoized. Any auth-enabled ExecuteDescribeStacks caller (atmos describe stacks, list values/instances, terraform --all/--query) authenticated every component in every stack before discarding the out-of-scope ones, and re-authenticated each same-identity component from scratch. On a large multi-stack repo, `atmos describe stacks -s <stack>` authenticates components in stacks other than the one requested and effectively hangs. cloudposse#2646 sidestepped this for `atmos secret list` by disabling per-component auth there; this fixes the root cause in the shared processor for every other caller. - Move the stack and component filters above resolveComponentAuthManager so only in-scope components authenticate. Auth still precedes its consumers (BuildTerraformWorkspace, template and YAML-function processing). - Add a pass-scoped cache keyed by the parent chain plus a deterministic JSON fingerprint of the component auth section, so components sharing an auth section reuse one authenticated manager instead of re-running the full auth cycle (credential writes, file locks, keyring rebuilds). - Add regression tests (out-of-scope skip + cache reuse). Measured with the identical command (`describe stacks -s <stack> --logs-level Debug`, 45s budget, only the atmos binary varies): the latest release (v1.221.1) and current main both fail to complete within 45s, authenticating mostly out-of-scope components, while this change completes in ~18s (43 auths; in-scope processor-path auth reduced to 2). Related to cloudposse#2639.
|
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 (3)
📝 WalkthroughWalkthroughMoves stack and component-inclusion filter evaluation ahead of per-component auth resolution in ChangesDescribe-stacks per-component auth scoping and caching fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2652 +/- ##
==========================================
+ Coverage 80.02% 80.06% +0.03%
==========================================
Files 1361 1361
Lines 127449 127469 +20
==========================================
+ Hits 101994 102056 +62
+ Misses 19790 19749 -41
+ Partials 5665 5664 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Andriy Knysh (aknysh)
left a comment
There was a problem hiding this comment.
thanks Brian Ojeda (@sgtoj)
e56077c
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.7. |
…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
resolveComponentAuthManagerinprocessComponentEntryso only in-scope components authenticate (auth still precedesBuildTerraformWorkspace, template, and YAML-function processing).why
Any auth-enabled
ExecuteDescribeStackscaller —atmos describe stacks,atmos list values/instances,atmos terraform --all/--query— resolves per-component auth before the stack/component filters and never reuses it. On a multi-stack repo where components declare their owndefault: trueidentity,atmos describe stacks -s <stack>authenticates components in other stacks before discarding them, and re-authenticates each same-identity component from scratch — so the command effectively hangs.Per-component auth exists only to populate
info.AuthContextfor that component's later template (atmos.Component(...)) and YAML-function (!terraform.state,!terraform.output) processing, which is skipped for filtered-out components — so authenticating them is wasted work.#2646 fixed
atmos secret listby disabling per-component auth for that command; it did not touch the shared processor, so every other caller still hits this.Measured with the identical command
atmos describe stacks -s <stack> --logs-level Debugunder a 45s budget, only the atmos binary varying:main(aa68d85be)With the fix, in-scope processor-path authentications drop to 2 and out-of-scope ones to zero (the ~42 remaining auths are legitimate nested
!terraform.output/atmos.Componentreads).references
atmos secret list -s <stack>(without-c) hangs: authenticates once per component across all stacks instead of scoping to the requested stack #2639; supersedes fix(stacks): scope per-component auth to requested stack/components #2642 and perf(stacks): cache per-component auth within a describe-stacks pass #2644.docs/fixes/2026-06-22-describe-stacks-scope-and-cache-per-component-auth.md