From 60d63ff4caca619215589acbb8c1d9c5f2e55b2a Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Nov 2026 05:25:57 +0000 Subject: [PATCH 1/3] ci: run EV signing jobs in the code-signing environment The EV signing service account in coder-ci will only trust jobs in this repository's code-signing environment, which only main and v* tags may use (coder/github-org-terraform). Today it trusts every workflow in the repository, so any branch can sign with Coder's EV certificate. --- .github/workflows/_desktop-release.yml | 3 +++ .github/workflows/pr.yml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/_desktop-release.yml b/.github/workflows/_desktop-release.yml index e1ac19d44f1..5dc50074dbc 100644 --- a/.github/workflows/_desktop-release.yml +++ b/.github/workflows/_desktop-release.yml @@ -201,6 +201,9 @@ jobs: build-windows: name: Build and Release Windows + # The EV signing service account (coder-ci) only trusts jobs in this + # environment, which only main and v* tags may use. + environment: code-signing runs-on: windows-latest permissions: contents: write # Upload release assets diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e59a31cfec2..8242abed5ea 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1338,6 +1338,10 @@ jobs: # Windows builds are slow - only run in merge queue and main pushes, not on every PR push if: ${{ (github.event_name == 'merge_group' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (needs.changes.outputs.src == 'true' || needs.changes.outputs.config == 'true') }} runs-on: windows-latest + # Pushes to main sign with the EV key, whose service account (coder-ci) + # only trusts jobs in code-signing. Merge queue builds run the queued PR's + # code, so they get no environment and stay unsigned. + environment: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'code-signing' || '' }} permissions: contents: read id-token: write # GCP workload identity for Windows code signing From 1ab9ce48bd03f4c9f279ac714757656a45cc2155 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Nov 2026 05:57:31 +0000 Subject: [PATCH 2/3] ci: only build release tags in release.yml desktop-builds signs in the code-signing environment, which is granted from the dispatch ref, but checked out the unvalidated tag input, so a dispatch from main could sign any branch or SHA. Preflight now requires the input to be an existing release tag and every build checks out refs/tags/. --- .github/workflows/_desktop-release.yml | 4 +++- .github/workflows/release.yml | 30 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/_desktop-release.yml b/.github/workflows/_desktop-release.yml index 5dc50074dbc..c56a661a775 100644 --- a/.github/workflows/_desktop-release.yml +++ b/.github/workflows/_desktop-release.yml @@ -202,7 +202,9 @@ jobs: build-windows: name: Build and Release Windows # The EV signing service account (coder-ci) only trusts jobs in this - # environment, which only main and v* tags may use. + # environment, which only main and v* tags may use. Callers must only pass + # a ref that is main or a v* tag (release.yml's preflight checks its tag + # input). v* tags are not protected in this repository. environment: code-signing runs-on: windows-latest permissions: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5213c62c29f..854b33ecf0d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,11 +19,18 @@ jobs: preflight: name: Validate release target runs-on: ubuntu-latest + outputs: + # The ref every build job checks out. Always a tag: desktop-builds signs + # in the code-signing environment, which is granted from the dispatch ref + # (main), so it must not check out an arbitrary branch or SHA. + ref: ${{ steps.target.outputs.ref }} steps: - name: Ensure release tag context + id: target env: EVENT_NAME: ${{ github.event_name }} INPUT_TAG: ${{ inputs.tag }} + GH_TOKEN: ${{ github.token }} run: | if [ -z "$RELEASE_TAG" ]; then echo "::error::RELEASE_TAG is empty. Ensure this workflow runs on a release event or refs/tags/* ref." @@ -39,7 +46,22 @@ jobs: fi fi - echo "Publishing tag $RELEASE_TAG" + if [ -n "$INPUT_TAG" ]; then + if [[ ! "$INPUT_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then + echo "::error::tag input must be a release tag like v1.2.3, got '$INPUT_TAG'" + exit 1 + fi + if ! gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$INPUT_TAG" --silent; then + echo "::error::tag $INPUT_TAG does not exist" + exit 1 + fi + ref="refs/tags/$INPUT_TAG" + else + ref="$GITHUB_REF" + fi + echo "ref=$ref" >> "$GITHUB_OUTPUT" + + echo "Publishing tag $RELEASE_TAG from $ref" desktop-builds: name: Build and Release Desktop Apps @@ -49,7 +71,7 @@ jobs: id-token: write # GCP workload identity for Windows code signing uses: ./.github/workflows/_desktop-release.yml with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} release_tag: ${{ inputs.tag || github.event.release.tag_name || github.ref_name }} secrets: inherit # zizmor: ignore[secrets-inherit] -- reusable workflow needs platform signing secrets @@ -62,7 +84,7 @@ jobs: packages: write # Push to GHCR uses: ./.github/workflows/_docker-release.yml with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} version: ${{ inputs.tag || github.event.release.tag_name || github.ref_name }} is_latest: true @@ -76,7 +98,7 @@ jobs: - name: Checkout code uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} fetch-depth: 0 # Required for git describe to find tags persist-credentials: false From 5ec03a3ca665f43d6e2dea1029a3df9436601a07 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Nov 2026 08:40:57 +0000 Subject: [PATCH 3/3] ci: pin release builds to a tag commit on main release.yml's preflight now resolves the release tag to its commit, rejects it unless that commit is on main, and passes the SHA to every build. v* tags are not protected here, so a tag on an unmerged commit could otherwise be built and EV-signed from a dispatch on main. --- .github/workflows/_desktop-release.yml | 6 ++--- .github/workflows/release.yml | 31 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/_desktop-release.yml b/.github/workflows/_desktop-release.yml index c56a661a775..568dacf066f 100644 --- a/.github/workflows/_desktop-release.yml +++ b/.github/workflows/_desktop-release.yml @@ -202,9 +202,9 @@ jobs: build-windows: name: Build and Release Windows # The EV signing service account (coder-ci) only trusts jobs in this - # environment, which only main and v* tags may use. Callers must only pass - # a ref that is main or a v* tag (release.yml's preflight checks its tag - # input). v* tags are not protected in this repository. + # environment, which only main and v* tags may use. v* tags are not + # protected in this repository, so callers must only pass a commit on main + # (release.yml's preflight resolves the tag and checks this). environment: code-signing runs-on: windows-latest permissions: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 854b33ecf0d..83d4da633f4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,9 +20,10 @@ jobs: name: Validate release target runs-on: ubuntu-latest outputs: - # The ref every build job checks out. Always a tag: desktop-builds signs - # in the code-signing environment, which is granted from the dispatch ref - # (main), so it must not check out an arbitrary branch or SHA. + # The commit every build job checks out: the release tag's commit, which + # must be on main. desktop-builds signs in the code-signing environment, + # which is granted from the dispatch ref (main), and v* tags are not + # protected, so it must not build a commit that never reached main. ref: ${{ steps.target.outputs.ref }} steps: - name: Ensure release tag context @@ -51,17 +52,25 @@ jobs: echo "::error::tag input must be a release tag like v1.2.3, got '$INPUT_TAG'" exit 1 fi - if ! gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$INPUT_TAG" --silent; then - echo "::error::tag $INPUT_TAG does not exist" - exit 1 - fi - ref="refs/tags/$INPUT_TAG" + tag_ref="refs/tags/$INPUT_TAG" else - ref="$GITHUB_REF" + tag_ref="$GITHUB_REF" + fi + + # Pin the build to the tag's commit, so moving the tag mid-run has + # no effect, and require that commit to be on main. + if ! sha=$(gh api "repos/$GITHUB_REPOSITORY/commits/$tag_ref" --jq .sha); then + echo "::error::tag ${tag_ref#refs/tags/} does not exist" + exit 1 + fi + status=$(gh api "repos/$GITHUB_REPOSITORY/compare/$sha...main" --jq .status) + if [ "$status" != "ahead" ] && [ "$status" != "identical" ]; then + echo "::error::${tag_ref#refs/tags/} points at $sha, which is not on main" + exit 1 fi - echo "ref=$ref" >> "$GITHUB_OUTPUT" + echo "ref=$sha" >> "$GITHUB_OUTPUT" - echo "Publishing tag $RELEASE_TAG from $ref" + echo "Publishing tag $RELEASE_TAG from $sha (${tag_ref#refs/tags/})" desktop-builds: name: Build and Release Desktop Apps