Skip to content

Commit c1c6fe6

Browse files
anaibertaclaudiamurialdo
authored andcommitted
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 (cherry picked from commit 7700101)
1 parent e014d81 commit c1c6fe6

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
@@ -155,16 +155,38 @@ jobs:
155155
- name: Sign packages
156156
if: github.repository_owner == 'GeneXusLabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
157157
env:
158-
TIMESTAMPER_URL: ${{ secrets.CODE_SIGN_CERTIFICATE_TIMESTAMPER_URL }}
159-
PFX_BASE64: ${{ secrets.CODE_SIGN_CERTIFICATE_BASE64 }}
160-
PFX_PASS: ${{ secrets.CODE_SIGN_CERTIFICATE_PASSWORD }}
158+
VAULT_URL: ${{ secrets.AZURE_CODE_SIGNING_VAULT_URL }}
159+
CERT_NAME: ${{ vars.AZURE_CODE_SIGNING_CERT_NAME }}
160+
TIMESTAMPER_URL: ${{ vars.AZURE_CODE_SIGNING_TIMESTAMP_SERVER }}
161+
AZURE_TENANT: ${{ secrets.AZURE_CODE_SIGNING_TENANT }}
162+
AZURE_APP_ID: ${{ secrets.AZURE_CODE_SIGNING_APP_ID }}
163+
AZURE_APP_PASSWORD: ${{ secrets.AZURE_CODE_SIGNING_APP_PASSWORD }}
161164
run: |
162-
$codesign_pfx = "code_sign_cert.pfx"
163-
$bytes = [Convert]::FromBase64String($Env:PFX_BASE64)
164-
[IO.File]::WriteAllBytes($codesign_pfx, $bytes)
165+
# Restore the local tool manifest (.config/dotnet-tools.json) which pins NuGetKeyVaultSignTool.
166+
dotnet tool restore
167+
168+
# Acquire an Azure Key Vault access token via client_credentials grant.
169+
$body = @{
170+
grant_type = 'client_credentials'
171+
client_id = $Env:AZURE_APP_ID
172+
client_secret = $Env:AZURE_APP_PASSWORD
173+
scope = 'https://vault.azure.net/.default'
174+
}
175+
$token = (Invoke-RestMethod -Method Post `
176+
-Uri "https://login.microsoftonline.com/$Env:AZURE_TENANT/oauth2/v2.0/token" `
177+
-Body $body).access_token
178+
Write-Host "::add-mask::$token"
165179
180+
# Sign every produced .nupkg against the certificate stored in the vault.
166181
Get-ChildItem ".\dotnet\*.nupkg" -Recurse | ForEach-Object {
167-
dotnet nuget sign $_.FullName --certificate-path $codesign_pfx --certificate-password $Env:PFX_PASS --timestamper $Env:TIMESTAMPER_URL
182+
dotnet tool run NuGetKeyVaultSignTool sign $_.FullName `
183+
-kvu $Env:VAULT_URL `
184+
-kvc $Env:CERT_NAME `
185+
-kva $token `
186+
-tr $Env:TIMESTAMPER_URL `
187+
-td sha256 `
188+
-fd sha256
189+
if ($LASTEXITCODE -ne 0) { throw "NuGetKeyVaultSignTool failed for $($_.Name)" }
168190
}
169191
170192
- name: Configure Azure Artifacts feed

0 commit comments

Comments
 (0)