Skip to content

Prevent sensitive YAML function value leaks - #2783

Merged
Andriy Knysh (aknysh) merged 8 commits into
mainfrom
osterman/fix-yaml-secret-lookup
Jul 22, 2026
Merged

Andriy Knysh (aknysh) merged 8 commits into
mainfrom
osterman/fix-yaml-secret-lookup

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

what

  • Keep Terraform-declared sensitive inputs out of generated JSON varfiles and pass them through TF_VAR_* during execution.
  • Block degraded (computed) values from Terraform handoff paths and add function-aware debug logging for graceful YAML-function degradation.
  • Add a generic producer/consumer regression fixture covering explicit-tag preservation, resolved state values, and JSON/environment transport.

why

  • A resolved value from a sensitive YAML function could bypass masker-derived detection, be written to a varfile, or be transported as lookup arguments instead of the resolved value.

references

  • N/A

Summary by CodeRabbit

  • Security
    • Terraform inputs marked sensitive = true are excluded from generated *.terraform.tfvars.json when masking is enabled, including --with-secrets.
    • Their resolved values are passed to Terraform via TF_VAR_<name> environment variables (not written to disk).
    • Masking-disabled behavior preserves prior JSON compatibility.
  • Bug Fixes
    • Execution, shell setup, and varfile generation now reject unresolved “(computed)” Terraform values before handoff (including nested maps/slices).
    • Sensitive root-module handling is improved using module metadata.
  • Diagnostics
    • Added debug logging for recoverable YAML function parsing errors with function name and context.
  • Tests
    • Added regression tests plus a new sensitive-state fixture covering explicit YAML tags and non-leakage.

@atmos-pro

atmos-pro Bot commented Jul 22, 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

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown

Resource Changes Found for bucket in test

Atmos CI

create

Plan: 4 to add, 0 to change, 0 to destroy.
To reproduce this locally, run:

atmos terraform plan bucket -s test

Create

+ aws_s3_bucket.checkov_target
+ aws_s3_bucket.this
+ aws_s3_bucket.trivy_target
+ aws_s3_bucket_public_access_block.trivy_target
Terraform Plan Summary
  # aws_s3_bucket.checkov_target will be created
  + resource "aws_s3_bucket" "checkov_target" {
      + acceleration_status         = (known after apply)
      + acl                         = (known after apply)
      + arn                         = (known after apply)
      + bucket                      = "atmos-native-ci-e2e-checkov-test"
      + bucket_domain_name          = (known after apply)
      + bucket_prefix               = (known after apply)
      + bucket_regional_domain_name = (known after apply)
      + force_destroy               = false
      + hosted_zone_id              = (known after apply)
      + id                          = (known after apply)
      + object_lock_enabled         = (known after apply)
      + policy                      = (known after apply)
      + region                      = (known after apply)
      + request_payer               = (known after apply)
      + tags_all                    = (known after apply)
      + website_domain              = (known after apply)
      + website_endpoint            = (known after apply)

      + cors_rule (known after apply)

      + grant (known after apply)

      + lifecycle_rule (known after apply)

      + logging (known after apply)

      + object_lock_configuration (known after apply)

      + replication_configuration (known after apply)

      + server_side_encryption_configuration (known after apply)

      + versioning (known after apply)

      + website (known after apply)
    }

  # aws_s3_bucket.this will be created
  + resource "aws_s3_bucket" "this" {
      + acceleration_status         = (known after apply)
      + acl                         = (known after apply)
      + arn                         = (known after apply)
      + bucket                      = "atmos-native-ci-e2e-test"
      + bucket_domain_name          = (known after apply)
      + bucket_prefix               = (known after apply)
      + bucket_regional_domain_name = (known after apply)
      + force_destroy               = false
      + hosted_zone_id              = (known after apply)
      + id                          = (known after apply)
      + object_lock_enabled         = (known after apply)
      + policy                      = (known after apply)
      + region                      = (known after apply)
      + request_payer               = (known after apply)
      + tags                        = {
          + "AtmosFixture" = "native-ci-e2e"
          + "Stage"        = "test"
        }
      + tags_all                    = {
          + "AtmosFixture" = "native-ci-e2e"
          + "Stage"        = "test"
        }
      + website_domain              = (known after apply)
      + website_endpoint            = (known after apply)

      + cors_rule (known after apply)

      + grant (known after apply)

      + lifecycle_rule (known after apply)

      + logging (known after apply)

      + object_lock_configuration (known after apply)

      + replication_configuration (known after apply)

      + server_side_encryption_configuration (known after apply)

      + versioning (known after apply)

      + website (known after apply)
    }

  # aws_s3_bucket.trivy_target will be created
  + resource "aws_s3_bucket" "trivy_target" {
      + acceleration_status         = (known after apply)
      + acl                         = (known after apply)
      + arn                         = (known after apply)
      + bucket                      = "atmos-native-ci-e2e-trivy-test"
      + bucket_domain_name          = (known after apply)
      + bucket_prefix               = (known after apply)
      + bucket_regional_domain_name = (known after apply)
      + force_destroy               = false
      + hosted_zone_id              = (known after apply)
      + id                          = (known after apply)
      + object_lock_enabled         = (known after apply)
      + policy                      = (known after apply)
      + region                      = (known after apply)
      + request_payer               = (known after apply)
      + tags_all                    = (known after apply)
      + website_domain              = (known after apply)
      + website_endpoint            = (known after apply)

      + cors_rule (known after apply)

      + grant (known after apply)

      + lifecycle_rule (known after apply)

      + logging (known after apply)

      + object_lock_configuration (known after apply)

      + replication_configuration (known after apply)

      + server_side_encryption_configuration (known after apply)

      + versioning (known after apply)

      + website (known after apply)
    }

  # aws_s3_bucket_public_access_block.trivy_target will be created
  + resource "aws_s3_bucket_public_access_block" "trivy_target" {
      + block_public_acls       = true
      + block_public_policy     = true
      + bucket                  = (known after apply)
      + id                      = (known after apply)
      + ignore_public_acls      = true
      + restrict_public_buckets = true
    }

