Skip to content

fix(stacks): scope per-component auth to requested stack/components - #2642

Closed
Brian Ojeda (sgtoj) wants to merge 2 commits into
cloudposse:mainfrom
sgtoj:fix/secret-list-stack-scope
Closed

Brian Ojeda (sgtoj) wants to merge 2 commits into
cloudposse:mainfrom
sgtoj:fix/secret-list-stack-scope

Conversation

@sgtoj

@sgtoj Brian Ojeda (sgtoj) commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

what

  • Scope describe stacks per-component authentication to the components the caller actually requested.
  • In processComponentEntry, the stack and component filters now run before resolveComponentAuthManager, so out-of-scope components are skipped without authenticating.
  • Add regression tests asserting the per-component auth resolver is not invoked for out-of-scope stacks/components.

why

  • atmos secret list -s <stack> (without --component) calls ExecuteDescribeStacks, which walks every stack file. Per-component auth — a full credential-file write + file lock + keyring rebuild — was resolved before the stack/component filters, so it authenticated every component in every other stack before discarding it.
  • The work scaled with the whole repo instead of the requested stack, so on large repos the command never reached its listing output (it appeared to hang). --component was fast only because it takes a separate single-component fast path.
  • Per-component auth exists solely to populate info.AuthContext for that component's later Go-template (atmos.Component(...)) and YAML-function (!terraform.state / !terraform.output) processing — which never runs for a filtered-out component, so resolving it first was pure waste.
  • The fix moves the filters ahead of auth; auth still precedes all of its consumers (BuildTerraformWorkspace, Go-template and YAML-function processing), so nothing downstream loses its AuthContext. This also benefits describe stacks -s and the list family.
  • Verified on a multi-stack repo with a SOPS aws-kms provider and a default identity: the command now returns promptly and authenticates only the requested stack plus the specific cross-stack components it actually references via !terraform.output / atmos.Component.

references

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a high-severity performance issue in atmos secret list -s <stack> where, without --component, the command could appear to hang by performing unnecessary authentication for out-of-scope components.
  • Documentation
    • Added a fix document describing the root cause, expected behavior, and how the fix was verified.
  • Tests
    • Added unit tests to confirm authentication is skipped when components don’t match the requested stack scope or are excluded by component filtering.

@sgtoj
Brian Ojeda (sgtoj) requested a review from a team as a code owner June 20, 2026 16:39
@atmos-pro

atmos-pro Bot commented Jun 20, 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 Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 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: dfe60701-1407-4606-8310-1869fd4b7150

📥 Commits

Reviewing files that changed from the base of the PR and between 4058bf9 and f27090b.

📒 Files selected for processing (3)
  • docs/fixes/2026-06-20-secret-list-stack-scope-per-component-auth.md
  • internal/exec/describe_stacks_component_processor.go
  • internal/exec/describe_stacks_component_processor_auth_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/exec/describe_stacks_component_processor_auth_test.go
  • internal/exec/describe_stacks_component_processor.go

📝 Walkthrough

Walkthrough

Reorders processComponentEntry so resolveComponentAuthManager and propagateAuth are called only after stack-scope and component-inclusion filters pass. Two regression tests verify the auth resolver is not invoked for out-of-scope components. A fix doc covers the symptom, root cause, and verification.

Changes

Auth Resolution Ordering Fix

Layer / File(s) Summary
Filter-before-auth reorder in processComponentEntry
internal/exec/describe_stacks_component_processor.go
Moves resolveComponentAuthManager and propagateAuth to run after shouldFilterByStack and component-inclusion checks. Adds comments clarifying auth must complete before template and YAML-function processing.
Regression tests for out-of-scope auth skip
internal/exec/describe_stacks_component_processor_auth_test.go
Adds TestProcessComponentEntry_OutOfScopeSkipsAuth with two test cases using a spy resolver that returns an error—verifying zero resolver calls and no returned error when a component is filtered out by stack scope or component inclusion.
Fix documentation
docs/fixes/2026-06-20-secret-list-stack-scope-per-component-auth.md
Documents the atmos secret list -s <stack> hang symptom, root cause in processComponentEntry, the fix, test verification steps, and a follow-up deduplication recommendation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

patch

Suggested reviewers

  • osterman
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main fix: reordering per-component auth to occur after stack/component filtering, which is the core change across all modified files.
Linked Issues check ✅ Passed The changes directly address issue #2639 by filtering components before auth resolution, eliminating unnecessary authentication cycles for out-of-scope components and enabling prompt command return.
Out of Scope Changes check ✅ Passed All changes stay focused on the scope-filtering and auth-ordering fix: documentation, core logic reordering, and targeted regression tests with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@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)
internal/exec/describe_stacks_component_processor_auth_test.go (1)

