Skip to content

Commit

Permalink
[ci] Enable 1ES PT (#20728)
Browse files Browse the repository at this point in the history
* [ci] Enable 1ES

Try no pool

Extend

Add pool

try again

Use additional artifacts

try again

additionartifacts parameters

again

again

Publish artifact

Update

other target path

Try new image

Use image prop

try again

update path

try artifactsPath

missing s

Update internal

Spot bugs

Fix place

enable sign

Fix identation

Fix sign

again

Try do insertion

try again

again

use parameters

again

does this one works

Clean

ufff

Try fix sdk insertion

try insertion

Fix variables

try again

remove copy paste

fix supress

sourceRepositoriesToScan

nuget-signed

add insertion

Fix msi

fix sourceanalyst

fix pool

Add suppressionsFile for credScan

Fix variable name

Add SetupNugetSources.ps1 to CredScan supression

Cleanup

Add parameters.

Fix setup

if we fix it don't ignore it

Fix internal

try move binaries outside nuget

Push artifacs on i1esp

Disable loc

try other pool

Fix reference

try add apiscan and compliance

Try again

Only binaries for scan on windows

fix path

use @self

cleanup

fix

use old way on handlers

Fix pack

[ci] On Maui we can run less

try gndusupress

Don't use crescan suppressionsFile

* More updates

* [ci] Policheck by default with 1ES

* Update sdk-insertion.yml
  • Loading branch information
rmarinho committed Mar 1, 2024
1 parent df7a2c9 commit 6aaeb44
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 275 deletions.
13 changes: 0 additions & 13 deletions eng/automation/guardian/CredScanSuppressions.json

This file was deleted.

12 changes: 0 additions & 12 deletions eng/automation/guardian/PoliCheck.Exclusions.xml

This file was deleted.

8 changes: 8 additions & 0 deletions eng/automation/guardian/source.gdnsuppress
Expand Up @@ -152,6 +152,14 @@
"default"
],
"createdDate": "2023-12-19 01:00:51Z"
},
"db932a43593049dd3d581d65ef9043ce4a5cc9f6970942c61f7ff29a8395ab5a": {
"signature": "db932a43593049dd3d581d65ef9043ce4a5cc9f6970942c61f7ff29a8395ab5a",
"alternativeSignatures": [],
"memberOf": [
"default"
],
"createdDate": "2024-02-27 23:34:18Z"
}
}
}
10 changes: 5 additions & 5 deletions eng/common/SetupNugetSources.ps1
Expand Up @@ -25,7 +25,7 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$ConfigFile,
[Parameter(Mandatory = $true)][string]$Password
[Parameter(Mandatory = $true)][SecureString]$Password
)

$ErrorActionPreference = "Stop"
Expand All @@ -35,7 +35,7 @@ Set-StrictMode -Version 2.0
. $PSScriptRoot\tools.ps1