Plan: 4 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + bucket_name = "atmos-native-ci-e2e-test"

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@osterman, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff6fd67e-abd9-4a9f-9fea-8569e3868adb

📥 Commits

Reviewing files that changed from the base of the PR and between d64d9f9 and 2f43eca.

📒 Files selected for processing (6)
  • docs/fixes/2026-07-22-sensitive-yaml-function-varfiles.md
  • errors/errors.go
  • internal/exec/stack_processor_template_test.go
  • internal/exec/stack_processor_utils.go
  • internal/exec/terraform_execute_helpers.go
  • internal/exec/terraform_execute_helpers_test.go
📝 Walkthrough

Walkthrough

Terraform execution now rejects unresolved computed values before varfile or shell preparation, detects module-declared sensitive variables, excludes them from masked disk output, and injects them through TF_VAR_* environment variables. Tests and fixtures cover nested values, YAML tags, masking modes, and sensitive state resolution.

Changes

Terraform input safety

Layer / File(s) Summary
Input validation and sensitive-key derivation
internal/exec/terraform_execute_helpers.go, internal/exec/terraform_execute_helpers_test.go
Terraform inputs are recursively checked for degraded computed values, while root-module sensitive = true variables are added to secret handling when masking is enabled.
Execution and varfile boundaries
internal/exec/terraform_execute_helpers_exec.go, internal/exec/terraform_shell.go, internal/exec/terraform_generate_varfile.go, internal/exec/terraform_generate_varfile_test.go, tests/fixtures/scenarios/yaml-sensitive-state-varfile/..., docs/fixes/...
Pre-execution, shell setup, and varfile generation reject unresolved values and keep declared sensitive values out of masked tfvars files while preserving secret environment injection.
Degraded YAML function handling
internal/exec/yaml_func_utils.go, pkg/utils/yaml_utils_test.go, docs/fixes/2026-07-22-sensitive-yaml-function-varfiles.md
Recoverable YAML function failures now log the parsed function name, and explicit tags retain their full expressions during decoding.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TerraformExecution
  participant InputValidation
  participant VarfileGeneration
  participant SecretEnvironment
  TerraformExecution->>InputValidation: validate component vars
  InputValidation-->>TerraformExecution: accept or reject computed values
  TerraformExecution->>VarfileGeneration: generate disk-safe tfvars
  VarfileGeneration->>SecretEnvironment: inject masked sensitive vars
Loading
🚥 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 clearly matches the main change: preventing sensitive YAML function values from leaking through Terraform execution paths.
Docstring Coverage ✅ Passed Docstring coverage is 100.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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/fix-yaml-secret-lookup

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.

