Skip to content

fix(auth): atmos.Component() nested lookups could lose/reuse wrong identity - #2712

Merged
Andriy Knysh (aknysh) merged 4 commits into
mainfrom
osterman/eks-pod-identity-regression-1222
Jul 10, 2026
Merged

Andriy Knysh (aknysh) merged 4 commits into
mainfrom
osterman/eks-pod-identity-regression-1222

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

what

  • Fixes internal/exec/terraform_nested_auth_helper.go so the nested-auth cache (nestedAuthManagerCache, added in fix(stacks): scope and cache per-component auth in describe stacks #2652/perf(stacks): dedupe per-identity auth in nested terraform.state resolution #2656) never caches a result resolved through authContextWrapper — its GetChain() always returns an empty slice by design, so two different real identities propagated this way could otherwise collide on the same cache key and silently reuse the wrong identity's AuthManager.
  • Fixes internal/exec/template_funcs_component.go (atmos.Component()) so it resolves a nested target's own auth: section (via resolveAuthManagerForNestedComponent) instead of always reusing the enclosing component's credentials verbatim — bringing it in line with how !terraform.state/!terraform.output already behave.
  • Adds regression tests for both (TestBuildComponentAuthCacheKey_AuthContextWrapperNeverCaches, TestResolveComponentFuncAuthManager) and a docs/fixes write-up.

why

  • A user reported atmos list instances regressing from v1.221.0 to v1.222.0 under GitHub Actions/OIDC auth (no ambient AWS credentials): a Go template calling atmos.Component(...) to fetch a nested component's terraform output failed with no valid credential sources found ... no EC2 IMDS role found — meaning the subprocess got zero AWS credential material and fell through to the (nonexistent, off-EC2) instance-metadata provider.
  • Both defects were introduced or exposed by the per-component/nested auth-caching optimizations added in v1.222.0 (fix(stacks): scope and cache per-component auth in describe stacks #2652, perf(stacks): dedupe per-identity auth in nested terraform.state resolution #2656) and match the same symptom already fixed once this cycle in the terraform-hooks path (docs/fixes/2026-06-27-store-hook-inherit-default-identity.md).
  • The user's own component topology (nested target with no auth: override of its own) isn't fully explained by these two fixes alone; that residual uncertainty and a debug-log diagnostic for further narrowing are documented in docs/fixes/2026-07-09-atmos-component-nested-auth-cache-collision.md.

references

…rong 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]>
@atmos-pro

atmos-pro Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/m Medium size PR label Jul 9, 2026
@osterman Erik Osterman (Cloud Posse) (osterman) added the patch A minor, backward compatible change label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6e72fc17-7d30-426a-a4df-5f2911b0f1a8

📥 Commits

Reviewing files that changed from the base of the PR and between d9c73ea and 9dc76e9.

📒 Files selected for processing (2)
  • internal/exec/terraform_output_getter_test.go
  • internal/exec/yaml_func_terraform_output_authcontext_test.go

📝 Walkthrough

Walkthrough

The change prevents wrapper-based nested auth cache reuse, resolves target-specific auth for nested atmos.Component() calls, and extends nested terraform output to resolve the target component’s auth context. Tests and documentation cover cacheability, fallback, auth-disabled behavior, nil contexts, and output auth handling.

Changes

Nested authentication behavior

Layer / File(s) Summary
Disable wrapper-rooted cache keys
internal/exec/terraform_nested_auth_helper.go, internal/exec/terraform_nested_auth_cache_test.go, docs/fixes/...
buildComponentAuthCacheKey skips caching for authContextWrapper parents, with tests and documentation covering the collision scenario.
Resolve nested component auth
internal/exec/template_funcs_component.go, internal/exec/template_funcs_component_test.go, docs/fixes/...
atmos.Component() resolves nested auth through resolveComponentFuncAuthManager, preserves disabled and fallback behavior, and passes the resolved manager into component execution.
Resolve nested output auth
internal/exec/terraform_output_getter.go, internal/exec/terraform_output_getter_test.go, internal/exec/yaml_func_terraform_output.go, internal/exec/yaml_func_terraform_output_authcontext_test.go, docs/fixes/...
terraform output resolves the nested target’s auth, propagates auth-disabled wrappers, and keeps the enclosing auth when resolution is unavailable; tests cover the new path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • cloudposse/atmos#2656: Introduces the nested auth memoization and resolution behavior that this change refines for wrapper-rooted identities and nested output lookup.

Suggested reviewers: aknysh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main auth regression fixed in nested atmos.Component() lookups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/eks-pod-identity-regression-1222

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 9, 2026
…dentity

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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/fixes/2026-07-09-atmos-component-nested-auth-cache-collision.md (1)

74-125: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Split the follow-up material out of this fix note.

The open question and deferred audit items are useful, but they read like separate investigations rather than part of this regression write-up. Moving them to a separate issue or appendix would keep this doc focused and reduce staleness.

🤖 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 `@docs/fixes/2026-07-09-atmos-component-nested-auth-cache-collision.md` around
lines 74 - 125, Move the open question and deferred audit items out of this fix
note so the document stays focused on the resolved regression. Keep only the
specific nested-auth cache collision fix summary in this file, and relocate the
broader follow-up material into a separate issue, appendix, or follow-up doc;
adjust the surrounding prose in the markdown note so it no longer reads like an
ongoing investigation.
🤖 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 `@internal/exec/terraform_output_getter_test.go`:
- Around line 14-24: Replace the hand-written fakeNestedOutputAuthManager stub
with the generated pkg/auth/types.NewMockAuthManager mock in the
terraform_output_getter_test setup. Configure the mock’s GetStackInfo behavior
to return the desired schema.ConfigAndStacksInfo instead of relying on the
embedded nil auth.AuthManager interface, and update the test code to use the
mock consistently with the existing mockgen pattern.

---

Nitpick comments:
In `@docs/fixes/2026-07-09-atmos-component-nested-auth-cache-collision.md`:
- Around line 74-125: Move the open question and deferred audit items out of
this fix note so the document stays focused on the resolved regression. Keep
only the specific nested-auth cache collision fix summary in this file, and
relocate the broader follow-up material into a separate issue, appendix, or
follow-up doc; adjust the surrounding prose in the markdown note so it no longer
reads like an ongoing investigation.
🪄 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: 766b0ae5-d884-419f-b0a8-45fc649b3ccb

📥 Commits

Reviewing files that changed from the base of the PR and between 99078ab and d9c73ea.

📒 Files selected for processing (5)
  • docs/fixes/2026-07-09-atmos-component-nested-auth-cache-collision.md
  • internal/exec/template_funcs_component.go
  • internal/exec/terraform_output_getter.go
  • internal/exec/terraform_output_getter_test.go
  • internal/exec/yaml_func_terraform_output.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/template_funcs_component.go

@codecov

codecov Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.18750% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.18%. Comparing base (33d1a0d) to head (fc72a1e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/template_funcs_component.go 86.36% 2 Missing and 1 partial ⚠️
internal/exec/yaml_func_terraform_output.go 80.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2712   +/-   ##
=======================================
  Coverage   81.18%   81.18%           
=======================================
  Files        1633     1633           
  Lines      154360   154413   +53     
=======================================
+ Hits       125311   125365   +54     
+ Misses      22123    22121    -2     
- Partials     6926     6927    +1     
Flag Coverage Δ
unittests 81.18% <92.18%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/exec/terraform_nested_auth_helper.go 75.00% <100.00%> (+0.36%) ⬆️
internal/exec/terraform_output_getter.go 100.00% <100.00%> (ø)
internal/exec/yaml_func_terraform_output.go 82.55% <80.00%> (+0.05%) ⬆️
internal/exec/template_funcs_component.go 84.26% <86.36%> (+2.07%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…per 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]>
@aknysh
Andriy Knysh (aknysh) merged commit 708f70e into main Jul 10, 2026
72 checks passed
@atmos-pro

atmos-pro Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@aknysh
Andriy Knysh (aknysh) deleted the osterman/eks-pod-identity-regression-1222 branch July 10, 2026 01:31
@github-actions

Copy link
Copy Markdown

These changes were released in v1.223.0-rc.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants