Skip to content

Commit 7700101

Browse files
authored
ci: sign nupkgs against Azure Key Vault using NuGetKeyVaultSignTool (#1274)
Code signing requirements now mandate HSM-compatible certificate storage: local PFX files are no longer viable. The certificate has moved to an Azure Key Vault, so the workflow needs a tool that can sign nupkgs using a remote key — `dotnet nuget sign` only supports local PFX paths. Issue:208489
1 parent f39c5ae commit 7700101

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"nugetkeyvaultsigntool": {
6+
"version": "3.2.3",
7+
"commands": [
8+
"NuGetKeyVaultSignTool"
9+
]
10+
}
11+
}
12+
}

.github/workflows/Build.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,38 @@ jobs:
160160
- name: Sign packages
161161
if: github.repository_owner == 'GeneXusLabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
162162
env:
163-
TIMESTAMPER_URL: ${{ secrets.CODE_SIGN_CERTIFICATE_TIMESTAMPER_URL }}
164-
PFX_BASE64: ${{ secrets.CODE_SIGN_CERTIFICATE_BASE64 }}
165-
PFX_PASS: ${{ secrets.CODE_SIGN_CERTIFICATE_PASSWORD }}
163+
VAULT_URL: ${{ secrets.AZURE_CODE_SIGNING_VAULT_URL }}
164+
CERT_NAME: ${{ vars.AZURE_CODE_SIGNING_CERT_NAME }}
165+
TIMESTAMPER_URL: ${{ vars.AZURE_CODE_SIGNING_TIMESTAMP_SERVER }}
166+
AZURE_TENANT: ${{ secrets.AZURE_CODE_SIGNING_TENANT }}
167+
AZURE_APP_ID: ${{ secrets.AZURE_CODE_SIGNING_APP_ID }}
168+
AZURE_APP_PASSWORD: ${{ secrets.AZURE_CODE_SIGNING_APP_PASSWORD }}
166169
run: |
167-
$codesign_pfx = "code_sign_cert.pfx"
168-
$bytes = [Convert]::FromBase64String($Env:PFX_BASE64)
169-
[IO.File]::WriteAllBytes($codesign_pfx, $bytes)
170+
# Restore the local tool manifest (.config/dotnet-tools.json) which pins NuGetKeyVaultSignTool.
171+
dotnet tool restore
172+
173+
# Acquire an Azure Key Vault access token via client_credentials grant.
174+
$body = @{
175+
grant_type = 'client_credentials'
176+
client_id = $Env:AZURE_APP_ID
177+
client_secret = $Env:AZURE_APP_PASSWORD
178+
scope = 'https://vault.azure.net/.default'
179+
}
180+
$token = (Invoke-RestMethod -Method Post `
181+
-Uri "https://login.microsoftonline.com/$Env:AZURE_TENANT/oauth2/v2.0/token" `
182+
-Body $body).access_token
183+
Write-Host "::add-mask::$token"
170184
185+
# Sign every produced .nupkg against the certificate stored in the vault.
171186
Get-ChildItem ".\dotnet\*.nupkg" -Recurse | ForEach-Object {
172-
dotnet nuget sign $_.FullName --certificate-path $codesign_pfx --certificate-password $Env:PFX_PASS --timestamper $Env:TIMESTAMPER_URL
187+
dotnet tool run NuGetKeyVaultSignTool sign $_.FullName `
188+
-kvu $Env:VAULT_URL `
189+
-kvc $Env:CERT_NAME `
190+
-kva $token `
191+
-tr $Env:TIMESTAMPER_URL `
192+
-td sha256 `
193+
-fd sha256
194+
if ($LASTEXITCODE -ne 0) { throw "NuGetKeyVaultSignTool failed for $($_.Name)" }
173195
}
174196
175197
- name: Configure Azure Artifacts feed

0 commit comments

Comments
 (0)