Repository navigation
fix(auth): skip identity resolution in describe when functions disabled - #2262
Conversation
When --process-functions=false is set, describe commands no longer attempt identity resolution. YAML functions (!terraform.state, !terraform.output) are the only consumers of auth credentials during describe, so identity resolution is unnecessary when functions are disabled. The --identity flag still works regardless of the process-functions setting.
Dependency Review✅ No vulnerabilities or license issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughDescribe commands now skip creating or assigning an AuthManager unless YAML function processing is enabled or the Changes
Sequence Diagram(s)sequenceDiagram
rect rgba(200,200,255,0.5)
participant CLI
end
rect rgba(200,255,200,0.5)
participant Cmd
end
rect rgba(255,200,200,0.5)
participant AuthManager
end
rect rgba(255,255,200,0.5)
participant Exec
end
CLI->>Cmd: invoke describe command (flags, env)
Cmd->>Cmd: check ProcessYamlFunctions and IdentityFlagChanged?
alt process functions enabled OR identity explicitly set
Cmd->>AuthManager: CreateAuthManagerFromIdentityWithAtmosConfig(...)
AuthManager-->>Cmd: AuthManager or error
Cmd->>Exec: Execute with AuthManager set
else skip auth creation
Cmd-->>Exec: Execute with AuthManager = nil
end
Exec-->>CLI: return result / error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/describe_skip_auth_test.go`:
- Around line 56-172: Add tests for the describe component command that ensure
an explicit --identity still forces auth even when
ProcessYamlFunctions/--process-functions is false: mirror the existing pattern
used in TestDescribeAffected_SkipsAuthWhenFunctionsDisabled and the other tests
but use newTestCmdWithFunctionsDisabled, getRunnableDescribeComponentCmd and a
mock exec created via exec.NewMockDescribeComponentExec; when the mock's Execute
is called assert that args.ProcessYamlFunctions is false but args.AuthManager is
NOT nil (i.e. auth is performed) when you pass an explicit identity in the CLI
args/props, and also include the complementary case (no explicit identity yields
nil AuthManager) so both sides are covered.
In `@cmd/describe_stacks.go`:
- Around line 77-84: GetIdentityFromFlags currently treats env vars as
equivalent to explicit flags which makes the guard in the describe commands
trigger auth even when --process-functions=false; update the logic so the code
only treats an identity as "explicit" (and thus should bypass the
process-functions skip) when the CLI flag was changed. Either modify
GetIdentityFromFlags to return (identity, wasExplicit bool) or, at each guard
(e.g., where describe.ProcessYamlFunctions and identityName are checked before
calling CreateAuthManagerFromIdentityWithAtmosConfig and assigning
describe.AuthManager), replace the identityName check with
cmd.Flags().Changed(IdentityFlagName) (or check the returned wasExplicit) so
that ambient ATMOS_IDENTITY env values do not cause auth to run when
--process-functions is false.
🪄 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: adac3784-7927-42fc-b4ff-62b6ac97016d
📒 Files selected for processing (5)
cmd/describe_affected.gocmd/describe_component.gocmd/describe_dependents.gocmd/describe_skip_auth_test.gocmd/describe_stacks.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2262 +/- ##
==========================================
+ Coverage 77.24% 77.29% +0.04%
==========================================
Files 1020 1020
Lines 96530 96564 +34
==========================================
+ Hits 74567 74638 +71
+ Misses 17762 17734 -28
+ Partials 4201 4192 -9
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Replace `identityName != ""` with `cmd.Flags().Changed(IdentityFlagName)` in all four describe command guards. This prevents ATMOS_IDENTITY env vars from bypassing the process-functions guard — only an explicit --identity CLI flag should force auth when functions are disabled. Add regression tests: env var doesn't bypass guard, explicit flag does, and unit tests for the Changed vs env var distinction.
Refactor describe component command to use factory function pattern (getRunnableDescribeComponentCmd) matching the other three describe commands. This enables mock injection for unit testing. Add DescribeComponentCmdExec interface and generated mock. Add 3 describe component tests: auth skipped when functions disabled, env var doesn't bypass guard, explicit --identity forces auth.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/describe_component.go`:
- Around line 164-166: The auth manager is being created with
CreateAuthManagerFromIdentity(identityName, mergedAuthConfig) which prevents
loading stack-level default identities when identityName is empty; update the
call to pass atmosConfig so stack-level defaults are considered (e.g. call
CreateAuthManagerFromIdentity(..., atmosConfig) or the equivalent
CreateAuthManagerFromIdentityWithConfig function if available) so that
authManager creation in describe component uses atmosConfig along with
mergedAuthConfig and identityName.
In `@cmd/describe_skip_auth_test.go`:
- Around line 114-147: The tests call viper.Reset() which clears the CLI
flag-to-viper binding so ATMOS_IDENTITY never reaches GetIdentityFromFlags;
re-establish the binding after each viper.Reset() in the env-var tests (the same
way the identity flag is rebound in the other test around the
GetIdentityFromFlags usage) so that the command's auth-guard is exercised
correctly—i.e., after viper.Reset() re-bind the "identity" flag to Viper (the
same binding logic used elsewhere), then run the test using
getRunnableDescribeStacksCmd and assert that args.AuthManager is nil when
ProcessYamlFunctions is false.
🪄 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: b89bf5d4-9efa-49b0-a9f9-92c1ec42d0cd
📒 Files selected for processing (5)
cmd/describe_affected.gocmd/describe_component.gocmd/describe_dependents.gocmd/describe_skip_auth_test.gocmd/describe_stacks.go
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/describe_affected.go
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (4)
cmd/describe_component.go (1)
187-192:⚠️ Potential issue | 🟠 MajorPass
atmosConfiginto auth creation here.Line 189 uses
CreateAuthManagerFromIdentity, so an emptyidentityNamecannot load stack-level default identities from the stack config. That leavesdescribe componentout of sync with the other describe commands whenever auth defaults live outsideatmos.yaml.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/describe_component.go` around lines 187 - 192, CreateAuthManagerFromIdentity is being called without the atmosConfig so an empty identityName cannot resolve stack-level defaults; update the auth creation call in describe_component.go to pass atmosConfig into the CreateAuthManagerFromIdentity invocation (e.g., CreateAuthManagerFromIdentity(atmosConfig, identityName, mergedAuthConfig)) so authManager can load stack-level default identities; adjust any matching function signature or import usage for CreateAuthManagerFromIdentity, and ensure authManager/error handling remains the same.cmd/describe_skip_auth_test.go (3)
112-148:⚠️ Potential issue | 🟡 MinorEnv-var test passes for the wrong reason.
viper.Reset()at line 114 clears the env binding, soGetIdentityFromFlagsreturns empty—not because the guard ignores env-var identity, but because viper can't see it. Rebind after reset to actually test the guard.🔧 Fix
viper.Reset() + require.NoError(t, viper.BindEnv(IdentityFlagName, "ATMOS_IDENTITY", "IDENTITY")) // Set the env var — this should NOT trigger auth when functions are disabled. t.Setenv("ATMOS_IDENTITY", "some-identity")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/describe_skip_auth_test.go` around lines 112 - 148, The test TestDescribeStacks_SkipsAuthWhenEnvVarSetButFunctionsDisabled currently calls viper.Reset(), which clears the environment bindings so GetIdentityFromFlags sees an empty identity for the wrong reason; after calling viper.Reset() re-establish the viper-to-flag/env bindings (the same bind logic used in production, e.g., the function that wires flags/env or whatever binding helper your code uses) so that setting t.Setenv("ATMOS_IDENTITY", ...) actually populates viper; keep the rest of the test (asserting args.AuthManager is nil in the mock Execute in mockExec and using newTestCmdWithFunctionsDisabled/getRunnableDescribeStacksCmd) unchanged so the guard behavior is validated correctly.
223-258:⚠️ Potential issue | 🟡 MinorSame viper binding issue here.
Rebind after
viper.Reset()so the env var is actually visible.🔧 Fix
viper.Reset() + require.NoError(t, viper.BindEnv(IdentityFlagName, "ATMOS_IDENTITY", "IDENTITY")) t.Setenv("ATMOS_IDENTITY", "some-identity")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/describe_skip_auth_test.go` around lines 223 - 258, The test resets viper with viper.Reset() which clears existing env bindings so the subsequent t.Setenv("ATMOS_IDENTITY", ...) has no effect; rebind the required env keys immediately after viper.Reset() in TestDescribeDependents_SkipsAuthWhenEnvVarSetButFunctionsDisabled (or call the shared viper setup helper used elsewhere) so that "ATMOS_IDENTITY" and "IDENTITY" are bound to viper before invoking getRunnableDescribeDependentsCmd/run; ensure the restore/bind calls mirror whatever binding logic the code uses (e.g., viper.BindEnv("ATMOS_IDENTITY") and viper.BindEnv("IDENTITY") or invoking the common viper-init function) so the test assertions on props.AuthManager behave as expected.
334-372:⚠️ Potential issue | 🟡 MinorSame viper binding issue here too.
Rebind after
viper.Reset().🔧 Fix
viper.Reset() + require.NoError(t, viper.BindEnv(IdentityFlagName, "ATMOS_IDENTITY", "IDENTITY")) t.Setenv("ATMOS_IDENTITY", "some-identity")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/describe_skip_auth_test.go` around lines 334 - 372, This test calls viper.Reset() which clears Viper bindings, so rebind the Viper/CLI flags after viper.Reset() (before creating testCmd or invoking getRunnableDescribeAffectedCmd) so the ATMOS_IDENTITY env var is picked up correctly; insert the same Viper binding call/helper used elsewhere in the tests (the helper you use to bind flags for commands) immediately after viper.Reset() in TestDescribeAffected_SkipsAuthWhenEnvVarSetButFunctionsDisabled.
🧹 Nitpick comments (1)
cmd/describe_skip_auth_test.go (1)
61-66:clearIdentityEnvVarsresets viper bindings.This helper calls
viper.Reset()which clears all env bindings. Tests that later rely onATMOS_IDENTITYbeing visible toGetIdentityFromFlagsneed to rebind after calling this.♻️ Consider adding rebind to the helper
func clearIdentityEnvVars(t *testing.T) { t.Helper() viper.Reset() + // Rebind so env vars can still be read when needed. + _ = viper.BindEnv(IdentityFlagName, "ATMOS_IDENTITY", "IDENTITY") t.Setenv("ATMOS_IDENTITY", "") t.Setenv("IDENTITY", "") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/describe_skip_auth_test.go` around lines 61 - 66, The helper clearIdentityEnvVars calls viper.Reset(), which removes environment bindings and breaks later tests that expect ATMOS_IDENTITY/IDENTITY to be bound for GetIdentityFromFlags; after resetting, re-establish the bindings by calling viper.BindEnv for the keys used by GetIdentityFromFlags (e.g., "ATMOS_IDENTITY" and "IDENTITY" or the canonical keys that GetIdentityFromFlags reads) so tests see the env vars again while still clearing their values via t.Setenv.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/describe_skip_auth_test.go`:
- Around line 479-504: This test needs to rebind Viper to the environment
variables the CLI reads (same pattern used elsewhere); after viper.Reset() and
t.Setenv(...) call viper.BindEnv for the relevant config keys (e.g., bind the
CLI config key for identity to "ATMOS_IDENTITY" and/or "IDENTITY") so the
command created by
newTestCmdForDescribeComponent/getRunnableDescribeComponentCmd sees the env var;
add the viper.BindEnv calls before creating mockExec or invoking run (adjust key
names to match describeComponentTestProps/atmosConfigWithBrokenDefaultIdentity
usage).
---
Duplicate comments:
In `@cmd/describe_component.go`:
- Around line 187-192: CreateAuthManagerFromIdentity is being called without the
atmosConfig so an empty identityName cannot resolve stack-level defaults; update
the auth creation call in describe_component.go to pass atmosConfig into the
CreateAuthManagerFromIdentity invocation (e.g.,
CreateAuthManagerFromIdentity(atmosConfig, identityName, mergedAuthConfig)) so
authManager can load stack-level default identities; adjust any matching
function signature or import usage for CreateAuthManagerFromIdentity, and ensure
authManager/error handling remains the same.
In `@cmd/describe_skip_auth_test.go`:
- Around line 112-148: The test
TestDescribeStacks_SkipsAuthWhenEnvVarSetButFunctionsDisabled currently calls
viper.Reset(), which clears the environment bindings so GetIdentityFromFlags
sees an empty identity for the wrong reason; after calling viper.Reset()
re-establish the viper-to-flag/env bindings (the same bind logic used in
production, e.g., the function that wires flags/env or whatever binding helper
your code uses) so that setting t.Setenv("ATMOS_IDENTITY", ...) actually
populates viper; keep the rest of the test (asserting args.AuthManager is nil in
the mock Execute in mockExec and using
newTestCmdWithFunctionsDisabled/getRunnableDescribeStacksCmd) unchanged so the
guard behavior is validated correctly.
- Around line 223-258: The test resets viper with viper.Reset() which clears
existing env bindings so the subsequent t.Setenv("ATMOS_IDENTITY", ...) has no
effect; rebind the required env keys immediately after viper.Reset() in
TestDescribeDependents_SkipsAuthWhenEnvVarSetButFunctionsDisabled (or call the
shared viper setup helper used elsewhere) so that "ATMOS_IDENTITY" and
"IDENTITY" are bound to viper before invoking
getRunnableDescribeDependentsCmd/run; ensure the restore/bind calls mirror
whatever binding logic the code uses (e.g., viper.BindEnv("ATMOS_IDENTITY") and
viper.BindEnv("IDENTITY") or invoking the common viper-init function) so the
test assertions on props.AuthManager behave as expected.
- Around line 334-372: This test calls viper.Reset() which clears Viper
bindings, so rebind the Viper/CLI flags after viper.Reset() (before creating
testCmd or invoking getRunnableDescribeAffectedCmd) so the ATMOS_IDENTITY env
var is picked up correctly; insert the same Viper binding call/helper used
elsewhere in the tests (the helper you use to bind flags for commands)
immediately after viper.Reset() in
TestDescribeAffected_SkipsAuthWhenEnvVarSetButFunctionsDisabled.
---
Nitpick comments:
In `@cmd/describe_skip_auth_test.go`:
- Around line 61-66: The helper clearIdentityEnvVars calls viper.Reset(), which
removes environment bindings and breaks later tests that expect
ATMOS_IDENTITY/IDENTITY to be bound for GetIdentityFromFlags; after resetting,
re-establish the bindings by calling viper.BindEnv for the keys used by
GetIdentityFromFlags (e.g., "ATMOS_IDENTITY" and "IDENTITY" or the canonical
keys that GetIdentityFromFlags reads) so tests see the env vars again while
still clearing their values via t.Setenv.
🪄 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: fbefedff-840c-49bf-97dd-4e3a3bae8d21
📒 Files selected for processing (4)
cmd/describe_component.gocmd/describe_skip_auth_test.gointernal/exec/describe_component.gointernal/exec/mock_describe_component.go
✅ Files skipped from review due to trivial changes (1)
- internal/exec/mock_describe_component.go
… test bindings Switch describe component from CreateAuthManagerFromIdentity to CreateAuthManagerFromIdentityWithAtmosConfig so stack-level default identities are discovered (matching the other three describe commands). Re-establish viper.BindEnv after viper.Reset() in all env-var tests so ATMOS_IDENTITY actually reaches GetIdentityFromFlags, ensuring the guard is exercised correctly rather than passing vacuously.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/describe_component.go`:
- Around line 109-112: The call to g.initCliConfig is building
schema.ConfigAndStacksInfo only from component and stack, which drops global
config-selection flags; fix by first populating the ConfigAndStacksInfo from the
parsed global flags (use flags.ParseGlobalFlags or the same parsing path used
elsewhere to seed the struct) and then set ComponentFromArg and Stack on that
struct before calling g.initCliConfig/InitCliConfig so --base-path, --config,
--config-path and --profile are preserved; update the code that constructs
schema.ConfigAndStacksInfo (used by g.initCliConfig / cfg.InitCliConfig) to
start from the parsed globals and then override ComponentFromArg and Stack.
🪄 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: f6a60da3-4c40-4d14-8b82-bbb901df8723
📒 Files selected for processing (2)
cmd/describe_component.gocmd/describe_skip_auth_test.go
…sInfo The describe component command was constructing ConfigAndStacksInfo with only ComponentFromArg and Stack, dropping --base-path, --config, --config-path, and --profile global flags. Extract these from cmd.Flags() to match the behavior of ProcessCommandLineArgs used by other describe commands.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/describe_component.go`:
- Around line 179-199: The code is currently ignoring componentErr from
g.executeDescribeComponent (while only returning for
errUtils.ErrInvalidComponent); instead, if executeDescribeComponent returns any
error it should be returned immediately so we don't begin authentication probes
on a likely real config/stack/component failure—modify the error branch in the
executeDescribeComponent call inside DescribeComponent to return componentErr
for non-nil componentErr (only keep the special-case return for
errUtils.ErrInvalidComponent if you truly want to treat that as a different
path), so the merge step (auth.MergeComponentAuthFromConfig) only runs when
componentConfig is valid.
🪄 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: fa9cad73-9ad8-4944-bbd9-63427be73079
📒 Files selected for processing (1)
cmd/describe_component.go
Add 9 tests covering previously untested paths in getRunnableDescribeComponentCmd: - FunctionsEnabled_HappyPath: auth resolution + executor called - ComponentNotFound: ErrInvalidComponent returned immediately - ComponentAuthError_FallsBackToGlobal: graceful degradation to global auth - PathResolution: isExplicitComponentPath triggers resolver - PathResolutionError: resolver errors propagated - InitConfigError: config loading errors propagated - GlobalFlagsExtracted: base-path captured in ConfigAndStacksInfo - CheckAtmosConfigError: early return on config check failure - AllGlobalFlagsExtracted: config, config-path, profile flags captured Coverage: 65.2% -> 82.6% (above 80% target). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Extract helpers from getRunnableDescribeComponentCmd to fix all golangci-lint issues: - parseDescribeComponentFlags: flag extraction (eliminates repeated GetString/GetBool) - buildConfigAndStacksInfoFromFlags: global flags to ConfigAndStacksInfo - resolveAuthManager with resolveAuthManagerParams struct (fixes nestif + arg-limit) - resolveComponentFromPathIfNeeded: path resolution extraction (fixes function-length) - handleConfigError: config error wrapping with path-resolution context - Use ErrInvalidArguments sentinel instead of dynamic errors.New (fixes err113) Restore flag registrations in init() (AddStackCompletion, PersistentFlags). Add 9 new tests for describe component coverage (65.2% -> 82.6%). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
These changes were released in v1.214.0-rc.1. |
what
describe component,describe stacks,describe affected,describe dependents) when--process-functions=falsecmd.Flags().Changed(IdentityFlagName)instead ofidentityName != ""so that only an explicit--identityCLI flag bypasses the guard —ATMOS_IDENTITYenv vars no longer trigger auth when functions are disabled--identityflag forces auth, and unit tests for theChangedvs env var distinctionwhy
--process-functions=false, describe commands were still attempting identity resolution (SSO login, credential fetching, etc.)!terraform.state,!terraform.output) are the only consumers of auth credentials during describe — no functions means no auth neededATMOS_IDENTITY) as equivalent to explicit CLI flags, causing auth to run even when the user only wanted raw config inspectionreferences
cmd/describe_component.go,cmd/describe_stacks.go,cmd/describe_affected.go,cmd/describe_dependents.goSummary by CodeRabbit
Bug Fixes
Tests
Refactor