Skip to content

refactor: Migrate atmos auth to Command Registry with StandardParser - #1919

Merged
Andriy Knysh (aknysh) merged 44 commits into
mainfrom
osterman/auth-registry-refactor
May 12, 2026
Merged

Andriy Knysh (aknysh) merged 44 commits into
mainfrom
osterman/auth-registry-refactor

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Dec 28, 2025 •

Copy link
Copy Markdown
Member

What

Refactors the atmos auth command family from the legacy flat-file structure to the Command Registry pattern with unified flag handling via pkg/flags/StandardParser. As a side-effect of the refactor, this PR also resolves two long-standing flag-precedence bugs (#1973 and #2392) and adds regression tests so they cannot silently regress again.

  • Migrated 11 auth files from cmd/auth_*.go to an organised cmd/auth/ package with a CommandProvider interface.
  • Replaced direct viper.BindPFlag() / viper.BindEnv() calls with flags.NewStandardParser(...) + parser.BindToViper(...) (Forbidigo-compliant).
  • Replaced DisableFlagParsing with the SeparatedArgs pattern for pass-through commands (auth shell, auth exec).
  • Promoted auth user to a real subcommand package (cmd/auth/user/).

Why

  • Eliminates Forbidigo violations: removes direct viper.BindPFlag() / viper.BindEnv() calls.
  • Consistent flag precedence: every auth subcommand now goes through BuildConfigAndStacksInfo(cmd, v) so global flags (--base-path, --config, --config-path, --profile) are honoured uniformly.
  • Enables the plugin architecture: commands self-register via CommandProvider.
  • Better testability: helpers are isolated and mockable; coverage on cmd/auth rose from 33% → 47% in this PR.

Closes

Closes #1973 — --profile not applied for auth exec and auth shell

Root cause: the legacy executeAuthExecCommandCore / executeAuthShellCommandCore loaded the atmos config from cfg.InitCliConfig(newAuthConfigAndStacksInfo(cmd), false) — a helper that only read --base-path / --config / --config-path and dropped --profile on the floor. auth list / auth env / auth whoami happened to call a different helper that did read profile, hence the asymmetric bug.

Fix: both cmd/auth/exec.go and cmd/auth/shell.go now call BuildConfigAndStacksInfo(cmd, v) (a wrapper over flags.BuildConfigAndStacksInfo) which extracts all global flags including --profile into ConfigAndStacksInfo.ProfilesFromArg before cfg.InitCliConfig.

Regression tests:

  • cmd/auth/exec_test.go::TestAuthExec_ProfileFlagAppliedToConfig
  • cmd/auth/shell_test.go::TestAuthShell_ProfileFlagAppliedToConfig

Both cover single-profile, multi-profile, and no-profile cases.

Closes #2392 — --identity silently dropped on atmos terraform plan

Root cause: the bug as reported at v1.216.0 stemmed from --identity being parsed inconsistently between command families. Terraform commands relied solely on the legacy arg-walker parseIdentityFlag while auth/describe used a Cobra-flag-based path.

Fix: terraform commands now register --identity via the StandardParser (cmd/terraform/flags.go::registerIdentityFlags) and the legacy arg-walker still populates info.Identity for backwards compat — so both paths converge on the same value. setupTerraformAuth (in internal/exec/terraform_execute_helpers.go) passes info.Identity verbatim to the auth manager creator; pkg/auth.resolveIdentityName returns it as-is when non-empty, so the explicit flag value can never be overridden by a profile-default identity.

Regression tests:

  • internal/exec/cli_utils_test.go::TestProcessCommandLineArgs_TerraformIdentityFlag_Issue2392 — replays the exact arg shape from the bug report (terraform plan account-map -s core-gbl-root --identity core-root/admin) and asserts info.Identity == "core-root/admin".
  • internal/exec/terraform_execute_helpers_auth_test.go::TestSetupTerraformAuth_IdentityFlagPropagatesToAuthCreator — builds a merged auth config with both a default: true identity and a non-default identity and asserts setupTerraformAuth passes the explicit --identity value verbatim.
  • internal/exec/terraform_execute_helpers_auth_test.go::TestSetupTerraformAuth_EmptyIdentity_AllowsAutoDetection — inverse guard: empty info.Identity must still allow auto-detect.

Testing

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive auth command group with subcommands: login, logout, whoami, list, env, exec, shell, console, validate, and user configure.
  • Improvements

    • Enhanced identity flag handling (equals/space forms, interactive select, disable/omit modes) and improved argument preprocessing/completions.
    • Better auth UX: cached credentials, safer environment output formats (bash/json/dotenv/GitHub), console/session options (destination, duration, issuer, print-only/no-open), and launch/run commands with authenticated environments.
  • Documentation

    • Updated CLI docs and usage tips for identity placement, examples, and auth command usage.

@github-actions github-actions Bot added the size/xl Extra large size PR label Dec 28, 2025
@mergify

mergify Bot commented Dec 28, 2025

Copy link
Copy Markdown
Contributor

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@github-actions

github-actions Bot commented Dec 28, 2025 •

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 43 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
github.com/Masterminds/semver/v33.5.0NullUnknown License
github.com/Microsoft/go-winio0.6.3-0.20251027160822-ad3df93bed29NullUnknown License
github.com/alecthomas/chroma/v22.24.1NullUnknown License
github.com/apparentlymart/go-cidr1.1.1NullUnknown License
github.com/aws/aws-sdk-go-v21.41.7NullUnknown License
github.com/aws/aws-sdk-go-v2/config1.32.17NullUnknown License
github.com/aws/aws-sdk-go-v2/credentials1.19.16NullUnknown License
github.com/aws/aws-sdk-go-v2/feature/ec2/imds1.18.23NullUnknown License
github.com/aws/aws-sdk-go-v2/feature/s3/manager1.22.17NullUnknown License
github.com/aws/aws-sdk-go-v2/internal/configsources1.4.23NullUnknown License
github.com/aws/aws-sdk-go-v2/internal/endpoints/v22.7.23NullUnknown License
github.com/aws/aws-sdk-go-v2/service/bedrockruntime1.50.6NullUnknown License
github.com/aws/aws-sdk-go-v2/service/ecr1.57.2NullUnknown License
github.com/aws/aws-sdk-go-v2/service/eks1.83.0NullUnknown License
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding1.13.9NullUnknown License
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url1.13.23NullUnknown License
github.com/aws/aws-sdk-go-v2/service/internal/s3shared1.19.23NullUnknown License
github.com/aws/aws-sdk-go-v2/service/organizations1.51.3NullUnknown License
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi1.31.12NullUnknown License
github.com/aws/aws-sdk-go-v2/service/s31.100.1NullUnknown License
github.com/aws/aws-sdk-go-v2/service/secretsmanager1.41.7NullUnknown License
github.com/aws/aws-sdk-go-v2/service/ssm1.68.6NullUnknown License
github.com/aws/aws-sdk-go-v2/service/sso1.30.17NullUnknown License
github.com/aws/aws-sdk-go-v2/service/ssooidc1.35.21NullUnknown License
github.com/aws/aws-sdk-go-v2/service/sts1.42.1NullUnknown License
github.com/buger/jsonparser1.2.0NullUnknown License
github.com/cockroachdb/errors1.13.0NullUnknown License
github.com/containerd/containerd/v22.3.0NullUnknown License
github.com/docker/cli29.4.3+incompatibleNullUnknown License
github.com/fsnotify/fsnotify1.10.1NullUnknown License
github.com/fxamacker/cbor/v22.9.2NullUnknown License
github.com/getsentry/sentry-go0.46.2NullUnknown License
github.com/go-git/go-git/v55.19.0NullUnknown License
github.com/klauspost/compress1.18.6NullUnknown License
github.com/mattn/go-isatty0.0.22NullUnknown License
github.com/modelcontextprotocol/go-sdk1.6.0NullUnknown License
github.com/open-policy-agent/opa1.16.1NullUnknown License
github.com/pelletier/go-toml/v22.3.1NullUnknown License
github.com/posthog/posthog-go1.12.4NullUnknown License
github.com/redis/go-redis/v99.19.0NullUnknown License
gopkg.in/ini.v11.67.2NullUnknown License
k8s.io/kube-openapi0.0.0-20260505163821-33341827b392NullUnknown License
modernc.org/sqlite1.50.0NullUnknown License
Allowed Licenses: MIT, MIT-0, Apache-2.0, BSD-2-Clause, BSD-2-Clause-Views, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-3.0, Python-2.0, OFL-1.1, LicenseRef-scancode-generic-cla, LicenseRef-scancode-unknown-license-reference, LicenseRef-scancode-unicode, LicenseRef-scancode-google-patent-license-golang
Excluded from license check: pkg:golang/modernc.org/libc

Scanned Files

  • go.mod

Comment thread cmd/auth/env.go Fixed
Comment thread cmd/auth/env.go Fixed
@coderabbitai

coderabbitai Bot commented Dec 28, 2025 •

Copy link