# Add source entry to PackageSources
function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Username, $Password) {
function AddPackageSource($sources, $SourceName, $SourceEndPoint, [SecureString] $creds, $Username, [SecureString] $Password) {
$packageSource = $sources.SelectSingleNode("add[@key='$SourceName']")

if ($packageSource -eq $null)
Expand All @@ -53,7 +53,7 @@ function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Usern
}

# Add a credential node for the specified source
function AddCredential($creds, $source, $username, $password) {
function AddCredential([SecureString] $creds, $source, $username, [SecureString] $password) {
# Looks for credential configuration for the given SourceName. Create it if none is found.
$sourceElement = $creds.SelectSingleNode($Source)
if ($sourceElement -eq $null)
Expand Down Expand Up @@ -85,7 +85,7 @@ function AddCredential($creds, $source, $username, $password) {
$passwordElement.SetAttribute("value", $Password)
}

function InsertMaestroPrivateFeedCredentials($Sources, $Creds, $Username, $Password) {
function InsertMaestroPrivateFeedCredentials($Sources, [SecureString] $Creds, $Username, [SecureString] $Password) {
$maestroPrivateSources = $Sources.SelectNodes("add[contains(@key,'darc-int')]")

Write-Host "Inserting credentials for $($maestroPrivateSources.Count) Maestro's private feeds."
Expand Down Expand Up @@ -164,4 +164,4 @@ foreach ($dotnetVersion in $dotnetVersions) {
}
}

$doc.Save($filename)
$doc.Save($filename)
Empty file modified eng/common/pipeline-logging-functions.sh 100644 → 100755
Empty file.
60 changes: 36 additions & 24 deletions eng/common/tools.ps1
Expand Up @@ -65,6 +65,9 @@ $ErrorActionPreference = 'Stop'
# Base-64 encoded SAS token that has permission to storage container described by $runtimeSourceFeed
[string]$runtimeSourceFeedKey = if (Test-Path variable:runtimeSourceFeedKey) { $runtimeSourceFeedKey } else { $null }

# True if the build is a product build
[bool]$productBuild = if (Test-Path variable:productBuild) { $productBuild } else { $false }

function Create-Directory ([string[]] $path) {
New-Item -Path $path -Force -ItemType 'Directory' | Out-Null
}
Expand Down Expand Up @@ -158,18 +161,13 @@ function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
$env:DOTNET_MULTILEVEL_LOOKUP=0

# Disable first run since we do not need all ASP.NET packages restored.
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_NOLOGO=1

# Disable telemetry on CI.
if ($ci) {
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

# Source Build uses DotNetCoreSdkDir variable
if ($env:DotNetCoreSdkDir -ne $null) {
$env:DOTNET_INSTALL_DIR = $env:DotNetCoreSdkDir
}

# Find the first path on %PATH% that contains the dotnet.exe
if ($useInstalledDotNetCli -and (-not $globalJsonHasRuntimes) -and ($env:DOTNET_INSTALL_DIR -eq $null)) {
$dotnetExecutable = GetExecutableFileName 'dotnet'
Expand Down Expand Up @@ -228,7 +226,7 @@ function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
Write-PipelinePrependPath -Path $dotnetRoot

Write-PipelineSetVariable -Name 'DOTNET_MULTILEVEL_LOOKUP' -Value '0'
Write-PipelineSetVariable -Name 'DOTNET_SKIP_FIRST_TIME_EXPERIENCE' -Value '1'
Write-PipelineSetVariable -Name 'DOTNET_NOLOGO' -Value '1'

return $global:_DotNetInstallDir = $dotnetRoot
}
Expand Down Expand Up @@ -379,13 +377,13 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
}

# Minimum VS version to require.
$vsMinVersionReqdStr = '17.6'
$vsMinVersionReqdStr = '17.7'
$vsMinVersionReqd = [Version]::new($vsMinVersionReqdStr)

# If the version of msbuild is going to be xcopied,
# use this version. Version matches a package here:
# https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/RoslynTools.MSBuild/versions/17.6.0-2
$defaultXCopyMSBuildVersion = '17.6.0-2'
# https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/Microsoft.DotNet.Arcade.MSBuild.Xcopy/versions/17.8.5
$defaultXCopyMSBuildVersion = '17.8.5'

if (!$vsRequirements) {
if (Get-Member -InputObject $GlobalJson.tools -Name 'vs') {
Expand Down Expand Up @@ -450,7 +448,7 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
if ($xcopyMSBuildVersion.Trim() -ine "none") {
$vsInstallDir = InitializeXCopyMSBuild $xcopyMSBuildVersion $install
if ($vsInstallDir -eq $null) {
throw "Could not xcopy msbuild. Please check that package 'RoslynTools.MSBuild @ $xcopyMSBuildVersion' exists on feed 'dotnet-eng'."
throw "Could not xcopy msbuild. Please check that package 'Microsoft.DotNet.Arcade.MSBuild.Xcopy @ $xcopyMSBuildVersion' exists on feed 'dotnet-eng'."
}
}
if ($vsInstallDir -eq $null) {
Expand Down Expand Up @@ -487,7 +485,7 @@ function InstallXCopyMSBuild([string]$packageVersion) {
}

function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install) {
$packageName = 'RoslynTools.MSBuild'
$packageName = 'Microsoft.DotNet.Arcade.MSBuild.Xcopy'
$packageDir = Join-Path $ToolsDir "msbuild\$packageVersion"
$packagePath = Join-Path $packageDir "$packageName.$packageVersion.nupkg"

Expand Down Expand Up @@ -601,7 +599,15 @@ function InitializeBuildTool() {
ExitWithExitCode 1
}
$dotnetPath = Join-Path $dotnetRoot (GetExecutableFileName 'dotnet')
$buildTool = @{ Path = $dotnetPath; Command = 'msbuild'; Tool = 'dotnet'; Framework = 'net8.0' }

# Use override if it exists - commonly set by source-build
if ($null -eq $env:_OverrideArcadeInitializeBuildToolFramework) {
$initializeBuildToolFramework="net9.0"
} else {
$initializeBuildToolFramework=$env:_OverrideArcadeInitializeBuildToolFramework
}

$buildTool = @{ Path = $dotnetPath; Command = 'msbuild'; Tool = 'dotnet'; Framework = $initializeBuildToolFramework }
} elseif ($msbuildEngine -eq "vs") {
try {
$msbuildPath = InitializeVisualStudioMSBuild -install:$restore
Expand Down Expand Up @@ -676,8 +682,14 @@ function Read-ArcadeSdkVersion() {
}

function InitializeToolset() {
if (Test-Path variable:global:_ToolsetBuildProj) {
return $global:_ToolsetBuildProj
# For Unified Build/Source-build support, check whether the environment variable is
# set. If it is, then use this as the toolset build project.
if ($env:_InitializeToolset -ne $null) {
return $global:_InitializeToolset = $env:_InitializeToolset
}

if (Test-Path variable:global:_InitializeToolset) {
return $global:_InitializeToolset
}

$nugetCache = GetNuGetPackageCachePath
Expand All @@ -688,7 +700,7 @@ function InitializeToolset() {
if (Test-Path $toolsetLocationFile) {
$path = Get-Content $toolsetLocationFile -TotalCount 1
if (Test-Path $path) {
return $global:_ToolsetBuildProj = $path
return $global:_InitializeToolset = $path
}
}

Expand All @@ -711,7 +723,7 @@ function InitializeToolset() {
throw "Invalid toolset path: $path"
}

return $global:_ToolsetBuildProj = $path
return $global:_InitializeToolset = $path
}

function ExitWithExitCode([int] $exitCode) {
Expand Down Expand Up @@ -763,12 +775,10 @@ function MSBuild() {
# new scripts need to work with old packages, so we need to look for the old names/versions
(Join-Path $basePath (Join-Path $buildTool.Framework 'Microsoft.DotNet.ArcadeLogging.dll')),
(Join-Path $basePath (Join-Path $buildTool.Framework 'Microsoft.DotNet.Arcade.Sdk.dll')),
(Join-Path $basePath (Join-Path netcoreapp2.1 'Microsoft.DotNet.ArcadeLogging.dll')),
(Join-Path $basePath (Join-Path netcoreapp2.1 'Microsoft.DotNet.Arcade.Sdk.dll'))
(Join-Path $basePath (Join-Path netcoreapp3.1 'Microsoft.DotNet.ArcadeLogging.dll')),
(Join-Path $basePath (Join-Path netcoreapp3.1 'Microsoft.DotNet.Arcade.Sdk.dll'))
(Join-Path $basePath (Join-Path net7.0 'Microsoft.DotNet.ArcadeLogging.dll')),
(Join-Path $basePath (Join-Path net7.0 'Microsoft.DotNet.Arcade.Sdk.dll'))
(Join-Path $basePath (Join-Path net7.0 'Microsoft.DotNet.Arcade.Sdk.dll')),
(Join-Path $basePath (Join-Path net8.0 'Microsoft.DotNet.ArcadeLogging.dll')),
(Join-Path $basePath (Join-Path net8.0 'Microsoft.DotNet.Arcade.Sdk.dll'))
)
$selectedPath = $null
foreach ($path in $possiblePaths) {
Expand Down Expand Up @@ -827,7 +837,8 @@ function MSBuild-Core() {
}
}

$env:ARCADE_BUILD_TOOL_COMMAND = "$($buildTool.Path) $cmdArgs"
# Be sure quote the path in case there are spaces in the dotnet installation location.
$env:ARCADE_BUILD_TOOL_COMMAND = "`"$($buildTool.Path)`" $cmdArgs"

$exitCode = Exec-Process $buildTool.Path $cmdArgs

Expand All @@ -842,7 +853,8 @@ function MSBuild-Core() {
}

# When running on Azure Pipelines, override the returned exit code to avoid double logging.
if ($ci -and $env:SYSTEM_TEAMPROJECT -ne $null) {
# Skip this when the build is a child of the VMR orchestrator build.
if ($ci -and $env:SYSTEM_TEAMPROJECT -ne $null -and !$productBuild -and $properties -notlike "*DotNetBuildRepo=true*") {
Write-PipelineSetResult -Result "Failed" -Message "msbuild execution failed."
# Exiting with an exit code causes the azure pipelines task to log yet another "noise" error
# The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error
Expand Down
32 changes: 17 additions & 15 deletions eng/common/tools.sh 100644 → 100755
Expand Up @@ -68,6 +68,9 @@ fi
runtime_source_feed=${runtime_source_feed:-''}
runtime_source_feed_key=${runtime_source_feed_key:-''}

# True if the build is a product build
product_build=${product_build:-false}

# Resolve any symlinks in the given path.
function ResolvePath {
local path=$1
Expand Down Expand Up @@ -112,7 +115,7 @@ function InitializeDotNetCli {
export DOTNET_MULTILEVEL_LOOKUP=0

# Disable first run since we want to control all package sources
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_NOLOGO=1

# Disable telemetry on CI
if [[ $ci == true ]]; then
Expand All @@ -123,11 +126,6 @@ function InitializeDotNetCli {
# so it doesn't output warnings to the console.
export LTTNG_HOME="$HOME"

# Source Build uses DotNetCoreSdkDir variable
if [[ -n "${DotNetCoreSdkDir:-}" ]]; then
export DOTNET_INSTALL_DIR="$DotNetCoreSdkDir"
fi

# Find the first path on $PATH that contains the dotnet.exe
if [[ "$use_installed_dotnet_cli" == true && $global_json_has_runtimes == false && -z "${DOTNET_INSTALL_DIR:-}" ]]; then
local dotnet_path=`command -v dotnet`
Expand All @@ -146,7 +144,7 @@ function InitializeDotNetCli {
if [[ $global_json_has_runtimes == false && -n "${DOTNET_INSTALL_DIR:-}" && -d "$DOTNET_INSTALL_DIR/sdk/$dotnet_sdk_version" ]]; then
dotnet_root="$DOTNET_INSTALL_DIR"
else
dotnet_root="$repo_root/.dotnet"
dotnet_root="${repo_root}.dotnet"

export DOTNET_INSTALL_DIR="$dotnet_root"

Expand All @@ -165,7 +163,7 @@ function InitializeDotNetCli {
Write-PipelinePrependPath -path "$dotnet_root"

Write-PipelineSetVariable -name "DOTNET_MULTILEVEL_LOOKUP" -value "0"
Write-PipelineSetVariable -name "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" -value "1"
Write-PipelineSetVariable -name "DOTNET_NOLOGO" -value "1"

# return value
_InitializeDotNetCli="$dotnet_root"
Expand Down Expand Up @@ -310,7 +308,7 @@ function GetDotNetInstallScript {
curl "$install_script_url" -sSL --retry 10 --create-dirs -o "$install_script" || {
if command -v openssl &> /dev/null; then
echo "Curl failed; dumping some information about dotnet.microsoft.com for later investigation"
echo | openssl s_client -showcerts -servername dotnet.microsoft.com -connect dotnet.microsoft.com:443
echo | openssl s_client -showcerts -servername dotnet.microsoft.com -connect dotnet.microsoft.com:443 || true
fi
echo "Will now retry the same URL with verbose logging."
with_retries curl "$install_script_url" -sSL --verbose --retry 10 --create-dirs -o "$install_script" || {
Expand Down Expand Up @@ -341,7 +339,12 @@ function InitializeBuildTool {
# return values
_InitializeBuildTool="$_InitializeDotNetCli/dotnet"
_InitializeBuildToolCommand="msbuild"
_InitializeBuildToolFramework="net8.0"
# use override if it exists - commonly set by source-build
if [[ "${_OverrideArcadeInitializeBuildToolFramework:-x}" == "x" ]]; then
_InitializeBuildToolFramework="net9.0"
else
_InitializeBuildToolFramework="${_OverrideArcadeInitializeBuildToolFramework}"
fi
}

# Set RestoreNoCache as a workaround for https://github.com/NuGet/Home/issues/3116
Expand Down Expand Up @@ -453,12 +456,10 @@ function MSBuild {
local possiblePaths=()
possiblePaths+=( "$toolset_dir/$_InitializeBuildToolFramework/Microsoft.DotNet.ArcadeLogging.dll" )
possiblePaths+=( "$toolset_dir/$_InitializeBuildToolFramework/Microsoft.DotNet.Arcade.Sdk.dll" )
possiblePaths+=( "$toolset_dir/netcoreapp2.1/Microsoft.DotNet.ArcadeLogging.dll" )
possiblePaths+=( "$toolset_dir/netcoreapp2.1/Microsoft.DotNet.Arcade.Sdk.dll" )
possiblePaths+=( "$toolset_dir/netcoreapp3.1/Microsoft.DotNet.ArcadeLogging.dll" )
possiblePaths+=( "$toolset_dir/netcoreapp3.1/Microsoft.DotNet.Arcade.Sdk.dll" )
possiblePaths+=( "$toolset_dir/net7.0/Microsoft.DotNet.ArcadeLogging.dll" )
possiblePaths+=( "$toolset_dir/net7.0/Microsoft.DotNet.Arcade.Sdk.dll" )
possiblePaths+=( "$toolset_dir/net8.0/Microsoft.DotNet.ArcadeLogging.dll" )
possiblePaths+=( "$toolset_dir/net8.0/Microsoft.DotNet.Arcade.Sdk.dll" )
for path in "${possiblePaths[@]}"; do
if [[ -f $path ]]; then
selectedPath=$path
Expand Down Expand Up @@ -505,7 +506,8 @@ function MSBuild-Core {
echo "Build failed with exit code $exit_code. Check errors above."

# When running on Azure Pipelines, override the returned exit code to avoid double logging.
if [[ "$ci" == "true" && -n ${SYSTEM_TEAMPROJECT:-} ]]; then
# Skip this when the build is a child of the VMR orchestrator build.
if [[ "$ci" == true && -n ${SYSTEM_TEAMPROJECT:-} && "$product_build" != true && $properties != *"DotNetBuildRepo=true"* ]]; then
Write-PipelineSetResult -result "Failed" -message "msbuild execution failed."
# Exiting with an exit code causes the azure pipelines task to log yet another "noise" error
# The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error
Expand Down
23 changes: 23 additions & 0 deletions eng/pipelines/common/apiscan.yml
@@ -0,0 +1,23 @@
parameters:
poolName: VSEngSS-MicroBuild2022-1ES
vmImage: ''
os: windows
softwareName: 'MAUI'
softwareVersion: 8.0
dependsOn: []
scanArtifacts: []
stageName: 'api_scan'
displayName: 'ApiScan'

stages:
- template: security/apiscan/v0.yml@yaml-templates
parameters:
windowsPoolName: ${{ parameters.poolName }}
windowsImageOverride: ${{ parameters.vmImage }}
stageDependsOn: ${{ parameters.dependsOn }}
timeoutInMinutes: 600
scanArtifacts: ${{ parameters.scanArtifacts }}
sourceGdnSuppressionFile: '$(System.DefaultWorkingDirectory)\eng\automation\guardian\source.gdnsuppress'
tsaConfigFile: '$(System.DefaultWorkingDirectory)\eng\automation\guardian\tsaoptions-v2.json'
apiScanSoftwareName: ${{ parameters.softwareName }}
apiScanSoftwareVersionNum: ${{ parameters.softwareVersion }}

0 comments on commit 6aaeb44

Please sign in to comment.