Skip to content

Commit a9feff7

Browse files
[dotnet/release/8.0] Update dependencies from dotnet/arcade
1 parent 1ed1640 commit a9feff7

19 files changed

Lines changed: 343 additions & 138 deletions

‎eng/Version.Details.xml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<ProductDependencies>
44
</ProductDependencies>
55
<ToolsetDependencies>
6-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.26371.5">
6+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.26431.7">
77
<Uri>https://github.com/dotnet/arcade</Uri>
8-
<Sha>444c2ef3c414558e2e409ee346f1faebb19687eb</Sha>
8+
<Sha>25da4e8f08fab05a39c27443df99b96d738f3c82</Sha>
99
</Dependency>
10-
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="8.0.0-beta.26371.5">
10+
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="8.0.0-beta.26431.7">
1111
<Uri>https://github.com/dotnet/arcade</Uri>
12-
<Sha>444c2ef3c414558e2e409ee346f1faebb19687eb</Sha>
12+
<Sha>25da4e8f08fab05a39c27443df99b96d738f3c82</Sha>
1313
</Dependency>
14-
<Dependency Name="Microsoft.DotNet.Build.Tasks.Packaging" Version="8.0.0-beta.26371.5">
14+
<Dependency Name="Microsoft.DotNet.Build.Tasks.Packaging" Version="8.0.0-beta.26431.7">
1515
<Uri>https://github.com/dotnet/arcade</Uri>
16-
<Sha>444c2ef3c414558e2e409ee346f1faebb19687eb</Sha>
16+
<Sha>25da4e8f08fab05a39c27443df99b96d738f3c82</Sha>
1717
</Dependency>
1818
</ToolsetDependencies>
1919
</Dependencies>

‎eng/Versions.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PreReleaseVersionIteration>
88
</PropertyGroup>
99
<PropertyGroup>
10-
<MicrosoftDotNetBuildTasksPackagingVersion>8.0.0-beta.26371.5</MicrosoftDotNetBuildTasksPackagingVersion>
10+
<MicrosoftDotNetBuildTasksPackagingVersion>8.0.0-beta.26431.7</MicrosoftDotNetBuildTasksPackagingVersion>
1111
</PropertyGroup>
1212
<PropertyGroup>
1313
<WasiSdkVersion>16</WasiSdkVersion>

