Skip to content

Commit 1b53ee9

Browse files
anaibertaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:feat/azure-keyvault-signing' into beta
1 parent ddb33c4 commit 1b53ee9

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
@@ -200,16 +200,38 @@ jobs:
200200
- name: Sign packages
201201
if: github.repository_owner == 'GeneXusLabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
202202
env:
203-
TIMESTAMPER_URL: ${{ secrets.CODE_SIGN_CERTIFICATE_TIMESTAMPER_URL }}
204-
PFX_BASE64: ${{ secrets.CODE_SIGN_CERTIFICATE_BASE64 }}
205-
PFX_PASS: ${{ secrets.CODE_SIGN_CERTIFICATE_PASSWORD }}
203+
VAULT_URL: ${{ secrets.AZURE_CODE_SIGNING_VAULT_URL }}
204+
CERT_NAME: ${{ vars.AZURE_CODE_SIGNING_CERT_NAME }}
205+
TIMESTAMPER_URL: ${{ vars.AZURE_CODE_SIGNING_TIMESTAMP_SERVER }}
206+
AZURE_TENANT: ${{ secrets.AZURE_CODE_SIGNING_TENANT }}
207+
AZURE_APP_ID: ${{ secrets.AZURE_CODE_SIGNING_APP_ID }}
208+
AZURE_APP_PASSWORD: ${{ secrets.AZURE_CODE_SIGNING_APP_PASSWORD }}
206209
run: |
207-
$codesign_pfx = "code_sign_cert.pfx"
208-
$bytes = [Convert]::FromBase64String($Env:PFX_BASE64)
209-
[IO.File]::WriteAllBytes($codesign_pfx, $bytes)
210+
# Restore the local tool manifest (.config/dotnet-tools.json) which pins NuGetKeyVaultSignTool.
211+
dotnet tool restore
212+
213+
# Acquire an Azure Key Vault access token via client_credentials grant.
214+
$body = @{
215+
grant_type = 'client_credentials'
216+
client_id = $Env:AZURE_APP_ID
217+
client_secret = $Env:AZURE_APP_PASSWORD
218+
scope = 'https://vault.azure.net/.default'
219+
}
220+
$token = (Invoke-RestMethod -Method Post `
221+
-Uri "https://login.microsoftonline.com/$Env:AZURE_TENANT/oauth2/v2.0/token" `
222+
-Body $body).access_token
223+
Write-Host "::add-mask::$token"
210224
225+
# Sign every produced .nupkg against the certificate stored in the vault.
211226
Get-ChildItem ".\dotnet\*.nupkg" -Recurse | ForEach-Object {
212-
dotnet nuget sign $_.FullName --certificate-path $codesign_pfx --certificate-password $Env:PFX_PASS --timestamper $Env:TIMESTAMPER_URL
227+
dotnet tool run NuGetKeyVaultSignTool sign $_.FullName `
228+
-kvu $Env:VAULT_URL `
229+
-kvc $Env:CERT_NAME `
230+
-kva $token `
231+
-tr $Env:TIMESTAMPER_URL `
232+
-td sha256 `
233+
-fd sha256
234+
if ($LASTEXITCODE -ne 0) { throw "NuGetKeyVaultSignTool failed for $($_.Name)" }
213235
}
214236
215237
- name: Configure Azure Artifacts feed

0 commit comments

Comments
 (0)