Skip to content

fix(hooks): store-output hooks inherit the run's default identity - #2662

Merged
Andriy Knysh (aknysh) merged 2 commits into
mainfrom
aknysh/fix-hook-default-identity
Jun 28, 2026
Merged

Andriy Knysh (aknysh) merged 2 commits into
mainfrom
aknysh/fix-hook-default-identity

Conversation

@aknysh

@aknysh Andriy Knysh (aknysh) commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

what

  • Make the terraform after-apply store-outputs hook path inherit the run's auto-detected identity for
    stores that don't declare their own identity, matching the main terraform path.
  • Add a new internal/exec.HookStoreDefaultIdentity helper (auto-detect the active identity from the
    auth manager's chain, normalize empty/select/disabled to ""); cmd/terraform's
    injectHookStoreAuthResolver now calls SetAuthContextResolverWithDefaultIdentity instead of the
    resolver-only variant.
  • Fix an adjacent bug: pkg/store.defaultIdentityForStore was missing *SecretsManagerStore
    (aws/asm), so AWS Secrets Manager stores never inherited a default identity on any path. Added
    the case so aws/asm behaves like aws/ssm.
  • Tests: internal/exec.TestHookStoreDefaultIdentity (new), cmd/terraform
    TestInjectHookStoreAuthResolver_InheritsDefaultIdentity (replaces …_ResolverOnly), updated
    pkg/store default-identity test so identity-less aws/asm asserts inheritance, and Floci E2E
    TestAWSStoreHooks_InheritedIdentity_FlociE2E with fixture aws-store-hooks-floci-inherit.
  • Fix doc: docs/fixes/2026-06-27-store-hook-inherit-default-identity.md.

why

  • Hook fix. Under Atmos auth, atmos terraform apply on a component with a store-outputs hook
    applied successfully but then failed in the hook when the target store had no identity:

    INFO  Running hooks event=after.terraform.apply status=success
    ✓ Fetching <output> from <component> in <stack>
    Error: failed to assume write role: … get identity: get credentials:
    failed to refresh cached credentials, no EC2 IMDS role found, … ec2imds: GetMetadata …
    

    Hooks run in a freshly-loaded config, so the apply-phase store registry (and its injected default
    identity) is gone. The hook re-injected the resolver but no default identity, so identity-less
    stores fell back to the default AWS SDK credential chain — empty under Atmos auth (credentials live
    in the keyring, not the environment) — and dropped to EC2 IMDS. The main terraform path and !store
    reads already inherit the run's identity; this removes a surprising asymmetry and completes the
    follow-up explicitly deferred in Fix AWS store auth and add Floci E2E coverage #2625 ("Component-identity inheritance for identity-less stores is
    intentionally left for a follow-up design decision").

  • ASM fix. defaultIdentityForStore handled *SSMStore, *AzureKeyVaultStore, and *GSMStore
    but not *SecretsManagerStore, so aws/asm stores without an explicit identity could never
    inherit one. This was latent before (and was even codified by the old test); the hook fix's E2E
    surfaced it.

  • Backward compatible. HookStoreDefaultIdentity returns "" whenever no identity is resolved
    (no auth manager, or empty/select/disabled), and SetAuthContextResolverWithDefaultIdentity("")
    is a no-op for the default — so runs without Atmos auth keep their prior ambient/default-SDK
    credential behavior, and stores with an explicit identity are never overridden.

references

  • Follow-up to Fix AWS store auth and add Floci E2E coverage #2625 (AWS stores/secrets auth; deferred identity-less inheritance in the hook path).
  • Related fix docs: docs/fixes/2026-06-17-aws-stores-secrets-auth-and-gists.md,
    docs/fixes/2026-05-25-store-hook-missing-backend-role-assumption.md.

The after-apply `store-outputs` hook resolves store credentials on a separate,
freshly-loaded config from the main terraform path. It injected the store auth
resolver but no default identity, so identity-less stores fell back to the
default AWS SDK credential chain — empty under Atmos auth — and failed with
"no EC2 IMDS role found". The main terraform path already inherits the run's
identity; this brings the hook path in line (the follow-up deferred in #2625).

- internal/exec: add HookStoreDefaultIdentity, mirroring the main path
  (auto-detect the active identity from the auth manager chain, normalize
  empty/select/disabled to ""). Returns "" with no auth manager, so runs
  without Atmos auth keep the prior ambient/default-credential behavior.
- cmd/terraform: injectHookStoreAuthResolver now injects the resolver WITH the
  default identity via SetAuthContextResolverWithDefaultIdentity.
- pkg/store: defaultIdentityForStore was missing *SecretsManagerStore (aws/asm),
  so AWS Secrets Manager stores never inherited a default identity on any path.
  Add the case so aws/asm behaves like aws/ssm.

Tests: internal/exec.TestHookStoreDefaultIdentity (new); cmd/terraform
TestInjectHookStoreAuthResolver_InheritsDefaultIdentity (replaces _ResolverOnly);
pkg/store default-identity test updated so identity-less aws/asm asserts
inheritance; Floci E2E TestAWSStoreHooks_InheritedIdentity_FlociE2E with new
fixture aws-store-hooks-floci-inherit (no per-store identity, ambient creds
cleared, hook write succeeds). Fix doc under docs/fixes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aknysh
Andriy Knysh (aknysh) requested review from a team as code owners June 27, 2026 17:22
@aknysh Andriy Knysh (aknysh) added the patch A minor, backward compatible change label Jun 27, 2026
@atmos-pro

atmos-pro Bot commented Jun 27, 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 27, 2026
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jun 27, 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: 83fd8145-7e73-49c2-bcdf-9e62a265fef6

📥 Commits

Reviewing files that changed from the base of the PR and between a8c4fc7 and a9fc716.

📒 Files selected for processing (3)
  • cmd/terraform/utils_hooks_test.go
  • internal/exec/utils_auth_test.go
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/atmos.yaml
💤 Files with no reviewable changes (1)
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/atmos.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/exec/utils_auth_test.go
  • cmd/terraform/utils_hooks_test.go

📝 Walkthrough

Walkthrough

After-apply store-outputs hooks now inherit the run’s auto-detected AWS identity for identity-less stores. The hook resolver uses SetAuthContextResolverWithDefaultIdentity, HookStoreDefaultIdentity derives the fallback, defaultIdentityForStore now covers SecretsManagerStore, and unit plus Floci E2E tests were added.

Changes

Hook Store Identity Inheritance

Layer / File(s) Summary
HookStoreDefaultIdentity helper and SecretsManagerStore default
internal/exec/terraform_execute_helpers.go, pkg/store/registry.go, pkg/store/identity_test.go
Adds HookStoreDefaultIdentity to derive and normalize the hook default identity, extends defaultIdentityForStore to *SecretsManagerStore, and updates the default-identity test expectation.
Hook resolver wiring update
cmd/terraform/utils.go
Switches hook auth-context wiring to SetAuthContextResolverWithDefaultIdentity(resolver, e.HookStoreDefaultIdentity(authManager, info)) and adds an inline comment about omitted store identities.
Unit tests for helper and hook resolver
internal/exec/utils_auth_test.go, cmd/terraform/utils_hooks_test.go
Adds table coverage for HookStoreDefaultIdentity and updates the hook resolver test to assert identity auto-detection, explicit identity preservation, and disabled/select handling.
Floci E2E fixture and integration test
tests/aws_store_hooks_inherit_floci_test.go, tests/fixtures/scenarios/aws-store-hooks-floci-inherit/*
Adds the Floci scenario, Terraform fixture, producer/consumer stacks, and E2E coverage for inherited-identity SSM and Secrets Manager writes.
Fix documentation
docs/fixes/2026-06-27-store-hook-inherit-default-identity.md
Documents the issue, root cause, fix, test coverage, and expected outcomes.

Sequence Diagram

sequenceDiagram
  participant Terraform as Terraform apply
  participant Hook as injectHookStoreAuthResolver
  participant Helper as HookStoreDefaultIdentity
  participant AuthMgr as authManager
  participant Store as SSMStore / SecretsManagerStore

  Terraform->>Hook: store-outputs hook setup
  Hook->>Helper: authManager, info
  Helper->>AuthMgr: GetChain() when identity is empty
  AuthMgr-->>Helper: chain leaf identity
  Helper-->>Hook: defaultIdentity
  Hook->>Store: SetAuthContextResolverWithDefaultIdentity(resolver, defaultIdentity)
  Store-->>Terraform: write outputs with inherited identity
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

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 clearly and concisely summarizes the main change: hook store-output identity inheritance.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aknysh/fix-hook-default-identity

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.

@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: 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 `@cmd/terraform/utils_hooks_test.go`:
- Around line 777-783: Update the explanatory note in the `utils_hooks_test.go`
test to include Secrets Manager in the list of concrete store types handled by
`defaultIdentityForStore`, since `SetAuthContext` now applies the default to
`*SecretsManagerStore` as well. Keep the rest of the seam-behavior explanation
intact, but revise the comment around the test that mentions `GetChain`,
`info.Identity`, and resolver wiring so it accurately reflects the current store
coverage.
- Around line 788-789: The struct field comments in the test helper type need to
follow the Go comment style rule by ending with periods. Update the comments on
the fields in the relevant struct near the chain and expectedIdentity
declarations so they each end with a period, keeping the rest of the wording
unchanged.

In `@internal/exec/utils_auth_test.go`:
- Line 451: The new inline comments in utils_auth_test.go need trailing periods
to satisfy the Go comment rule enforced by godot. Update the affected comment
text near expectedIdentity and the other matching inline comments in the same
test file so each ends with a period, keeping the existing meaning and placement
intact.

In `@tests/fixtures/scenarios/aws-store-hooks-floci-inherit/atmos.yaml`:
- Around line 48-50: The fixture is using a Unix-specific log sink via logs.file
in the atmos.yaml scenario, which breaks cross-platform execution before the
hook path runs. Update the aws-store-hooks-floci-inherit scenario config by
removing the logs.file entry or replacing it with a portable sink that the test
harness sets up, while keeping the logs.level setting intact. Use the logs block
in this fixture as the target for the change.
🪄 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: bc8ec8e8-8388-4f09-ba61-15d2ea2e4fff

📥 Commits

Reviewing files that changed from the base of the PR and between 3562be2 and a8c4fc7.

📒 Files selected for processing (13)
  • cmd/terraform/utils.go
  • cmd/terraform/utils_hooks_test.go
  • docs/fixes/2026-06-27-store-hook-inherit-default-identity.md
  • internal/exec/terraform_execute_helpers.go
  • internal/exec/utils_auth_test.go
  • pkg/store/identity_test.go
  • pkg/store/registry.go
  • tests/aws_store_hooks_inherit_floci_test.go
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/atmos.yaml
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/components/terraform/output-demo/main.tf
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/components/terraform/output-demo/outputs.tf
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/stacks/consumer.yaml
  • tests/fixtures/scenarios/aws-store-hooks-floci-inherit/stacks/producer.yaml

Comment thread cmd/terraform/utils_hooks_test.go
Comment thread cmd/terraform/utils_hooks_test.go Outdated
Comment thread internal/exec/utils_auth_test.go Outdated
Comment thread tests/fixtures/scenarios/aws-store-hooks-floci-inherit/atmos.yaml
@codecov

codecov Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.46%. Comparing base (3562be2) to head (a9fc716).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2662      +/-   ##
==========================================
+ Coverage   80.44%   80.46%   +0.02%     
==========================================
  Files        1444     1444              
  Lines      134759   134768       +9     
==========================================
+ Hits       108406   108444      +38     
+ Misses      20348    20317      -31     
- Partials     6005     6007       +2     
Flag Coverage Δ
unittests 80.46% <100.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
cmd/terraform/utils.go 65.18% <100.00%> (ø)
internal/exec/terraform_execute_helpers.go 76.21% <100.00%> (+0.84%) ⬆️
pkg/store/registry.go 78.51% <100.00%> (+2.24%) ⬆️

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

@aknysh Andriy Knysh (aknysh) self-assigned this Jun 27, 2026
@aknysh
Andriy Knysh (aknysh) merged commit edbf42c into main Jun 28, 2026
100 of 101 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the aknysh/fix-hook-default-identity branch June 28, 2026 16:22
@atmos-pro

atmos-pro Bot commented Jun 28, 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.12.

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