Skip to content

fix(secret): skip remote-state reads in credential-free secret list - #2657

Merged
Andriy Knysh (aknysh) merged 2 commits into
cloudposse:mainfrom
sgtoj:fix/secret-list-credential-free-skip
Jun 23, 2026
Merged

Andriy Knysh (aknysh) merged 2 commits into
cloudposse:mainfrom
sgtoj:fix/secret-list-credential-free-skip

Conversation

@sgtoj

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

Copy link
Copy Markdown
Contributor

what

  • Make credential-free atmos secret list skip the YAML functions that perform authenticated backend reads (!terraform.state, !terraform.output, !store, !store.get) while it enumerates secret declarations.
  • Add a credentialFreeSkip() helper and use it in the two credential-free paths: secret list -s <stack> enumeration and the single-scope secret list -s <stack> -c <component> path without --verify.
  • Authenticated paths (get / set / exec / shell, and secret list --verify) are unchanged — they keep skipping only !secret.
  • Adds TestCredentialFreeSkip pinning the skip set and a docs/fixes write-up.

why

  • Secret listing is intentionally credential-free: it disables authentication so a large stack doesn't run one full auth cycle per component. But it still evaluated !terraform.state / !terraform.output / !store in component vars / settings. With auth disabled, the S3 backend assumes its configured role with no base credentials, the AWS SDK falls back to the default credential chain, and ultimately dials the EC2 IMDS endpoint — unreachable on a workstation — so the command aborts with a confusing assume-role/credentials error even immediately after a successful atmos auth login.
  • Listing only needs the static secrets.vars declarations (secrets.ExtractDeclarations), which never require a resolved value. Evaluating these functions was unnecessary and failure-prone. A skipped function leaves its raw string in place, which the declaration extractor ignores, so discovery is unchanged.
  • This is a regression: before credential-free enumeration was introduced, secret list authenticated per component, so these reads had credentials (slow, but working). Disabling auth removed the credentials without removing the reads.

references

…secret list

`atmos secret list -s <stack>` (and `secret list -s <stack> -c <component>`
without `--verify`) resolve stack/component config with authentication disabled
to avoid one auth cycle per component, but still evaluated `!terraform.state`,
`!terraform.output`, and `!store`. With auth disabled, those reads fall back to
the default AWS credential chain and ultimately the unreachable EC2 IMDS
endpoint, so listing aborts with an assume-role/credentials error even when the
user is authenticated.

Listing only needs the static `secrets.vars` declarations
(secrets.ExtractDeclarations), which never require a resolved value. Add
credentialFreeSkip() and use it in enumerateSecretScopes and loadServiceForList
(non-verify) so the credentialed read functions are skipped; a skipped function
leaves its raw string in place, which the extractor ignores. Authenticated
paths (loadServiceAndConfig, `secret list --verify`) keep skipping only
`!secret`.

Write-up: docs/fixes/2026-06-23-secret-list-credential-free-skip.md

Related to cloudposse#2639. Follow-up to cloudposse#2646, which made secret-list enumeration
credential-free but left the credentialed function evaluation in place.
@sgtoj
Brian Ojeda (sgtoj) requested a review from a team as a code owner June 23, 2026 15:56
@atmos-pro

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

coderabbitai Bot commented Jun 23, 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: 8abf89ff-fad1-4b5c-86dc-b45dd0cef95b

📥 Commits

Reviewing files that changed from the base of the PR and between 12f9e3d and ba8c2ee.

📒 Files selected for processing (4)
  • cmd/secret/enumerate.go
  • cmd/secret/shared.go
  • cmd/secret/shared_test.go
  • docs/fixes/2026-06-23-secret-list-credential-free-skip.md

📝 Walkthrough

Walkthrough

Introduces credentialFreeSkip() in cmd/secret/shared.go that builds a slice of YAML function tokens (stripped of !) from AtmosYamlFunc* constants. This replaces the prior hardcoded []string{"secret"} skip in both enumerateSecretScopes and loadServiceForList, ensuring all credentialed read functions are skipped during auth-disabled secret listing.

Changes

Credential-Free Secret List Fix

Layer / File(s) Summary
credentialFreeSkip() helper and callers
cmd/secret/shared.go, cmd/secret/enumerate.go
Adds strings import and credentialFreeSkip() that trims ! from selected AtmosYamlFunc* constants. Updates enumerateSecretScopes and loadServiceForList (verify=false) to use the full returned token set with AuthManager: nil and AuthDisabled: true, replacing the hardcoded []string{"secret"}.
Unit test
cmd/secret/shared_test.go
Adds TestCredentialFreeSkip with aliased u and strings imports; asserts the returned set matches expected tokens derived from u.AtmosYamlFunc* constants, checks no ! prefix remains, and pins terraform.state/terraform.output as required members.
Fix documentation
docs/fixes/2026-06-23-secret-list-credential-free-skip.md
New fix doc covering the regression, root cause (YAML function evaluation under auth-disabled paths), implemented fix, verification via TestCredentialFreeSkip and end-to-end test, and follow-up recommendations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

patch

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 directly and specifically describes the main fix: skipping remote-state reads in credential-free secret list operations.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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.

@aknysh Andriy Knysh (aknysh) added the patch A minor, backward compatible change label Jun 23, 2026
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.08%. Comparing base (1434ede) to head (76e20f3).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2657      +/-   ##
==========================================
+ Coverage   80.04%   80.08%   +0.04%     
==========================================
  Files        1361     1361              
  Lines      127583   127594      +11     
==========================================
+ Hits       102129   102190      +61     
+ Misses      19790    19744      -46     
+ Partials     5664     5660       -4     
Flag Coverage Δ
unittests 80.08% <100.00%> (+0.04%) ⬆️

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

Files with missing lines Coverage Δ
cmd/secret/enumerate.go 97.40% <100.00%> (ø)
cmd/secret/shared.go 82.85% <100.00%> (+1.46%) ⬆️

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

@aknysh Andriy Knysh (aknysh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@aknysh
Andriy Knysh (aknysh) merged commit 49ce1d3 into cloudposse:main Jun 23, 2026
66 of 67 checks passed
@atmos-pro

atmos-pro Bot commented Jun 23, 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

Copy link
Copy Markdown

These changes were released in v1.222.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