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
12 changes: 10 additions & 2 deletions PowerShell.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@

<TargetFramework>net7.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<PublishReadyToRun Condition=" '$(Configuration)' != 'Debug' ">true</PublishReadyToRun>
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -171,7 +169,15 @@

<!-- Define all OS, release configuration properties -->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
<Optimize>true</Optimize>
</PropertyGroup>

<!-- Define all OS, release configuration properties -->
<PropertyGroup Condition=" '$(Configuration)' == 'StaticAnalysis' ">
<Optimize>true</Optimize>
<DebugType>full</DebugType>
</PropertyGroup>

<!-- Define windows, release configuration properties -->
Expand All @@ -193,6 +199,8 @@
<!-- Define all OS, CodeCoverage configuration properties -->
<PropertyGroup Condition=" '$(Configuration)' == 'CodeCoverage' ">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the code coverage configuration

<!-- This is required to be portable to Coverlet tool !-->
<PublishReadyToRun Condition=" '$(Configuration)' != 'Debug' ">true</PublishReadyToRun>
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
<DebugType>portable</DebugType>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function Start-PSBuild {
"win7-x86")]
[string]$Runtime,

[ValidateSet('Debug', 'Release', 'CodeCoverage', '')] # We might need "Checked" as well
[ValidateSet('Debug', 'Release', 'CodeCoverage', 'StaticAnalysis', '')] # We might need "Checked" as well
[string]$Configuration,