🧹 Nitpick comments (1)
internal/exec/terraform_execute_helpers.go (1)

41-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the repository’s static error definition.

Move this sentinel to errors/errors.go and reference it here so error definitions follow the shared contract.

🤖 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 `@internal/exec/terraform_execute_helpers.go` at line 41, Move the
errUnresolvedComputedTerraformVar sentinel definition from the Terraform
execution helpers into the repository’s shared errors/errors.go definitions,
then update its references in the relevant execution code to use the shared
errors package symbol.

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.

Nitpick comments:
In `@internal/exec/terraform_execute_helpers.go`:
- Line 41: Move the errUnresolvedComputedTerraformVar sentinel definition from
the Terraform execution helpers into the repository’s shared errors/errors.go
definitions, then update its references in the relevant execution code to use
the shared errors package symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5ee1c4d1-fb9a-4309-846e-80c1ca8c3fa5

📥 Commits

Reviewing files that changed from the base of the PR and between a8bc6e9 and 1dce912.

📒 Files selected for processing (12)
  • internal/exec/terraform_execute_helpers.go
  • internal/exec/terraform_execute_helpers_exec.go
  • internal/exec/terraform_execute_helpers_test.go
  • internal/exec/terraform_generate_varfile.go
  • internal/exec/terraform_generate_varfile_test.go
  • internal/exec/terraform_shell.go
  • internal/exec/yaml_func_utils.go
  • pkg/utils/yaml_utils_test.go
  • tests/fixtures/scenarios/yaml-sensitive-state-varfile/atmos.yaml
  • tests/fixtures/scenarios/yaml-sensitive-state-varfile/components/terraform/consumer/variables.tf
  • tests/fixtures/scenarios/yaml-sensitive-state-varfile/components/terraform/producer/main.tf
  • tests/fixtures/scenarios/yaml-sensitive-state-varfile/stacks/dev.yaml

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 22, 2026

@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: 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 `@docs/fixes/2026-07-22-sensitive-yaml-function-varfiles.md`:
- Around line 34-39: Update the Validation section of the fix note to include
the exact required commands `atmos lint --changed` and `atmos test`, and use the
full build command rather than the abbreviated “Go build” description. If any
required checks were not run, explicitly identify them as not run.
🪄 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: dce43cec-1aec-497f-b4b5-a9011fa03b2c

📥 Commits

Reviewing files that changed from the base of the PR and between 1dce912 and c244281.

📒 Files selected for processing (1)
  • docs/fixes/2026-07-22-sensitive-yaml-function-varfiles.md

@aknysh
Andriy Knysh (aknysh) merged commit 164e7f8 into main Jul 22, 2026
85 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the osterman/fix-yaml-secret-lookup branch July 22, 2026 20:41
@atmos-pro

atmos-pro Bot commented Jul 22, 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.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.50725% with 10 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@a8bc6e9). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/terraform_execute_helpers.go 91.83% 3 Missing and 1 partial ⚠️
internal/exec/terraform_execute_helpers_exec.go 0.00% 1 Missing and 1 partial ⚠️
internal/exec/terraform_generate_varfile.go 50.00% 1 Missing and 1 partial ⚠️
internal/exec/terraform_shell.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2783   +/-   ##
=======================================
  Coverage        ?   81.70%           
=======================================
  Files           ?     1778           
  Lines           ?   170709           
  Branches        ?        0           
=======================================
  Hits            ?   139483           
  Misses          ?    23497           
  Partials        ?     7729           
Flag Coverage Δ
unittests 81.70% <85.50%> (?)

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

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
internal/exec/stack_processor_utils.go 82.06% <100.00%> (ø)
internal/exec/yaml_func_utils.go 82.85% <100.00%> (ø)
internal/exec/terraform_execute_helpers_exec.go 85.01% <0.00%> (ø)
internal/exec/terraform_generate_varfile.go 82.41% <50.00%> (ø)
internal/exec/terraform_shell.go 71.31% <0.00%> (ø)
internal/exec/terraform_execute_helpers.go 77.60% <91.83%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.223.1-rc.4.

This branch was previously deployed

1 inactive deployment
screengrabs — 2f43eca7 Deployed Jul 22, 2026 by osterman via build #530
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