‎eng/common/Get-GitHubAppToken.ps1‎

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Mints a short-lived GitHub App installation access token by signing a JWT
2+
# with a private key stored in Azure Key Vault (RSA, RS256). The signed JWT is
3+
# exchanged with the GitHub API for a token scoped to a single installation.
4+
#
5+
# Requirements:
6+
# - A GitHub App whose private key has been uploaded into Key Vault as an RSA
7+
# key (the PEM converted to a Key Vault *key*, NOT stored as a secret).
8+
# - The caller (the federated Azure service connection used to run this script)
9+
# must have the `Key Vault Crypto User` role (or at minimum the `Sign`
10+
# action) on that key.
11+
# - The App must be installed on the target organization/account
12+
# (`InstallationOwner`) with the permissions/repositories it needs.
13+
#
14+
# Installation tokens (ghs_*) are exempt from the enterprise classic-PAT
15+
# lifetime policy, which is why this replaces the long-lived PAT.
16+
17+
[CmdletBinding()]
18+
param(
19+
# Name of the Key Vault that holds the GitHub App's RSA signing key.
20+
[Parameter(Mandatory = $true)]
21+
[string] $KeyVaultName,
22+
23+
# Name of the RSA key inside the Key Vault (the App's private key).
24+
[Parameter(Mandatory = $true)]
25+
[string] $KeyName,
26+
27+
# The GitHub App's Client ID (the value to put in the `iss` JWT claim).
28+
[Parameter(Mandatory = $true)]
29+
[string] $AppClientId,
30+
31+
# Login of the organization or user account whose installation we should
32+
# mint the token for (e.g. `dotnet`, `microsoft`).
33+
[Parameter(Mandatory = $true)]
34+
[string] $InstallationOwner,
35+
36+
# Optional Azure DevOps pipeline variable name to set with the installation
37+
# token (marked as a secret). When not specified, the token is written to
38+
# stdout instead.
39+
[Parameter(Mandatory = $false)]
40+
[string] $OutputVariableName
41+
)
42+
43+
$ErrorActionPreference = 'Stop'
44+
$PSNativeCommandUseErrorActionPreference = $true
45+
46+
. $PSScriptRoot\pipeline-logging-functions.ps1
47+
48+
function ConvertTo-Base64Url([byte[]] $bytes) {
49+
return [Convert]::ToBase64String($bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_')
50+
}
51+
52+
# Build JWT header and payload. Use [ordered] hashtables so JSON
53+
# serialization is deterministic.
54+
$jwtHeader = [ordered]@{
55+
alg = 'RS256'
56+
typ = 'JWT'
57+
}
58+
$now = [System.DateTimeOffset]::UtcNow
59+
$jwtPayload = [ordered]@{
60+
iat = $now.AddMinutes(-1).ToUnixTimeSeconds()
61+
exp = $now.AddMinutes(5).ToUnixTimeSeconds()
62+
iss = $AppClientId
63+
}
64+
65+
$headerEncoded = ConvertTo-Base64Url ([System.Text.Encoding]::UTF8.GetBytes(($jwtHeader | ConvertTo-Json -Compress)))
66+
$payloadEncoded = ConvertTo-Base64Url ([System.Text.Encoding]::UTF8.GetBytes(($jwtPayload | ConvertTo-Json -Compress)))
67+
$signingInput = "$headerEncoded.$payloadEncoded"
68+
69+
# Key Vault `sign` expects the *digest* (base64), not the raw bytes.
70+
$sha256 = [System.Security.Cryptography.SHA256]::Create()
71+
$digestBytes = $sha256.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($signingInput))
72+
$digestBase64 = [Convert]::ToBase64String($digestBytes)
73+
74+
Write-Host "Signing JWT with key '$KeyName' in vault '$KeyVaultName'..."
75+
$previousNativeCommandErrorPreference = $PSNativeCommandUseErrorActionPreference
76+
try {
77+
# Azure CLI can emit non-fatal Python warnings to stderr even when signing succeeds.
78+
# Use the exit code to determine success for this invocation.
79+
$PSNativeCommandUseErrorActionPreference = $false
80+
$signatureBase64 = az keyvault key sign `
81+
--vault-name $KeyVaultName `
82+
--name $KeyName `
83+
--algorithm RS256 `
84+
--digest $digestBase64 `
85+
--query signature `
86+
--output tsv `
87+
--only-show-errors
88+
$signExitCode = $LASTEXITCODE
89+
}
90+
catch {
91+
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to sign the JWT via Key Vault (key '$KeyName', vault '$KeyVaultName'): $_. Verify the service connection identity has the 'Key Vault Crypto User' role (Sign action) on the key."
92+
exit 1
93+
}
94+
finally {
95+
$PSNativeCommandUseErrorActionPreference = $previousNativeCommandErrorPreference
96+
}
97+
if ($signExitCode -ne 0 -or [string]::IsNullOrWhiteSpace($signatureBase64)) {
98+
Write-PipelineTelemetryError -Category 'Build' -Message "'az keyvault key sign' exited with code $signExitCode for key '$KeyName' in vault '$KeyVaultName'. Verify the service connection identity has the 'Key Vault Crypto User' role (Sign action) on the key."
99+
exit 1
100+
}
101+
$signatureUrl = $signatureBase64.Trim().TrimEnd('=').Replace('+', '-').Replace('/', '_')
102+
$jwt = "$signingInput.$signatureUrl"
103+
104+
$headers = @{
105+
Authorization = "Bearer $jwt"
106+
'X-GitHub-Api-Version' = '2022-11-28'
107+
Accept = 'application/vnd.github+json'
108+
'User-Agent' = 'dotnet-arcade-onelocbuild'
109+
}
110+
111+
Write-Host "Looking up installation for '$InstallationOwner'..."
112+
try {
113+
$installations = [System.Collections.Generic.List[object]]::new()
114+
$page = 1
115+
do {
116+
$pageResponse = Invoke-RestMethod `
117+
-Uri "https://api.github.com/app/installations?per_page=100&page=$page" `
118+
-Headers $headers `
119+
-Method Get
120+
$pageInstallationCount = 0
121+
foreach ($installation in $pageResponse) {
122+
$installations.Add($installation)
123+
$pageInstallationCount++
124+
}
125+
$page++
126+
} while ($pageInstallationCount -eq 100)
127+
}
128+
catch {
129+
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to list GitHub App installations: $_. The signed JWT may be invalid or the App's Client ID ('$AppClientId') may be incorrect."
130+
exit 1
131+
}
132+
$matchingInstallations = @($installations | Where-Object { $_.account.login -ieq $InstallationOwner })
133+
if ($matchingInstallations.Count -eq 0) {
134+
$found = ($installations | ForEach-Object { $_.account.login }) -join ', '
135+
Write-PipelineTelemetryError -Category 'Build' -Message "No installation found for '$InstallationOwner'. App is installed on: $found"
136+
exit 1
137+
}
138+
if ($matchingInstallations.Count -ne 1) {
139+
$matchingIds = ($matchingInstallations | ForEach-Object { $_.id }) -join ', '
140+
Write-PipelineTelemetryError -Category 'Build' -Message "Found multiple installations for '$InstallationOwner': $matchingIds"
141+
exit 1
142+
}
143+
$installation = $matchingInstallations[0]
144+
Write-Host "Using installation $($installation.id) for '$($installation.account.login)'."
145+
146+
try {
147+
$tokenResponse = Invoke-RestMethod `
148+
-Uri "https://api.github.com/app/installations/$($installation.id)/access_tokens" `
149+
-Headers $headers `
150+
-Method Post `
151+
-ContentType 'application/json'
152+
}
153+
catch {
154+
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to mint an installation access token for '$InstallationOwner' (installation $($installation.id)): $_"
155+
exit 1
156+
}
157+
158+
Write-Host "Got installation token for '$InstallationOwner' (expires $($tokenResponse.expires_at))."
159+
if ($OutputVariableName) {
160+
Write-Host "Setting pipeline variable '$OutputVariableName'."
161+
Write-Host "##vso[task.setvariable variable=$OutputVariableName;issecret=true]$($tokenResponse.token)"
162+
}
163+
else {
164+
Write-Host $tokenResponse.token -ForegroundColor Green
165+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Mints a short-lived GitHub App installation access token by signing a JWT
2+
# with a private key stored in Azure Key Vault (RSA, RS256). The JWT is
3+
# exchanged with the GitHub API for a token scoped to a single installation.
4+
#
5+
# Requirements (per GitHub App you want to authenticate as):
6+
# - A GitHub App with its private key uploaded into Key Vault as an RSA key
7+
# (PEM converted to a key, NOT stored as a secret).
8+
# - The Azure service connection passed via `azureSubscription` must be
9+
# granted the `Key Vault Crypto User` role (or at minimum `Sign` action)
10+
# on that key.
11+
# - The App must be installed on the target organization/account
12+
# (`installationOwner`) with the permissions/repositories you need.
13+
#
14+
# Output: a secret pipeline variable named ${{ parameters.outputVariableName }}
15+
# containing the installation access token. Token lifetime is ~1 hour and is
16+
# automatically scrubbed from logs. Installation tokens are exempt from the
17+
# enterprise classic-PAT lifetime policy.
18+
19+
parameters:
20+
# Azure DevOps service connection (federated) that can call
21+
# `az keyvault key sign` on the App's signing key.
22+
- name: azureSubscription
23+
type: string
24+
25+
# Name of the Key Vault that holds the GitHub App's RSA signing key.
26+
- name: keyVaultName
27+
type: string
28+
29+
# Name of the RSA key inside the Key Vault (the App's private key).
30+
- name: keyName
31+
type: string
32+
33+
# The GitHub App's Client ID (the value to put in the `iss` JWT claim).
34+
# Prefer this over the numeric App ID; GitHub accepts either, but Client ID
35+
# is the documented form going forward.
36+
- name: appClientId
37+
type: string
38+
39+
# Login of the organization or user account whose installation we should
40+
# mint the token for (e.g. `dotnet`, `microsoft`).
41+
- name: installationOwner
42+
type: string
43+
44+
# Name of the pipeline variable that will receive the installation token.
45+
- name: outputVariableName
46+
type: string
47+
48+
- name: is1ESPipeline
49+
type: boolean
50+
51+
- name: stepName
52+
type: string
53+
default: getGitHubAppInstallationToken
54+
55+
- name: condition
56+
type: string
57+
default: ''
58+
59+
- name: displayName
60+
type: string
61+
default: Get GitHub App installation token
62+
63+
steps:
64+
- task: AzureCLI@2
65+
displayName: ${{ parameters.displayName }}
66+
name: ${{ parameters.stepName }}
67+
${{ if ne(parameters.condition, '') }}:
68+
condition: ${{ parameters.condition }}
69+
inputs:
70+
azureSubscription: ${{ parameters.azureSubscription }}
71+
scriptType: pscore
72+
scriptLocation: inlineScript
73+
inlineScript: |
74+
& "$(System.DefaultWorkingDirectory)/eng/common/Get-GitHubAppToken.ps1" `
75+
-KeyVaultName '${{ parameters.keyVaultName }}' `
76+
-KeyName '${{ parameters.keyName }}' `
77+
-AppClientId '${{ parameters.appClientId }}' `
78+
-InstallationOwner '${{ parameters.installationOwner }}' `
79+
-OutputVariableName '${{ parameters.outputVariableName }}'

‎eng/common/sdl/extract-artifact-packages.ps1‎

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)