From c68dcb26369f16263802fcd835bb8e4db4449c88 Mon Sep 17 00:00:00 2001 From: Jacob Page Date: Mon, 16 Nov 2026 12:59:12 -0800 Subject: [PATCH 1/2] fix(release): sign the Windows gddy.exe with DigiCert KeyLocker The Windows gddy.exe in each release is now Authenticode-signed, so SmartScreen shows the publisher name and managed machines that require signed executables can run it. The signature is verified before the binary is packaged. Signing uses DigiCert's official GitHub Action, pinned to a commit SHA, and replaces the hand-rolled PowerShell script. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/Sign-WithKeyLocker.ps1 | 107 ----------------------- .github/workflows/release.yml | 59 ++++++++++--- 2 files changed, 46 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/Sign-WithKeyLocker.ps1 diff --git a/.github/workflows/Sign-WithKeyLocker.ps1 b/.github/workflows/Sign-WithKeyLocker.ps1 deleted file mode 100644 index fbc63a79..00000000 --- a/.github/workflows/Sign-WithKeyLocker.ps1 +++ /dev/null @@ -1,107 +0,0 @@ -<# -.SYNOPSIS - Authenticode-sign the gddy.exe artifact with DigiCert KeyLocker, then - verify the signature. - -.DESCRIPTION - Used by .github/workflows/release.yml's Windows build leg. Signing is - gated by the caller via the `vars.ENABLE_WINDOWS_SIGNING == '1'` step - condition; this script assumes it should sign when invoked. - - Uses a KeyLocker service-account client cert + API key and an EV Code - Signing certificate keypair alias (both provisioned out of band). The - DigiCert client (smctl + KSP) is installed manually from the KeyLocker - API. `smctl sign` delegates to signtool, so the Windows SDK signtool - directory is added to PATH. - - Adapted from gocode-client's .github/scripts/Sign-WithKeyLocker.ps1. - - Required environment variables (mapped from repo secrets by the caller): - SM_HOST KeyLocker client-auth host - SM_API_KEY KeyLocker API token - SM_CLIENT_CERT_PASSWORD password for the client auth .p12 - SM_CLIENT_CERT_FILE_B64 base64 of the client auth .p12 - -.PARAMETER Path - One or more paths to artifacts to sign. - -.PARAMETER KeypairAlias - KeyLocker keypair alias to sign with (repo variable KEYLOCKER_KEYPAIR_ALIAS). -#> -param( - [Parameter(Mandatory = $true)] - [string[]] $Path, - - [Parameter(Mandatory = $true)] - [string] $KeypairAlias -) - -$ErrorActionPreference = 'Stop' - -foreach ($v in 'SM_HOST', 'SM_API_KEY', 'SM_CLIENT_CERT_PASSWORD', 'SM_CLIENT_CERT_FILE_B64') { - if (-not (Test-Path "env:$v")) { throw "Sign-WithKeyLocker: required env var '$v' is not set." } -} - -# Materialize the client authentication certificate (.p12) from the base64 -# secret and point SM_CLIENT_CERT_FILE (read by smctl) at it. Cleaned up in -# the `finally` block below regardless of how the script exits. -$p12 = Join-Path $env:RUNNER_TEMP 'keylocker-client.p12' -[IO.File]::WriteAllBytes($p12, [Convert]::FromBase64String($env:SM_CLIENT_CERT_FILE_B64)) -$env:SM_CLIENT_CERT_FILE = $p12 - -try { - # Install the DigiCert KeyLocker client tools (smctl + KSP + PKCS#11) if - # not already present on this runner. - $smHome = 'C:\Program Files\DigiCert\DigiCert Keylocker Tools' - if (-not (Test-Path (Join-Path $smHome 'smctl.exe'))) { - $msi = Join-Path $env:RUNNER_TEMP 'Keylockertools-windows-x64.msi' - curl.exe -fSs -X GET "$($env:SM_HOST)/signingmanager/api-ui/v1/releases/Keylockertools-windows-x64.msi/download" ` - -H "x-api-key:$($env:SM_API_KEY)" -o $msi - if ($LASTEXITCODE -ne 0) { throw "Sign-WithKeyLocker: KeyLocker tools download failed ($LASTEXITCODE)." } - $install = Start-Process msiexec.exe -ArgumentList "/i `"$msi`" /quiet /qn /norestart" -Wait -PassThru - if ($install.ExitCode -ne 0) { throw "Sign-WithKeyLocker: KeyLocker tools install failed ($($install.ExitCode))." } - } - - # `smctl sign` shells out to signtool, which is not on PATH by default. - $signtool = (Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe' -ErrorAction SilentlyContinue | - Sort-Object FullName -Descending | Select-Object -First 1) - if (-not $signtool) { throw 'Sign-WithKeyLocker: signtool.exe not found in the Windows SDK.' } - $env:PATH = "$smHome;$($signtool.Directory.FullName);$env:PATH" - - # Validate credentials. Redirect output to a file rather than the console: - # `smctl healthcheck` echoes a partially-masked API key / cert password - # that GitHub's exact-match secret masking does not catch. Removed - # immediately on success; left in place on failure for debugging (the - # runner itself is torn down afterward regardless). - $healthcheckLog = "$env:RUNNER_TEMP\keylocker-healthcheck.log" - smctl healthcheck --all *> $healthcheckLog - if ($LASTEXITCODE -ne 0) { throw "Sign-WithKeyLocker: smctl healthcheck failed ($LASTEXITCODE) - log withheld to avoid leaking credentials." } - Remove-Item $healthcheckLog -ErrorAction SilentlyContinue - - # Register the DigiCert KSP and sync the leaf cert into the Windows store. - # ksp register can exit non-zero when the KSP is already registered - # (BCryptRegisterProvider / STATUS_OBJECT_NAME_COLLISION 0xc0000035) — - # benign, so warn rather than fail the job; certsync has no such known - # benign-failure case, so it fails fast like the rest of the script. - smctl windows ksp register - if ($LASTEXITCODE -ne 0) { - Write-Warning "smctl windows ksp register exited $LASTEXITCODE - continuing (expected if the KSP is already registered)" - } - smctl windows certsync --keypair-alias="$KeypairAlias" - if ($LASTEXITCODE -ne 0) { throw "Sign-WithKeyLocker: smctl windows certsync failed ($LASTEXITCODE)." } - - foreach ($f in $Path) { - $full = (Resolve-Path $f).Path - Write-Host "::group::sign $full" - smctl sign --keypair-alias "$KeypairAlias" --input $full --verbose - if ($LASTEXITCODE -ne 0) { throw "Sign-WithKeyLocker: smctl sign failed for $full ($LASTEXITCODE)." } - & $signtool.FullName verify /pa /v $full - if ($LASTEXITCODE -ne 0) { throw "Sign-WithKeyLocker: signtool verify failed for $full ($LASTEXITCODE)." } - Write-Host "::endgroup::" - } - Write-Host "KeyLocker signing complete for: $($Path -join ', ')" -} -finally { - Remove-Item $p12 -ErrorAction SilentlyContinue - Remove-Item Env:\SM_CLIENT_CERT_FILE -ErrorAction SilentlyContinue -} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e0d058ec..31fd5b16 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -219,19 +219,52 @@ jobs: shell: bash run: security delete-keychain "${{ steps.signing_keychain.outputs.keychain_path }}" || true - # Windows Authenticode signing via DigiCert KeyLocker is temporarily - # disabled — tracked in DEVEX-1081. No SM_HOST/SM_API_KEY/etc. secrets - # or ENABLE_WINDOWS_SIGNING/KEYLOCKER_KEYPAIR_ALIAS vars exist on this - # repo yet. Re-enable once those land (see .github/workflows/Sign-WithKeyLocker.ps1). - # - name: Sign gddy.exe (DigiCert KeyLocker) - # if: matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' - # shell: pwsh - # env: - # SM_HOST: ${{ secrets.SM_HOST }} - # SM_API_KEY: ${{ secrets.SM_API_KEY }} - # SM_CLIENT_CERT_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }} - # SM_CLIENT_CERT_FILE_B64: ${{ secrets.SM_CLIENT_CERT_FILE }} - # run: ../.github/workflows/Sign-WithKeyLocker.ps1 -Path "target/${{ matrix.target }}/release/gddy.exe" -KeypairAlias "${{ vars.KEYLOCKER_KEYPAIR_ALIAS }}" + # Windows Authenticode signing via DigiCert KeyLocker (DEVEX-1081). All + # four steps are skipped unless the repo variable ENABLE_WINDOWS_SIGNING + # is set to 1. Configuration: + # secrets SM_API_KEY, SM_CLIENT_CERT_PASSWORD, and SM_CLIENT_CERT_FILE + # (base64 of the KeyLocker client-authentication .p12) + # variables SM_HOST (KeyLocker client-auth host), KEYLOCKER_KEYPAIR_ALIAS + - name: Prepare KeyLocker client certificate (Windows) + if: matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' + shell: pwsh + env: + SM_CLIENT_CERT_B64: ${{ secrets.SM_CLIENT_CERT_FILE }} + run: | + $p12 = Join-Path $env:RUNNER_TEMP 'keylocker-client.p12' + [IO.File]::WriteAllBytes($p12, [Convert]::FromBase64String($env:SM_CLIENT_CERT_B64)) + "SM_CLIENT_CERT_FILE=$p12" >> $env:GITHUB_ENV + + # The action silently skips signing when `input` or `keypair-alias` is + # empty, so the verify step below is what catches a missing alias. + - name: Sign gddy.exe (DigiCert KeyLocker) + if: matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' + uses: digicert/code-signing-software-trust-action@fae23a455ba4bde62b64fd7cb2f81ade788f5a95 # v1.2.1 + with: + simple-signing-mode: true + keypair-alias: ${{ vars.KEYLOCKER_KEYPAIR_ALIAS }} + input: ${{ github.workspace }}\rust\target\${{ matrix.target }}\release\gddy.exe + env: + SM_HOST: ${{ vars.SM_HOST }} + SM_API_KEY: ${{ secrets.SM_API_KEY }} + SM_CLIENT_CERT_FILE: ${{ env.SM_CLIENT_CERT_FILE }} + SM_CLIENT_CERT_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }} + + - name: Verify gddy.exe signature (Windows) + if: matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' + shell: pwsh + run: | + # signtool ships with the Windows SDK on the runner but is not on PATH. + $signtool = Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe' -ErrorAction SilentlyContinue | + Sort-Object FullName -Descending | Select-Object -First 1 + if (-not $signtool) { throw 'signtool.exe not found in the Windows SDK.' } + & $signtool.FullName verify /pa /v "target/${{ matrix.target }}/release/gddy.exe" + if ($LASTEXITCODE -ne 0) { throw "signtool verify failed ($LASTEXITCODE)." } + + - name: Remove KeyLocker client certificate (Windows) + if: always() && matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' + shell: pwsh + run: Remove-Item (Join-Path $env:RUNNER_TEMP 'keylocker-client.p12') -ErrorAction SilentlyContinue - name: Package gddy shell: bash From ec863fabfbe09bd3b99fe34b94c4ef2fe20ea087 Mon Sep 17 00:00:00 2001 From: Jacob Page Date: Mon, 16 Nov 2026 14:14:59 -0800 Subject: [PATCH 2/2] fix(release): fail with a clear message when signing config is missing Check every secret and variable the Windows signing steps need before using them, and name the ones that are missing. A missing or malformed client certificate now fails with a specific error instead of surfacing later inside the base64 decode or the signing action. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/release.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31fd5b16..9cc71273 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -230,13 +230,33 @@ jobs: shell: pwsh env: SM_CLIENT_CERT_B64: ${{ secrets.SM_CLIENT_CERT_FILE }} + SM_API_KEY: ${{ secrets.SM_API_KEY }} + SM_CLIENT_CERT_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }} + SM_HOST: ${{ vars.SM_HOST }} + KEYLOCKER_KEYPAIR_ALIAS: ${{ vars.KEYLOCKER_KEYPAIR_ALIAS }} run: | + # Fail up front, naming everything that is missing, instead of + # failing later inside the base64 decode or the signing action. + $missing = @('SM_API_KEY', 'SM_CLIENT_CERT_PASSWORD', 'SM_HOST', 'KEYLOCKER_KEYPAIR_ALIAS') | + Where-Object { [string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable($_)) } + if ([string]::IsNullOrWhiteSpace($env:SM_CLIENT_CERT_B64)) { $missing += 'SM_CLIENT_CERT_FILE' } + if ($missing) { + Write-Host "::error::Windows signing is enabled (ENABLE_WINDOWS_SIGNING=1) but these secrets/variables are not set: $($missing -join ', '). Set them in the repository settings, or set ENABLE_WINDOWS_SIGNING to 0 to skip signing." + exit 1 + } + try { + $bytes = [Convert]::FromBase64String($env:SM_CLIENT_CERT_B64) + } catch { + Write-Host '::error::The SM_CLIENT_CERT_FILE secret is not valid base64. It must be the base64 encoding of the client certificate .p12 file.' + exit 1 + } $p12 = Join-Path $env:RUNNER_TEMP 'keylocker-client.p12' - [IO.File]::WriteAllBytes($p12, [Convert]::FromBase64String($env:SM_CLIENT_CERT_B64)) + [IO.File]::WriteAllBytes($p12, $bytes) "SM_CLIENT_CERT_FILE=$p12" >> $env:GITHUB_ENV # The action silently skips signing when `input` or `keypair-alias` is - # empty, so the verify step below is what catches a missing alias. + # empty. The step above checks the alias; the verify step below catches + # anything else that leaves the binary unsigned. - name: Sign gddy.exe (DigiCert KeyLocker) if: matrix.os == 'windows-latest' && vars.ENABLE_WINDOWS_SIGNING == '1' uses: digicert/code-signing-software-trust-action@fae23a455ba4bde62b64fd7cb2f81ade788f5a95 # v1.2.1