Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/skills/vstest-build-test/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ See [CONTRIBUTING.md](../../../CONTRIBUTING.md#running-a-specific-test) for more

### Running tests locally (DOTNET_ROOT gotcha)

Test executables are built against the repo's preview TFM (e.g. `net11.0`), and integration and
Test executables are built against the repo's preview TFM (e.g. `net12.0`), and integration and
smoke tests additionally launch test-asset apphosts built the same way. An apphost resolves its
shared runtime from `DOTNET_ROOT`, falling back to the machine-wide install
(`C:\Program Files\dotnet`), which usually lacks the preview runtime — so it fails instantly with
Expand Down
2 changes: 0 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@
<TestRunnerAdditionalArguments Condition=" '$(TestRunnerExternalArguments)' != ''">$(TestRunnerExternalArguments)</TestRunnerAdditionalArguments>
<!-- Skip windows only tests on non-windows systems. -->
<TestRunnerAdditionalArguments Condition=" '$(OS)' != 'Windows_NT' ">$(TestRunnerAdditionalArguments) --filter "TestCategory!=Windows&amp;TestCategory!=Windows-Review"</TestRunnerAdditionalArguments>
<!-- Arcade always passes the deprecated no-progress flag, which makes MTP 2.5+ warn outside CI and fails local builds that treat warnings as errors. An explicit progress option takes precedence and suppresses the warning. -->
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --progress off</TestRunnerAdditionalArguments>
<!-- Allow us to see errors instead of capturing everything into files. -->
<TestCaptureOutput>false</TestCaptureOutput>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<add key="dotnet10-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10-transport/nuget/v3/index.json" />
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
<add key="dotnet9-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9-transport/nuget/v3/index.json" />
<add key="dotnet12" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet12/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="vs-impl-archived" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl-archived/nuget/v3/index.json" />
Expand Down
2 changes: 1 addition & 1 deletion eng/Version.Details.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This file should be imported by eng/Versions.props
<Project>
<PropertyGroup>
<!-- dotnet-arcade dependencies -->
<MicrosoftDotNetArcadeSdkPackageVersion>12.0.0-beta.26469.3</MicrosoftDotNetArcadeSdkPackageVersion>
<MicrosoftDotNetArcadeSdkPackageVersion>12.0.0-beta.26569.6</MicrosoftDotNetArcadeSdkPackageVersion>
<!-- dotnet-core-setup dependencies -->
<MicrosoftExtensionsFileSystemGlobbingPackageVersion>2.0.0</MicrosoftExtensionsFileSystemGlobbingPackageVersion>
<!-- dotnet-dotnet dependencies -->
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="12.0.0-beta.26469.3">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="12.0.0-beta.26569.6">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>63c79a28ca6e086d59c5553e7ed69cacb1d52fbd</Sha>
<Sha>c27ac90fa251c0460888a432a4fb41f22643a64f</Sha>
</Dependency>
<Dependency Name="Microsoft.DiaSymReader.Pdb2Pdb" Version="1.1.0-beta2-19575-01">
<Uri>https://github.com/dotnet/symreader-converter</Uri>
Expand Down
103 changes: 50 additions & 53 deletions eng/common/Get-GitHubAppToken.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Mints a short-lived GitHub App installation access token by signing a JWT
# with an RSA private key (RS256). The signed JWT is exchanged with the GitHub
# API for a token scoped to a single installation.
# via Azure Key Vault's RSA signing operation (RS256). The private key never
# leaves Key Vault. The JWT is exchanged for a single installation's token.
#
# Requirements:
# - A GitHub App ID and PEM private key stored as Azure Key Vault secrets.
# - The federated Azure service connection running this script must have
# `Get` access to those two secrets.
# - The GitHub App's private key imported as a Key Vault RSA key.
# - Read access to the configured App-ID secret projection.
# - The federated Azure service connection must have the `Sign` action on
# that key. Reading private-key secrets is neither required nor supported.
# - The App must be installed on the target organization/account
# (`InstallationOwner`) with the permissions/repositories it needs.
#
Expand All @@ -14,17 +15,19 @@

[CmdletBinding()]
param(
# Name of the Key Vault holding the GitHub App credentials.
# Key Vault holding the App-ID projection and RSA signing key.
[Parameter(Mandatory = $true)]
[string] $KeyVaultName,

# Secret Manager projection containing the GitHub App ID.
# Name of the RSA signing key, not a Key Vault secret.
[Parameter(Mandatory = $true)]
[string] $AppIdSecretName,
[ValidateNotNullOrEmpty()]
[string] $KeyName,

# Secret Manager projection containing the PEM private key.
# Secret Manager projection containing the GitHub App's public ID.
[Parameter(Mandatory = $true)]
[string] $AppPrivateKeySecretName,
[ValidateNotNullOrEmpty()]
[string] $AppIdSecretName,

# Login of the organization or user account whose installation we should
# mint the token for (e.g. `dotnet`, `microsoft`).
Expand All @@ -51,55 +54,33 @@ function ConvertTo-Base64Url([byte[]] $bytes) {
return [Convert]::ToBase64String($bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_')
}

Write-Host "Reading GitHub App ID from secret '$AppIdSecretName' in vault '$KeyVaultName'..."
$previousNativeCommandErrorPreference = $PSNativeCommandUseErrorActionPreference
try {
# Azure CLI can emit non-fatal Python warnings to stderr.
$PSNativeCommandUseErrorActionPreference = $false
$keyVaultAccessToken = az account get-access-token `
# az keyvault secret show fails for this projection with Errno 22; az rest keeps authentication in Azure CLI.
$escapedSecretName = [Uri]::EscapeDataString($AppIdSecretName)
$appId = az rest `
--method get `
--url "https://$KeyVaultName.vault.azure.net/secrets/${escapedSecretName}?api-version=7.4" `
--resource https://vault.azure.net `
--query accessToken `
--query value `
--output tsv `
--only-show-errors
$tokenExitCode = $LASTEXITCODE
$secretExitCode = $LASTEXITCODE
}
catch {
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to acquire an Azure Key Vault access token: $_"
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to read App ID secret '$AppIdSecretName' from vault '$KeyVaultName' with Azure CLI: $_"
exit 1
}
finally {
$PSNativeCommandUseErrorActionPreference = $previousNativeCommandErrorPreference
}
if ($tokenExitCode -ne 0 -or [string]::IsNullOrWhiteSpace($keyVaultAccessToken)) {
Write-PipelineTelemetryError -Category 'Build' -Message "'az account get-access-token' exited with code $tokenExitCode while acquiring an Azure Key Vault access token."
if ($secretExitCode -ne 0 -or [string]::IsNullOrWhiteSpace($appId)) {
Write-PipelineTelemetryError -Category 'Build' -Message "'az rest' failed with exit code $secretExitCode while reading App ID secret '$AppIdSecretName' from vault '$KeyVaultName'. Verify the service connection can read this App-ID projection."
exit 1
}

function Get-KeyVaultSecret([string] $SecretName) {
# Use the data-plane REST API because `az keyvault secret show` can fail
# with Errno 22 on hosted Windows agents when reading these projections.
$escapedSecretName = [Uri]::EscapeDataString($SecretName)
$secretUri = "https://$KeyVaultName.vault.azure.net/secrets/$escapedSecretName`?api-version=7.4"
try {
$response = Invoke-RestMethod `
-Uri $secretUri `
-Headers @{ Authorization = "Bearer $keyVaultAccessToken" } `
-Method Get
}
catch {
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to read secret '$SecretName' from vault '$KeyVaultName': $_. Verify the secret exists and the service connection has 'Key Vault Secrets User' access to it."
exit 1
}
if ([string]::IsNullOrWhiteSpace($response.value)) {
Write-PipelineTelemetryError -Category 'Build' -Message "Secret '$SecretName' in vault '$KeyVaultName' is empty."
exit 1
}
return [string] $response.value
}

Write-Host "Reading GitHub App credentials from vault '$KeyVaultName'..."
$appId = Get-KeyVaultSecret $AppIdSecretName
$privateKey = Get-KeyVaultSecret $AppPrivateKeySecretName

# Build JWT header and payload. Use [ordered] hashtables so JSON
# serialization is deterministic.
$jwtHeader = [ordered]@{
Expand All @@ -125,23 +106,34 @@ finally {
$sha256.Dispose()
}

Write-Host 'Signing JWT with the GitHub App private key...'
$rsa = [System.Security.Cryptography.RSA]::Create()
$digestBase64 = [Convert]::ToBase64String($digestBytes)
Write-Host "Signing JWT with key '$KeyName' in vault '$KeyVaultName'..."
$previousNativeCommandErrorPreference = $PSNativeCommandUseErrorActionPreference
try {
$rsa.ImportFromPem($privateKey)
$signatureBytes = $rsa.SignHash(
$digestBytes,
[System.Security.Cryptography.HashAlgorithmName]::SHA256,
[System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
$signatureUrl = ConvertTo-Base64Url $signatureBytes
# Azure CLI can emit non-fatal Python warnings to stderr.
$PSNativeCommandUseErrorActionPreference = $false
$signatureBase64 = az keyvault key sign `
--vault-name $KeyVaultName `
--name $KeyName `
--algorithm RS256 `
--digest $digestBase64 `
--query signature `
--output tsv `
--only-show-errors
$signExitCode = $LASTEXITCODE
}
catch {
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to sign the GitHub App JWT with the supplied private key: $_"
Write-PipelineTelemetryError -Category 'Build' -Message "Failed to sign the JWT via Key Vault (key '$KeyName', vault '$KeyVaultName'): $_. Verify the service connection has the Sign action on the key."
exit 1
}
finally {
$rsa.Dispose()
$PSNativeCommandUseErrorActionPreference = $previousNativeCommandErrorPreference
}
if ($signExitCode -ne 0 -or [string]::IsNullOrWhiteSpace($signatureBase64)) {
Write-PipelineTelemetryError -Category 'Build' -Message "'az keyvault key sign' exited with code $signExitCode for key '$KeyName' in vault '$KeyVaultName'. Verify the service connection has the Sign action on the key."
exit 1
}
$signatureUrl = $signatureBase64.Trim().TrimEnd('=').Replace('+', '-').Replace('/', '_')
$jwt = "$signingInput.$signatureUrl"

$headers = @{
Expand Down Expand Up @@ -198,6 +190,11 @@ catch {
exit 1
}

if ([string]::IsNullOrWhiteSpace($tokenResponse.token)) {
Write-PipelineTelemetryError -Category 'Build' -Message "GitHub returned an empty installation token for '$InstallationOwner'."
exit 1
}

Write-Host "Got installation token for '$InstallationOwner' (expires $($tokenResponse.expires_at))."
if ($OutputVariableName) {
Write-Host "Setting pipeline variable '$OutputVariableName'."
Expand Down
4 changes: 0 additions & 4 deletions eng/common/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ try {
if (-not $PSBoundParameters.ContainsKey('nodeReuse')) {
$nodeReuse = $false
}
# MSBuild's multi-threaded mode isn't run on CI unless it was explicitly requested via -msbuildMultiThreaded.
if (-not $PSBoundParameters.ContainsKey('msbuildMultiThreaded')) {
$msbuildMultiThreaded = $false
}
}

if (-not [string]::IsNullOrEmpty($binaryLogName)) {
Expand Down
Loading
Loading