[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d{1,2})?)?$")]
Expand Down Expand Up @@ -814,7 +814,7 @@ function Compress-TestContent {
function New-PSOptions {
[CmdletBinding()]
param(
[ValidateSet("Debug", "Release", "CodeCoverage", '')]
[ValidateSet('Debug', 'Release', 'CodeCoverage', 'StaticAnalysis', '')]
[string]$Configuration,

[ValidateSet("net7.0")]
Expand Down Expand Up @@ -2234,7 +2234,7 @@ function Start-DevPowerShell {
[string[]]$ArgumentList = @(),
[switch]$LoadProfile,
[Parameter(ParameterSetName='ConfigurationParamSet')]
[ValidateSet("Debug", "Release", "CodeCoverage", '')] # should match New-PSOptions -Configuration values
[ValidateSet('Debug', 'Release', 'CodeCoverage', 'StaticAnalysis', '')] # should match New-PSOptions -Configuration values
[string]$Configuration,
[Parameter(ParameterSetName='BinDirParamSet')]
[string]$BinDir,
Expand Down
7 changes: 7 additions & 0 deletions tools/releaseBuild/azureDevOps/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ stages:
- template: templates/compliance/compliance.yml
parameters:
parentJobs: []
- stage: APIScan
displayName: 'ApiScan'
dependsOn: []
jobs:
- template: templates/compliance/apiscan.yml
parameters:
parentJobs: []
- stage: notice
displayName: Generate Notice File
dependsOn: []
Expand Down
20 changes: 1 addition & 19 deletions tools/releaseBuild/azureDevOps/templates/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
- name: NugetSecurityAnalysisWarningLevel
value: none

# Defines the variables APIScanClient, APIScanTenant and APIScanSecret
- group: PS-PS-APIScan

displayName: Compliance
dependsOn:
${{ parameters.parentJobs }}
Expand All @@ -20,9 +17,6 @@ jobs:
demands:
- ImageOverride -equals PSMMS2019-Secure

# APIScan can take a long time
timeoutInMinutes: 180

steps:
- checkout: self
clean: true
Expand Down Expand Up @@ -93,18 +87,6 @@ jobs:

# PreFASt is not applicable

- task: securedevelopmentteam.vss-secure-development-tools.build-task-apiscan.APIScan@2
displayName: 'Run APIScan'
inputs:
softwareFolder: '$(CompliancePath)'
softwareName: PowerShell
softwareVersionNum: '$(ReleaseTagVar)'
isLargeApp: false
preserveTempFiles: true
env:
AzureServicesAuthConnectionString: RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)
continueOnError: true

- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
displayName: 'Publish Security Analysis Logs to Build Artifacts'
continueOnError: true
Expand All @@ -129,7 +111,7 @@ jobs:
displayName: 'Create Security Analysis Report'
inputs:
TsvFile: false
APIScan: true
APIScan: false
BinSkim: true
CredScan: true
PoliCheck: true
Expand Down
112 changes: 112 additions & 0 deletions tools/releaseBuild/azureDevOps/templates/compliance/apiscan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
jobs:
- job: APIScan
variables:
- name: runCodesignValidationInjection
value : false
- name: NugetSecurityAnalysisWarningLevel
value: none
- name: ReleaseTagVar
value: fromBranch
# Defines the variables APIScanClient, APIScanTenant and APIScanSecret
- group: PS-PS-APIScan
# PAT permissions NOTE: Declare a SymbolServerPAT variable in this group with a 'microsoft' organizanization scoped PAT with 'Symbols' Read permission.
# A PAT in the wrong org will give a single Error 203. No PAT will give a single Error 401, and individual pdbs may be missing even if permissions are correct.
- group: symbols

pool:
name: PowerShell1ES
demands:
- ImageOverride -equals PSMMS2019-Secure

# APIScan can take a long time
timeoutInMinutes: 180

steps:
- template: ../SetVersionVariables.yml
parameters:
ReleaseTagVar: $(ReleaseTagVar)
CreateJson: yes
UseJson: no

- pwsh: |
Import-Module .\build.psm1 -force
Start-PSBootstrap
workingDirectory: '$(Build.SourcesDirectory)'
retryCountOnTaskFailure: 2
displayName: 'Bootstrap'

- pwsh: |
Import-Module .\build.psm1 -force
Find-DotNet
dotnet tool install dotnet-symbol --tool-path $(Agent.ToolsDirectory)\tools\dotnet-symbol
$symbolToolPath = Get-ChildItem -Path $(Agent.ToolsDirectory)\tools\dotnet-symbol\dotnet-symbol.exe | Select-Object -First 1 -ExpandProperty FullName
Write-Host "##vso[task.setvariable variable=symbolToolPath]$symbolToolPath"
displayName: Install dotnet-symbol
retryCountOnTaskFailure: 2

- pwsh: |
Import-Module .\build.psm1 -force
Find-DotNet
Start-PSBuild -Configuration StaticAnalysis -PSModuleRestore -Clean

$OutputFolder = Split-Path (Get-PSOutput)
Write-Host "##vso[task.setvariable variable=BinDir]$OutputFolder"
workingDirectory: '$(Build.SourcesDirectory)'
displayName: 'Build PowerShell Source'

- pwsh: |
Get-ChildItem -Path env:
displayName: Capture Environment
condition: succeededOrFailed()

# Explicitly download symbols for the drop since the SDL image doesn't have http://SymWeb access and APIScan cannot handle https yet.
- pwsh: |
Import-Module .\build.psm1 -force
Find-DotNet
$pat = '$(SymbolServerPAT)'
if ($pat -like '*PAT*' -or $pat -eq '')
{
throw 'No PAT defined'
}
$url = 'https://microsoft.artifacts.visualstudio.com/defaultcollection/_apis/symbol/symsrv'
$(symbolToolPath) --authenticated-server-path $(SymbolServerPAT) $url --symbols -d "$env:BinDir\*" --recurse-subdirectories
displayName: 'Download Symbols for binaries'
retryCountOnTaskFailure: 2
workingDirectory: '$(Build.SourcesDirectory)'

- task: securedevelopmentteam.vss-secure-development-tools.build-task-apiscan.APIScan@2
displayName: 'Run APIScan'
inputs:
softwareFolder: '$(BinDir)'
softwareName: PowerShell
softwareVersionNum: '$(ReleaseTagVar)'
isLargeApp: false
preserveTempFiles: false
verbosityLevel: standard
# write a status update every 5 minutes. Default is 1 minute
statusUpdateInterval: '00:05:00'
env:
AzureServicesAuthConnectionString: RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)

- task: securedevelopmentteam.vss-secure-development-tools.build-task-report.SdtReport@2
continueOnError: true
displayName: 'Guardian Export'
inputs:
GdnExportVstsConsole: true
GdnExportSarifFile: true
GdnExportHtmlFile: true
GdnExportAllTools: false
GdnExportGdnToolApiScan: true
#this didn't do anything GdnExportCustomLogsFolder: '$(Build.ArtifactStagingDirectory)/Guardian'

- pwsh: |
Get-ChildItem -Path env:
displayName: Capture Environment
condition: succeededOrFailed()

- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@3
displayName: 'Publish Guardian Artifacts'
inputs:
AllTools: false
APIScan: true
ArtifactName: APIScan