Skip to content

feat(generate): publish outputs, and never one that reaches the password - #29

Merged
ehtishammubarik merged 1 commit into
masterfrom
feat/generated-outputs
Aug 30, 2026
Merged

ehtishammubarik merged 1 commit into
masterfrom
feat/generated-outputs

Conversation

@ehtishammubarik

Copy link
Copy Markdown
Owner

Closes #9. One issue, one PR.

A generated repository built infrastructure and then declined to say what it built:

$ ls environments/dev
backend.tf  main.tf  terraform.tfvars.example  variables.tf  versions.tf

No cluster endpoint, no database address, no subnet ids. Finding them meant terraform state show, which is a workaround rather than a workflow and does not survive being put in a pipeline. It also blocked the composition story the README implies, since terraform_remote_state only exposes root module outputs.

The security argument, which decided the design

The issue's last checkbox is the one that shaped everything else:

a test asserting that no generated output is named or sourced from anything password-shaped, because terraform output is not a privileged operation and CI logs are not private

So the rule is not "mark the password output sensitive". sensitive stops casual printing; it does not stop terraform output -json, and the value is in state either way. The rule is never create an output that reaches the password at all, directly or transitively.

That is why outputs are an explicit per-stack allowlist rather than a forwarding of everything upstream exposes. terraform-aws-modules/rds also exposes db_instance_master_user_secret and friends. A generator that forwarded wholesale would be one upstream release away from publishing a credential nobody chose to publish.

The test, and why it reads the value expression

An output called endpoint that reads module.rds.db_instance_master_user_secret is exactly as dangerous as one called password, and only the second is caught by reading names. So the test checks name and value expression. I confirmed it catches the realistic mistake rather than only the obvious one:

$ # add Output("db_connection", "module.rds.db_instance_master_user_secret", "Connection info")
AssertionError: output 'db_connection' for stacks ['vpc', 'rds'] touches 'secret':
                value = 'module.rds.db_instance_master_user_secret'

Innocuous name, caught anyway.

It deliberately does not scan description. My first version did, and it failed on my own text: "Cluster CA certificate. Not a secret, but a large blob...". A test that flags prose has one fix available, which is writing a worse description. Descriptions are for humans and may legitimately discuss secrets; what can leak is what the output exposes.

What is published

Nine outputs across three stacks, and only for stacks that were selected, so a repo generated without RDS never references module.rds:

output "cluster_certificate_authority_data" {
  value       = module.eks.cluster_certificate_authority_data
  description = "Cluster CA certificate. Not a secret, but a large blob that ruins a plan diff"
  sensitive   = true
}

The file opens by saying what is absent and why, because the next person's instinct will be to add a password output:

There is no password output, and there is no output that reaches one. terraform output is not a privileged operation, -json ignores the sensitive flag, and CI logs are not private.

The generated README gains a Consuming what it built section with the aws eks update-kubeconfig line the issue asked for, using the region the generator already knows rather than parsing it back out of backend.tf.

Verification

Real terraform plan against AWS, AWS_PROFILE=default (604786434653):

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

Changes to Outputs:
  + cluster_certificate_authority_data = (sensitive value)
  + cluster_endpoint                   = (known after apply)
  + cluster_name                       = "demo-dev-eks"
  + db_instance_address                = (known after apply)
  + db_instance_port                   = 5432
  + private_subnets                    = [ ... ]

Terraform itself confirms the sensitive handling, and confirms no password output exists.

pytest                                120 passed  (112 -> 120)
ruff check / format --check           clean
terraform validate                    Success! The configuration is valid.
terraform fmt -check -recursive       FMT=0
secret-scan / git-hygiene / syntax    PASS

kubernetes and helm gates skipped, not passed.

Per this repo's roadmap rule, the #9 row moves out of Next into Now in this PR rather than afterwards.

Scope

One issue. The six stub stacks (#21-#26) are untouched; when each is configured it adds its own entry to STACK_OUTPUTS, and the security test covers it automatically.

A generated repository built infrastructure and then declined to say what
it built. No cluster endpoint, no database address, no subnet ids, so
finding them meant terraform state show. That is a workaround rather than
a workflow and it does not survive being put in a pipeline. It also
blocked the composition story the README implies, since
terraform_remote_state only exposes root module outputs.

Outputs are an explicit per-stack allowlist, not a forwarding of
everything upstream exposes. That distinction is the whole security
argument: terraform-aws-modules/rds also exposes
db_instance_master_user_secret, and a generator that forwarded wholesale
would be one upstream release away from publishing a credential nobody
chose to publish.

There is no password output and none that reaches one. sensitive = true
is not the mechanism, because terraform output is not privileged, -json
ignores the flag, and CI logs are not private. The mechanism is never
creating the output.

The test checks the name and the value expression, not the description:
an output called endpoint reading db_instance_master_user_secret is
exactly as dangerous as one called password, and only the second is
caught by reading names. Verified by adding
Output("db_connection", "module.rds.db_instance_master_user_secret") and
watching it fail, which is also why the description is excluded: scanning
prose flagged "Not a secret, but a large blob", whose only fix would have
been writing a worse description.

Generated README gains a Consuming what it built section with the
aws eks update-kubeconfig line, using the region the generator already
knows rather than parsing it back out of backend.tf.

Real plan against AWS (profile default, 604786434653): 63 to add, 0 to
change, 0 to destroy, with cluster_certificate_authority_data reported as
(sensitive value) and no password output present.

Closes #9

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ehtishammubarik
ehtishammubarik merged commit 7cc1a97 into master Aug 30, 2026
10 checks passed
@ehtishammubarik
ehtishammubarik deleted the feat/generated-outputs branch August 30, 2026 09:51
ehtishammubarik added a commit that referenced this pull request Sep 20, 2026
…ready owns (#34)

The v0.1.1 release failed at test-wheel on all three Pythons, published
nothing, and surfaced a workflow that had been broken for five weeks.

release.yml asserted `publicly_accessible = false` with a single space.
create_db_subnet_group is 22 characters and joined that block in #13, so
terraform fmt realigned the attribute to four spaces and the assertion has
been false since 2026-07-31. Nothing noticed because the workflow runs only
on a tag push, and no tag was cut in that window. The generated output was
correct throughout: the database is private, and prod deletion_protection is
true.

The assertions should not have been there. tests/test_stackmason.py already
covers both properties, and covers them whitespace-tolerantly, and the step
directly above runs that suite against the installed package with the source
tree deleted. The workflow copy was strictly worse duplication: no feedback
loop between releases, so it drifted silently while the copy next to the code
was kept correct.

- release.yml: drop the HCL content assertions. What remains is what the
  suite genuinely cannot see, because it is about the artifact rather than
  the source: the entry point resolves from the wheel, a real `stackmason
  new` writes real files, the published build still refuses an 0.0.0.0/0
  database and writes nothing when it blocks, and the output carries no
  literal credential. Added outputs.tf to the file list, since #29 made it
  part of every environment.
- A comment states why there are no content assertions there, with the #13
  alignment story, so the next person does not add one back.
- tests: made the deletion_protection assertion whitespace-tolerant, matching
  the regex style already used two functions below it for
  publicly_accessible.

Demonstrated both directions rather than assuming:
  realigned the attribute to one space  -> test passes
  set prod deletion_protection = false  -> test fails

Verified: pytest 91 passed, coverage 90.90% against the 88% floor, ruff clean.

Closes #33


Claude-Session: https://claude.ai/code/session_012fMM2HhoJ2XzDkfMR2HwSa

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated environments have no outputs, so nothing downstream can consume them

1 participant