From 1da96d9459b3a11dad67932c34111e3ecbafa9b6 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Thu, 19 Nov 2026 00:01:02 +0800 Subject: [PATCH] ci(windows): sign releases with Azure Artifact Signing and OIDC --- .github/workflows/build-windows.yaml | 19 ++++++++++++++++++- .github/workflows/build.yaml | 3 +++ packaging/windows/README.md | 21 +++++++++++++++++++-- packaging/windows/installer.nsi | 4 ++++ scripts/sign-windows.ps1 | 24 ++++++++++++++++++++++++ scripts/test-windows-installer.ps1 | 7 +++++++ scripts/test-windows-signature.ps1 | 14 ++++++++++++++ 7 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 scripts/sign-windows.ps1 create mode 100644 scripts/test-windows-signature.ps1 diff --git a/.github/workflows/build-windows.yaml b/.github/workflows/build-windows.yaml index f5313a5..37b64db 100644 --- a/.github/workflows/build-windows.yaml +++ b/.github/workflows/build-windows.yaml @@ -49,6 +49,10 @@ permissions: jobs: build: runs-on: ${{ inputs.architecture == 'arm64' && 'windows-11-arm' || 'windows-2022' }} + environment: windows-signing + permissions: + contents: read + id-token: write timeout-minutes: 120 env: BUILD_ARCHITECTURE: ${{ inputs.architecture }} @@ -59,6 +63,10 @@ jobs: GPGUI_BUILD_VERSION: ${{ inputs.channel == 'snapshot' && inputs.build || '' }} GPGUI_WINDOWS_UPDATE_PUBLIC_KEY: ${{ vars.WINDOWS_UPDATE_PUBLIC_KEY }} GPGUI_LICENSE_SIGNING_KEYS: ${{ vars.GPGUI_LICENSE_SIGNING_KEYS }} + AZURE_SIGNING_ENDPOINT: ${{ vars.AZURE_SIGNING_ENDPOINT }} + AZURE_SIGNING_ACCOUNT: ${{ vars.AZURE_SIGNING_ACCOUNT }} + AZURE_SIGNING_PROFILE: ${{ vars.AZURE_SIGNING_PROFILE }} + WINDOWS_SIGNING_PUBLISHER: ${{ vars.WINDOWS_SIGNING_PUBLISHER }} steps: - name: Select native build tools id: native @@ -125,6 +133,15 @@ jobs: & ./source/gp/scripts/build-openconnect-windows.ps1 -MsysRoot $env:MSYS_ROOT -MsysSubsystem ${{ steps.native.outputs.subsystem }} -Prefix $prefix & ./source/gp/scripts/test-openconnect-windows.ps1 -MsysRoot $env:MSYS_ROOT -MsysSubsystem ${{ steps.native.outputs.subsystem }} -Prefix $prefix "OPENCONNECT_WINDOWS_PREFIX=$prefix" >> $env:GITHUB_ENV + - name: Log in to Azure with GitHub OIDC + uses: azure/login@v3 + with: + client-id: ${{ vars.AZURE_SIGNING_CLIENT_ID }} + tenant-id: ${{ vars.AZURE_TENANT_ID }} + subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} + - name: Install Microsoft Artifact Signing tooling + shell: pwsh + run: Install-Module ArtifactSigning -RequiredVersion 0.1.20 -Repository PSGallery -Force -Scope CurrentUser - name: Build and package the matching Windows runtime shell: pwsh env: @@ -134,7 +151,7 @@ jobs: $log = Join-Path $env:RUNNER_TEMP 'windows-package.log' # Compiler diagnostics may contain private GUI source. Keep them on the runner. try { - & ./source/gpgui/scripts/build-windows.ps1 -Profile Release ` + & ./source/gpgui/scripts/build-windows.ps1 -Profile Release -Sign ` -NativePrefix $env:OPENCONNECT_WINDOWS_PREFIX -MsysRoot $env:MSYS_ROOT -MsysSubsystem ${{ steps.native.outputs.subsystem }} ` -WintunDirectory (Join-Path $env:WINDOWS_BUILD_TOOLS 'wintun') ` -MakeNsis (Join-Path ${env:ProgramFiles(x86)} 'NSIS/makensis.exe') ` diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d77aaf2..fb51363 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -478,6 +478,9 @@ jobs: build-windows: needs: validate-inputs + permissions: + contents: read + id-token: write if: ${{ (github.event_name == 'workflow_dispatch' && inputs.build_windows) || (startsWith(github.ref, 'refs/tags/') && vars.BUILD_WINDOWS_ON_TAG == 'true') }} strategy: fail-fast: false diff --git a/packaging/windows/README.md b/packaging/windows/README.md index f96b1a4..23f721a 100644 --- a/packaging/windows/README.md +++ b/packaging/windows/README.md @@ -56,8 +56,25 @@ the current and previous attempt in ProgramData. No updater cache is added. The installer never launches the GUI as administrator. Users open GP Connect from the Start menu after completion. User configuration and licensing state -are retained during upgrades and uninstall. Authenticode setup is separate; -WinSparkle must still verify the installer payload signature before handoff. +are retained during upgrades and uninstall. Release builds use Azure Artifact +Signing with GitHub OIDC and RFC 3161 timestamps. Application executables, +the built OpenConnect DLL, and the generated NSIS uninstaller and installer +are signed before checksums and WinSparkle signatures are generated. +Vendor DLL signatures are preserved. WinSparkle independently verifies its +installer payload signature before handoff. + +The GitHub `windows-signing` environment is trusted by the Entra application +`gp-connect-github-signing`. Its only Azure role is Artifact Signing Certificate +Profile Signer on `tangramly-signing/certificateProfiles/gp-connect`. +Environment deployment policies allow the `release/next` branch and `v*` tags. +Repository variables supply `AZURE_SIGNING_CLIENT_ID`, `AZURE_TENANT_ID`, +`AZURE_SUBSCRIPTION_ID`, `AZURE_SIGNING_ENDPOINT`, `AZURE_SIGNING_ACCOUNT`, +`AZURE_SIGNING_PROFILE`, and `WINDOWS_SIGNING_PUBLISHER`. No Azure client secret +or signing private key is stored in GitHub. `build-windows.ps1 -Sign` requires +Microsoft's ArtifactSigning PowerShell module 0.1.20 and an Azure CLI login. +The build verifies the publisher, certificate trust and timestamp on each signed +file. The installer smoke test repeats those checks on the installed runtime +and uninstaller before testing removal. The Start menu shortcut registers `System.AppUserModel.ID` as `com.yuezk.gpgui`, matching the GUI and native toast sender. Windows uses the shortcut's name and diff --git a/packaging/windows/installer.nsi b/packaging/windows/installer.nsi index aee3af0..3d0b198 100644 --- a/packaging/windows/installer.nsi +++ b/packaging/windows/installer.nsi @@ -22,6 +22,10 @@ RequestExecutionLevel admin !ifndef DISPLAY_VERSION !define DISPLAY_VERSION "${PRODUCT_VERSION}" !endif +!ifdef SIGN_SCRIPT + !uninstfinalize 'pwsh -NoLogo -NoProfile -NonInteractive -File "${SIGN_SCRIPT}" -Files "%1"' = 0 + !finalize 'pwsh -NoLogo -NoProfile -NonInteractive -File "${SIGN_SCRIPT}" -Files "%1"' = 0 +!endif Name "GP Connect" OutFile "${OUTPUT_FILE}" diff --git a/scripts/sign-windows.ps1 b/scripts/sign-windows.ps1 new file mode 100644 index 0000000..7cd1447 --- /dev/null +++ b/scripts/sign-windows.ps1 @@ -0,0 +1,24 @@ +[CmdletBinding()] +param([Parameter(Mandatory=$true)][string[]]$Files) +$ErrorActionPreference = 'Stop' +foreach ($name in @('AZURE_SIGNING_ENDPOINT', 'AZURE_SIGNING_ACCOUNT', 'AZURE_SIGNING_PROFILE', 'WINDOWS_SIGNING_PUBLISHER')) { + if (![Environment]::GetEnvironmentVariable($name)) { throw "Missing signing configuration: $name" } +} +Import-Module ArtifactSigning -RequiredVersion 0.1.20 +$credentials = @{ + ExcludeEnvironmentCredential = $true + ExcludeWorkloadIdentityCredential = $true + ExcludeManagedIdentityCredential = $true + ExcludeSharedTokenCacheCredential = $true + ExcludeVisualStudioCredential = $true + ExcludeVisualStudioCodeCredential = $true + ExcludeAzurePowerShellCredential = $true + ExcludeAzureDeveloperCliCredential = $true + ExcludeInteractiveBrowserCredential = $true +} +# Azure CLI holds the short-lived GitHub OIDC login; no client secret is used. +Invoke-ArtifactSigning -Endpoint $env:AZURE_SIGNING_ENDPOINT ` + -CodeSigningAccountName $env:AZURE_SIGNING_ACCOUNT -CertificateProfileName $env:AZURE_SIGNING_PROFILE ` + -Files ($Files -join ',') -FileDigest SHA256 -TimestampDigest SHA256 ` + -TimestampRfc3161 'http://timestamp.acs.microsoft.com' -Description 'GP Connect' @credentials +& (Join-Path $PSScriptRoot 'test-windows-signature.ps1') -Files $Files -Publisher $env:WINDOWS_SIGNING_PUBLISHER diff --git a/scripts/test-windows-installer.ps1 b/scripts/test-windows-installer.ps1 index 60f1955..4ad6d6a 100644 --- a/scripts/test-windows-installer.ps1 +++ b/scripts/test-windows-installer.ps1 @@ -20,6 +20,13 @@ if ($process.ExitCode -ne 0) { } $info = Get-Content (Join-Path $destination 'build-info.json') -Raw | ConvertFrom-Json if ($info.architecture -ne $Architecture -or [string]$info.build_version -ne $Build) { throw 'The installed package identity does not match.' } +if ($env:WINDOWS_SIGNING_PUBLISHER) { + $signed = @($Installer) + foreach ($name in @('gpgui.exe', 'gpauth.exe', 'gpservice.exe', 'gp-posture.exe', 'libopenconnect-5.dll', 'uninstall.exe')) { + $signed += Join-Path $destination $name + } + & (Join-Path $PSScriptRoot 'test-windows-signature.ps1') -Files $signed -Publisher $env:WINDOWS_SIGNING_PUBLISHER +} $service = Get-CimInstance Win32_Service -Filter "Name='GPConnect'" if ($service.State -ne 'Running' -or $service.StartMode -ne 'Auto' -or $service.StartName -ne 'LocalSystem') { throw 'The service did not start automatically as LocalSystem.' diff --git a/scripts/test-windows-signature.ps1 b/scripts/test-windows-signature.ps1 new file mode 100644 index 0000000..d4affe7 --- /dev/null +++ b/scripts/test-windows-signature.ps1 @@ -0,0 +1,14 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory=$true)][string[]]$Files, + [Parameter(Mandatory=$true)][string]$Publisher +) +$ErrorActionPreference = 'Stop' +foreach ($file in $Files) { + $signature = Get-AuthenticodeSignature -LiteralPath $file + if ($signature.Status -ne 'Valid') { throw "Invalid Authenticode signature: $file ($($signature.Status))" } + $name = $signature.SignerCertificate.GetNameInfo([Security.Cryptography.X509Certificates.X509NameType]::SimpleName, $false) + if ($name -ne $Publisher) { throw "Unexpected signing publisher for ${file}: $name" } + if (!$signature.TimeStamperCertificate) { throw "Missing signature timestamp: $file" } + Write-Host "Verified $file (publisher: $name; timestamped)" +}