Repository navigation
fix(secrets): SOPS cloud-KMS secrets authenticate via Atmos identity - #2643
Conversation
…2637) `atmos secret` and `!secret` against a SOPS cloud-KMS backend ignored the Atmos identity (--identity / ATMOS_IDENTITY / secrets.providers.<name>.identity / the stack's effective identity) and required ambient cloud credentials, forcing every call to be wrapped in `atmos auth exec`. The SOPS provider now resolves credentials from the identity and injects them into the in-process getsops encrypt/decrypt via ApplyToMasterKey (no env mutation). The cloud is inferred from the file's master-key type at runtime — there is no per-cloud "kind". SOPS moves to its own package (pkg/secrets/providers/sops) with a registry of per-cloud key handlers (aws/gcp/azure), and the cloud-SDK credential building lives in the depguard-exempt pkg/store/sopsauth bridge. Backward compatible: with no resolvable identity, the ambient-credential fallback is unchanged. Reproduced with a Floci KMS E2E (ambient creds cleared, identity-only) and covered by unit tests for key-service selection, registry dispatch, identity precedence, and kind-aware error hints. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Document that the SOPS cloud-KMS kinds (sops/aws-kms, sops/gcp-kms, sops/azure-kv) authenticate via an Atmos identity (no atmos auth exec wrapper), the identity precedence (per-provider > --identity/ATMOS_IDENTITY > stack/component effective), and the ambient-credential fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds identity-aware authentication to SOPS cloud-KMS operations. A new ChangesSOPS Cloud-KMS Identity Authentication
Sequence DiagramsequenceDiagram
participant CLI as atmos secret / terraform exec
participant SharedWiring as injectSecretStoreAuthResolver / injectTerraformStoreAuthResolver
participant AtmosConfig as AtmosConfiguration.SecretsAuth
participant sopsProvider as sopsProvider.keyClient()
participant sopsKeyServiceClient
participant cloudKeyHandler as awsKeyHandler / gcpKeyHandler / azureKeyHandler
participant sopsauthBuilder as sopsauth.Builder
participant MasterKey as getsops MasterKey
CLI->>SharedWiring: scope / info.Identity
SharedWiring->>AtmosConfig: set SecretsAuthContext{Resolver, DefaultIdentity}
CLI->>sopsProvider: Get / Set (Decrypt / Encrypt)
sopsProvider->>sopsKeyServiceClient: wrapCloudKeyService(authResolver, identity, base)
sopsKeyServiceClient->>sopsKeyServiceClient: keyTypeID(req.Key)
sopsKeyServiceClient->>cloudKeyHandler: decrypt / encrypt(builder, identity, req)
cloudKeyHandler->>sopsauthBuilder: AWSKMS / GCPKMS / AzureKV(ctx, identity)
sopsauthBuilder-->>cloudKeyHandler: applier
cloudKeyHandler->>MasterKey: ApplyToMasterKey + Decrypt / Encrypt
MasterKey-->>cloudKeyHandler: plaintext / ciphertext
cloudKeyHandler-->>sopsKeyServiceClient: result bytes
sopsKeyServiceClient-->>sopsProvider: DecryptResponse / EncryptResponse
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 4
🤖 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 `@pkg/store/sopsauth/aws.go`:
- Around line 20-27: The ResolveAWSAuthContext method can return a nil
authContext without an error, and the code then passes this nil value to
awsAuthConfigOpts which dereferences it, causing a panic. After checking the
error returned by ResolveAWSAuthContext, add an explicit nil check for
authContext and return an error immediately if authContext is nil before it is
passed to awsAuthConfigOpts.
In `@pkg/store/sopsauth/azure.go`:
- Around line 19-27: The authContext variable obtained from
b.resolver.ResolveAzureAuthContext is used without a nil check, which can cause
a nil-pointer panic if the resolver returns a nil context. After the error check
for ResolveAzureAuthContext, add an explicit nil check for authContext and
return a controlled error if it is nil, before proceeding to use
authContext.TenantID.
In `@pkg/store/sopsauth/gcp.go`:
- Around line 24-31: After calling b.resolver.ResolveGCPAuthContext(ctx,
identity), add a nil check for the returned authContext before attempting to
dereference its fields like authContext.AccessToken. The current code only
checks for errors but not for a nil context, which would cause a panic if the
resolver returns (nil, nil). Insert a nil guard after the error check and before
accessing authContext.AccessToken to return an appropriate error if authContext
is nil.
In `@tests/fixtures/scenarios/sops-kms-floci/atmos.yaml`:
- Line 42: The fixture file contains a Unix-specific path `/dev/stderr` in the
logs configuration on line 42. Remove the `file: /dev/stderr` line entirely to
use the default logging sink, or if logging to a file is required, replace it
with a fixture-relative file path that works cross-platform (such as a relative
path like `logs/output.log`) to ensure the scenario works on Windows, macOS, and
Linux.
🪄 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: ff157d98-64f0-4bbb-97a8-b4a97004d21b
📒 Files selected for processing (37)
cmd/secret/shared.gocmd/secret/shared_loaders_test.godocs/fixes/2026-06-20-sops-cloud-kms-identity.mdgo.modinternal/exec/terraform_execute_helpers.gopkg/schema/schema.gopkg/secrets/factory.gopkg/secrets/providers/keygen.gopkg/secrets/providers/provider.gopkg/secrets/providers/registry_test.gopkg/secrets/providers/sops/aws.gopkg/secrets/providers/sops/azure.gopkg/secrets/providers/sops/construct_test.gopkg/secrets/providers/sops/errors.gopkg/secrets/providers/sops/gcp.gopkg/secrets/providers/sops/keyservice.gopkg/secrets/providers/sops/keyservice_test.gopkg/secrets/providers/sops/sops.gopkg/secrets/providers/sops/sops_age_key_file_test.gopkg/secrets/providers/sops/sops_age_key_store.gopkg/secrets/providers/sops/sops_age_key_store_test.gopkg/secrets/providers/sops/sops_coverage_test.gopkg/secrets/providers/sops/sops_inline_key_test.gopkg/secrets/providers/sops/sops_keygen.gopkg/secrets/providers/sops/sops_keygen_coverage_test.gopkg/secrets/providers/sops/sops_keygen_test.gopkg/secrets/providers/sops/sops_test.gopkg/secrets/providers/store_test.gopkg/store/identity.gopkg/store/sopsauth/aws.gopkg/store/sopsauth/azure.gopkg/store/sopsauth/builder.gopkg/store/sopsauth/gcp.gotests/fixtures/scenarios/sops-kms-floci/atmos.yamltests/fixtures/scenarios/sops-kms-floci/components/terraform/app/main.tftests/fixtures/scenarios/sops-kms-floci/stacks/dev.yamltests/sops_kms_floci_test.go
💤 Files with no reviewable changes (2)
- pkg/secrets/providers/provider.go
- pkg/secrets/providers/store_test.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@website/docs/cli/configuration/secrets.mdx`:
- Line 215: In the secrets.mdx file, locate the sentence that states "The cloud
is inferred from the file's recipients at runtime" and replace the term
"recipients" with "master keys" or "master-key type" for precision. The
documentation should clarify that the cloud provider inference is based on the
SOPS file's master-key type (the KMS key ARNs and resource IDs in the metadata)
rather than the more generic term "recipients". This will align the
documentation with the actual implementation behavior.
🪄 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: f68574c4-16f0-41e8-a5e2-51521be5f5f2
📒 Files selected for processing (1)
website/docs/cli/configuration/secrets.mdx
…log path Address CodeRabbit review on #2643. The sopsauth cloud builders dereferenced the resolver result without a nil guard; the AuthContextResolver interface contract permits a (nil, nil) return, so add fail-fast guards with wrapped static sentinel errors in aws.go, gcp.go, and azure.go. Also drop the hardcoded /dev/stderr logs.file from the Floci KMS fixture (Atmos already defaults to that sink) for cross-platform portability. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ients Address CodeRabbit review on #2643. Cloud-KMS inference is based on the SOPS file's master-key type (KMS key ARNs/resource IDs in metadata), not the more generic SOPS "recipients" term. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2643 +/- ##
==========================================
+ Coverage 80.02% 80.04% +0.02%
==========================================
Files 1353 1361 +8
Lines 127034 127262 +228
==========================================
+ Hits 101653 101873 +220
- Misses 19731 19733 +2
- Partials 5650 5656 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The #2643 patch landed at 50% coverage; the new cloud-credential code was largely untested. Add deterministic unit tests for the testable surface: - pkg/store/sopsauth: full coverage of AWSKMS/GCPKMS/AzureKV (resolver error, nil-context guard, and offline success paths) plus awsAuthConfigOpts, via the existing store.MockAuthContextResolver — package 0% -> 95.9%. - pkg/secrets/providers/sops: handler credential-resolution error branches for all three clouds, the pure keyservice->master-key converters, cloudKeyTypeName, duplicate-registration panic, and the Encrypt dispatch path. - cmd/secret: secretsDefaultIdentity precedence (explicit vs select/disabled/empty -> authenticated chain tail) and the injectSecretStoreAuthResolver nil guard. The cloud KMS success paths (mk.Decrypt/Encrypt make real network calls) remain covered by the Floci E2E rather than fragile network-dependent unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/store/sopsauth/sopsauth_test.go (1)
20-176: 🏗️ Heavy liftPrefer table-driven tests for the repeated resolver scenarios.
The subtests are solid, but this many repeated branches are easier to maintain and extend as table-driven cases (especially for AWS/GCP/Azure parity and new edge cases).
Refactor sketch
+type kmsCase struct { + name string + setup func(*store.MockAuthContextResolver) + assertErr func(*testing.T, error) +} + +cases := []kmsCase{ + { + name: "resolver error is wrapped", + setup: func(r *store.MockAuthContextResolver) { + r.EXPECT().ResolveAWSAuthContext(gomock.Any(), "id").Return(nil, errResolve) + }, + assertErr: func(t *testing.T, err error) { require.ErrorIs(t, err, errResolve) }, + }, + // ... +} +for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + // shared setup + assertions + }) +}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 `@pkg/store/sopsauth/sopsauth_test.go` around lines 20 - 176, The test functions TestAWSKMS, TestGCPKMS, and TestAzureKV contain repeated resolver test scenarios that would be better organized as table-driven tests. Refactor these functions by defining test cases as a slice of structs containing the scenario name, mock setup expectations, and assertions, then iterate through them with a single loop. This will reduce code duplication, make it easier to add new edge cases, and improve maintainability across the different KMS provider implementations. Keep the TestAWSAuthConfigOpts function as-is since it follows a different testing pattern.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 `@pkg/secrets/providers/sops/handlers_test.go`:
- Around line 103-106: The test for deep-copying the encryption context
currently only verifies that mutating the source key.Context does not affect the
result mk.EncryptionContext. To complete the bidirectional isolation test per
coding guidelines, add a second assertion that mutates mk.EncryptionContext (for
example, setting a different key-value pair) and then verify that the original
key.Context remains unchanged, ensuring true deep-copy isolation in both
directions.
---
Nitpick comments:
In `@pkg/store/sopsauth/sopsauth_test.go`:
- Around line 20-176: The test functions TestAWSKMS, TestGCPKMS, and TestAzureKV
contain repeated resolver test scenarios that would be better organized as
table-driven tests. Refactor these functions by defining test cases as a slice
of structs containing the scenario name, mock setup expectations, and
assertions, then iterate through them with a single loop. This will reduce code
duplication, make it easier to add new edge cases, and improve maintainability
across the different KMS provider implementations. Keep the
TestAWSAuthConfigOpts function as-is since it follows a different testing
pattern.
🪄 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: 5f066965-635b-47b0-a833-962410c29594
📒 Files selected for processing (8)
cmd/secret/shared_identity_test.gopkg/secrets/providers/sops/handlers_test.gopkg/store/sopsauth/aws.gopkg/store/sopsauth/azure.gopkg/store/sopsauth/gcp.gopkg/store/sopsauth/sopsauth_test.gotests/fixtures/scenarios/sops-kms-floci/atmos.yamlwebsite/docs/cli/configuration/secrets.mdx
💤 Files with no reviewable changes (1)
- tests/fixtures/scenarios/sops-kms-floci/atmos.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
- pkg/store/sopsauth/azure.go
- pkg/store/sopsauth/gcp.go
- pkg/store/sopsauth/aws.go
- website/docs/cli/configuration/secrets.mdx
… test Address CodeRabbit review on #2643. Per the aliasing test contract, verify both directions: mutating the converted master key's encryption-context value must not affect the original source map (result -> src), in addition to the existing src -> result check. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The Check Markdown Links job failed with exit code 2 due to two timeouts for https://no-color.org/, the canonical NO_COLOR standard site referenced in two PRD docs. lychee counts timeouts as failures. The site is valid but intermittently slow in CI, matching the existing flaky-host exclusion pattern (gnu.org, tldp.org, kubernetes.io, etc.). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Resolves conflicts from the SOPS refactor in #2643 (main), which moved pkg/secrets/providers/sops.go into the new pkg/secrets/providers/sops subpackage and added cloud-KMS auth via Atmos identity. - pkg/secrets/providers/store_test.go: kept this branch's localFakeStore + TestStoreProvider_LocalStatusCheck (testing storeProvider.LocalStatusCheck); dropped TestNewSops_FromSection/TestNewSops_NotFound, which main moved to the sops subpackage (newSopsProvider no longer lives in package providers). - pkg/secrets/providers/sops/sops_test.go: qualified this branch's added tests' references to LocalStatus and Coordinate with the providers package now that the file lives in package sops. The auto-merged sops/sops.go retains both main's cloud-KMS auth (sopsauth, keyservice, authResolver) and this branch's credential-free existence check (keyExists/branchHasKey/LocalStatusCheck). go build ./..., go vet ./..., and the full secret suite (pkg/secrets/..., pkg/store/..., cmd/secret/...) pass.
|
These changes were released in v1.222.0-rc.6. |
what
atmos secretand!secret(duringterraform plan) against a SOPS cloud-KMS backend now authenticate using the Atmos identity —--identity/ATMOS_IDENTITY, the per-providersecrets.providers.<name>.identity, or the stack/component effective identity — instead of requiring ambient cloud credentials.kind. Credentials are injected into the in-process getsops encrypt/decrypt viaApplyToMasterKey(no process-environment mutation).pkg/secrets/providers/sops/with a registry of per-cloud key handlers (aws.go/gcp.go/azure.go); the cloud-SDK credential building lives in the depguard-exemptpkg/store/sopsauth/bridge so the SOPS package imports no cloud SDK directly.AtmosConfiguration.SecretsAuthseam, populated in both theatmos secretand terraform code paths.why
atmos secretwith a SOPS aws-kms backend ignores atmos identity and requires ambient AWS credentials #2637: the documentedsecrets.providers.<name>.identityfield and--identitywere silently ignored for the SOPS cloud-KMS track, forcing every command to be wrapped inatmos auth execeven though Track-1 stores (SSM/ASM/Key Vault/Secret Manager) already authenticated via the identity.kindremains only for the legitimate age-vs-KMS keygen distinction.secret set/get— the exactatmos secretwith a SOPS aws-kms backend ignores atmos identity and requires ambient AWS credentials #2637 scenario, RED before this change) plus unit tests for key-service selection, per-cloud registry dispatch, identity precedence, and kind-aware error hints.references
atmos secretwith a SOPS aws-kms backend ignores atmos identity and requires ambient AWS credentials #2637docs/fixes/2026-06-20-sops-cloud-kms-identity.md(root cause, fix, and full backend audit)