Add secure Terraform release workflow#1997
Conversation
Validate trusted commits, manifests, and protected environments before credentialed Terraform plan and apply jobs run, while keeping the workflow inert until release orchestration dispatches it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a security-focused preflight validation step for Terraform environment releases, ensuring workflow-dispatch inputs are verified via the GitHub API before any credentialed self-hosted runner work begins. It also enhances the run-dx-task action to pass GitHub auth context and expose task return values as JSON, and adds an (currently inert) reusable workflow to plan/apply using the validated immutable commit.
Changes:
- Add
validateTerraformEnvironmentReleasedx-task (with unit tests) that validates project/root mapping, protected default branch reachability, environment manifest, and required apply reviewers. - Update the default dispatcher and
run-dx-taskaction to pass a GitHub token through task context, and expose JSON task results as an action output. - Add a
workflow_dispatchTerraform environment release workflow that validates inputs, runs plan-upload, then applies a reviewed persisted plan.
Reviewed changes
Copilot reviewed 14 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/dx-tasks/src/tasks.ts | Registers the new validateTerraformEnvironmentRelease task definition. |
| packages/dx-tasks/src/index.ts | Exports the new validation task and its public types. |
| packages/dx-tasks/src/github/validate-terraform-environment-release.ts | Implements GitHub-API-based validation and trusted metadata resolution. |
| packages/dx-tasks/src/github/tests/validate-terraform-environment-release.test.ts | Unit tests covering validation and failure modes. |
| packages/dx-tasks/src/dispatcher.ts | Extends dispatcher context with githubToken. |
| packages/dx-tasks/src/default-dispatcher.ts | Wires githubToken into the default dispatcher context and registers the new task. |
| packages/dx-tasks/src/tests/default-dispatcher.test.ts | Adds dispatcher integration test coverage for the new task and Octokit mocks. |
| packages/dx-tasks/README.md | Documents the new available task. |
| actions/run-dx-task/src/index.ts | Reads GitHub token (currently via env) and sets JSON result output. |
| actions/run-dx-task/README.md | Documents the new result output contract. |
| actions/run-dx-task/dist/rolldown-runtime-DaDcL9Zw.mjs | Rebuilt bundled runtime output. |
| actions/run-dx-task/dist/es5-BIm4_leK.mjs | Rebuilt bundled dependency output. |
| actions/run-dx-task/action.yaml | Declares the new result output. |
| .nx/version-plans/version-plan-1784227063140.md | Version plan for run-dx-task action output change. |
| .nx/version-plans/version-plan-1784227055723.md | Version plan for @pagopa/dx-tasks new release validation task. |
| .github/workflows/release-terraform-environment-v1.yaml | Adds the new validated plan/approve/apply Terraform environment release workflow. |
Make token configuration explicit for callers while retaining the legacy GITHUB_TOKEN fallback and avoiding an implicit default that could override custom tokens. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep workflows compatible with the run-dx-task action currently published on main while the new explicit input is introduced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Code Review ReportTerraform Plan:
|
Why
Deployment inputs are workflow-dispatch data and must not be trusted before code runs on credentialed self-hosted runners.
What changed
run-dx-task.The workflow is not connected to
release-v2.yamlin this PR and is therefore inert.Validation
pnpm nx run-many -t test lint typecheck -p @pagopa/dx-tasks run-dx-taskpnpm nx run run-dx-task:buildDepends on #1996.
Extracted from #1926.