Fix/terraform workflow security hardening#1225
Open
dami-005 wants to merge 4 commits into
Open
Conversation
terraform output -json bypasses the CLI's sensitive-value redaction, so the uploaded outputs-<env>.json artifact contained plaintext rds_endpoint/redis_endpoint for every environment. Filter those keys out with jq before writing the file, and print the (correctly redacted) human-readable `terraform output` to the job logs for any legitimate need to eyeball values.
terraform plan/apply only ever passed -var-file="environments/<env>.tfvars",
but none of those files (nor any TF_VAR_*/`-var` flag) supplied the
required, no-default variables: db_username, db_password, hmac_key,
sendgrid_api_key, api_signing_key, acm_certificate_arn, api_image_uri,
redis_auth_token, sendgrid_key_rotated_at. Every environment hard-failed
with "No value for required variable".
Populate TF_VAR_* for each of these from per-environment GitHub encrypted
secrets (e.g. DB_PASSWORD_DEV/STAGING/PROD), following the same
secrets[format('X_{0}', matrix.environment)] pattern already used for
AWS_ROLE_* in this workflow. Committed tfvars files remain free of
secrets.
The apply job's matrix (dev/staging/prod) ran unconditionally on every
push to main with no environment: key, so prod applied automatically
with no manual gate -- contradicting environments/README.md, which
documents production as requiring explicit approval.
Set `environment: ${{ matrix.environment }}` on the apply job so each
matrix leg maps to a same-named GitHub Environment. Configure a "prod"
environment with required reviewers in repo settings to make that leg
pause for approval; dev/staging have no protection rules configured and
continue to auto-apply as before.
terraform.yml authenticated with long-lived AWS_ACCESS_KEY_ID/
AWS_SECRET_ACCESS_KEY repo secrets on every PR touching Terraform,
including the prod matrix leg -- weaker than deploy.yml, which already
uses short-lived OIDC role assumption. A leaked static key never
expires and is usable outside CI.
Switch to role-to-assume (AWS_ROLE_ARN), resolved per GitHub Environment
via the job's existing `environment: ${{ matrix.environment }}`, and add
the id-token: write permission OIDC requires. The old
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY secrets are no longer referenced
anywhere and should be deleted from repo settings.
|
@dami-005 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Description:
Type of Change
Testing Done
Bundle Size
Checklist
docs/architecture.mdRelated Issues
Closes #1204
Closes #1205
Closes #1206
Closes #1207