Skip to content

Commit 3e2bdc1

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 9324ab2 commit 3e2bdc1

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
@@ -135,16 +135,38 @@ jobs:
135135
- name: Sign packages
136136
if: github.repository_owner == 'GeneXusLabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
137137
env:
138-
TIMESTAMPER_URL: ${{ secrets.CODE_SIGN_CERTIFICATE_TIMESTAMPER_URL }}
139-
PFX_BASE64: ${{ secrets.CODE_SIGN_CERTIFICATE_BASE64 }}
140-
PFX_PASS: ${{ secrets.CODE_SIGN_CERTIFICATE_PASSWORD }}
138+
VAULT_URL: ${{ secrets.AZURE_CODE_SIGNING_VAULT_URL }}
139+
CERT_NAME: ${{ vars.AZURE_CODE_SIGNING_CERT_NAME }}
140+
TIMESTAMPER_URL: ${{ vars.AZURE_CODE_SIGNING_TIMESTAMP_SERVER }}
141+
AZURE_TENANT: ${{ secrets.AZURE_CODE_SIGNING_TENANT }}
142+
AZURE_APP_ID: ${{ secrets.AZURE_CODE_SIGNING_APP_ID }}
143+
AZURE_APP_PASSWORD: ${{ secrets.AZURE_CODE_SIGNING_APP_PASSWORD }}
141144
run: |
142-
$codesign_pfx = "code_sign_cert.pfx"
143-
$bytes = [Convert]::FromBase64String($Env:PFX_BASE64)
144-
[IO.File]::WriteAllBytes($codesign_pfx, $bytes)
145+
# Restore the local tool manifest (.config/dotnet-tools.json) which pins NuGetKeyVaultSignTool.
146+
dotnet tool restore
147+
148+
# Acquire an Azure Key Vault access token via client_credentials grant.
149+
$body = @{
150+
grant_type = 'client_credentials'
151+
client_id = $Env:AZURE_APP_ID
152+
client_secret = $Env:AZURE_APP_PASSWORD
153+
scope = 'https://vault.azure.net/.default'
154+
}
155+
$token = (Invoke-RestMethod -Method Post `
156+
-Uri "https://login.microsoftonline.com/$Env:AZURE_TENANT/oauth2/v2.0/token" `
157+
-Body $body).access_token
158+
Write-Host "::add-mask::$token"
145159
160+
# Sign every produced .nupkg against the certificate stored in the vault.
146161
Get-ChildItem ".\dotnet\*.nupkg" -Recurse | ForEach-Object {
147-
dotnet nuget sign $_.FullName --certificate-path $codesign_pfx --certificate-password $Env:PFX_PASS --timestamper $Env:TIMESTAMPER_URL
162+
dotnet tool run NuGetKeyVaultSignTool sign $_.FullName `
163+
-kvu $Env:VAULT_URL `
164+
-kvc $Env:CERT_NAME `
165+
-kva $token `
166+
-tr $Env:TIMESTAMPER_URL `
167+
-td sha256 `
168+
-fd sha256
169+
if ($LASTEXITCODE -ne 0) { throw "NuGetKeyVaultSignTool failed for $($_.Name)" }
148170
}
149171
150172
- name: Configure Azure Artifacts feed

0 commit comments

Comments
 (0)