366-445: ⚡ Quick win

Consolidate these two skip-auth scenarios into one table-driven test.

The two tests are structurally the same and differ only by filter setup. A table-driven form will reduce duplication and make additional skip-path cases easier to extend.

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/describe_stacks_component_processor_auth_test.go` around lines
366 - 445, The two test functions
TestProcessComponentEntry_OutOfScopeStackSkipsAuth and
TestProcessComponentEntry_OutOfScopeComponentSkipsAuth are structurally
identical and differ only in their filter setup and component inputs.
Consolidate them into a single table-driven test by defining a slice of test
case structs that capture the differences (such as filterByStack value,
components filter slice, stackFileName, and componentName), then iterate through
the table executing the same test logic for each scenario. This will eliminate
code duplication and make it easier to add additional skip-path test cases in
the future.

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-20-secret-list-stack-scope-per-component-auth.md`:
- Around line 32-38: The fenced code block containing the log output starting
with "DEBU Created component-specific AuthManager..." is missing a language
identifier, which triggers markdownlint rule MD040. Add the language identifier
"text" to the opening fence of this code block by changing the opening triple
backticks from ``` to ```text.

---

Nitpick comments:
In `@internal/exec/describe_stacks_component_processor_auth_test.go`:
- Around line 366-445: The two test functions
TestProcessComponentEntry_OutOfScopeStackSkipsAuth and
TestProcessComponentEntry_OutOfScopeComponentSkipsAuth are structurally
identical and differ only in their filter setup and component inputs.
Consolidate them into a single table-driven test by defining a slice of test
case structs that capture the differences (such as filterByStack value,
components filter slice, stackFileName, and componentName), then iterate through
the table executing the same test logic for each scenario. This will eliminate
code duplication and make it easier to add additional skip-path test cases in
the future.
🪄 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: b4e3523d-fe7b-4058-9298-ef1bb8170716

📥 Commits

Reviewing files that changed from the base of the PR and between 8a9754b and ac9f879.

📒 Files selected for processing (3)
  • docs/fixes/2026-06-20-secret-list-stack-scope-per-component-auth.md
  • internal/exec/describe_stacks_component_processor.go
  • internal/exec/describe_stacks_component_processor_auth_test.go

`processComponentEntry` resolved per-component auth (a full credential
write + file lock + keyring rebuild) before applying the stack and
component filters. Because describe-stacks walks every stack file,
`atmos secret list -s <stack>` authenticated every component in every
other stack before discarding it, scaling with the whole repo and
appearing to hang on large repos.

Move the stack and component filters ahead of resolveComponentAuthManager
so per-component auth runs only for in-scope components. Auth still
precedes its consumers (BuildTerraformWorkspace, Go-template and
YAML-function processing), so nothing downstream loses its AuthContext.
This also benefits `describe stacks -s` and the `list` family.

Adds a table-driven regression test asserting the resolver is not invoked
for out-of-scope stacks or components.

Closes cloudposse#2639
@sgtoj
Brian Ojeda (sgtoj) force-pushed the fix/secret-list-stack-scope branch from 4058bf9 to f27090b Compare June 20, 2026 16:53
@aknysh Andriy Knysh (aknysh) added the patch A minor, backward compatible change label Jun 20, 2026
@codecov

codecov Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.04%. Comparing base (aa68d85) to head (84176d8).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2642      +/-   ##
==========================================
+ Coverage   80.02%   80.04%   +0.01%     
==========================================
  Files        1361     1361              
  Lines      127449   127449              
==========================================
+ Hits       101994   102016      +22     
+ Misses      19790    19766      -24     
- Partials     5665     5667       +2     
Flag Coverage Δ
unittests 80.04% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...ternal/exec/describe_stacks_component_processor.go 95.42% <100.00%> (ø)

... and 7 files with indirect coverage changes

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

@sgtoj

Copy link
Copy Markdown
Contributor Author

Superseded by #2652, which branches off the latest main as a single commit and contains both optimizations (filter-before-auth reorder + per-component auth cache), reframed as a general describe stacks fix (the original secret list symptom in #2639 was resolved separately by #2646).

@atmos-pro

atmos-pro Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Note

Atmos Pro  

Waiting for your GitHub Actions workflow to upload affected stacks.
Learn More.

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.

atmos secret list -s <stack> (without -c) hangs: authenticates once per component across all stacks instead of scoping to the requested stack

2 participants