Skip to content

Commit d9d6b7f

Browse files
authored
Move ApiScan to compliance build (PowerShell#18191)
1 parent 618d1a7 commit d9d6b7f

File tree

5 files changed

+133
-24
lines changed

5 files changed

+133
-24
lines changed

PowerShell.Common.props

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@
137137

138138
<TargetFramework>net7.0</TargetFramework>
139139
<LangVersion>10.0</LangVersion>
140-
<PublishReadyToRun Condition=" '$(Configuration)' != 'Debug' ">true</PublishReadyToRun>
141-
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
142140

143141
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
144142
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -171,7 +169,15 @@
171169

172170
<!-- Define all OS, release configuration properties -->
173171
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
172+
<PublishReadyToRun>true</PublishReadyToRun>
173+
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
174+
<Optimize>true</Optimize>
175+
</PropertyGroup>
176+
177+
<!-- Define all OS, release configuration properties -->
178+
<PropertyGroup Condition=" '$(Configuration)' == 'StaticAnalysis' ">
174179
<Optimize>true</Optimize>
180+
<DebugType>full</DebugType>
175181
</PropertyGroup>
176182

177183
<!-- Define windows, release configuration properties -->
@@ -193,6 +199,8 @@
193199
<!-- Define all OS, CodeCoverage configuration properties -->
194200
<PropertyGroup Condition=" '$(Configuration)' == 'CodeCoverage' ">
195201
<!-- This is required to be portable to Coverlet tool !-->
202+
<PublishReadyToRun Condition=" '$(Configuration)' != 'Debug' ">true</PublishReadyToRun>
203+
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
196204
<DebugType>portable</DebugType>
197205
</PropertyGroup>
198206

build.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function Start-PSBuild {
319319
"win7-x86")]
320320
[string]$Runtime,
321321

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

325325
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d{1,2})?)?$")]
@@ -814,7 +814,7 @@ function Compress-TestContent {
814814
function New-PSOptions {
815815
[CmdletBinding()]
816816
param(
817-
[ValidateSet("Debug", "Release", "CodeCoverage", '')]
817+
[ValidateSet('Debug', 'Release', 'CodeCoverage', 'StaticAnalysis', '')]
818818
[string]$Configuration,
819819

820820
[ValidateSet("net7.0")]
@@ -2234,7 +2234,7 @@ function Start-DevPowerShell {
22342234
[string[]]$ArgumentList = @(),
22352235
[switch]$LoadProfile,
22362236
[Parameter(ParameterSetName='ConfigurationParamSet')]
2237-
[ValidateSet("Debug", "Release", "CodeCoverage", '')] # should match New-PSOptions -Configuration values
2237+
[ValidateSet('Debug', 'Release', 'CodeCoverage', 'StaticAnalysis', '')] # should match New-PSOptions -Configuration values
22382238
[string]$Configuration,
22392239
[Parameter(ParameterSetName='BinDirParamSet')]
22402240
[string]$BinDir,

tools/releaseBuild/azureDevOps/compliance.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ stages:
3939
- template: templates/compliance/compliance.yml
4040
parameters:
4141
parentJobs: []
42+
- stage: APIScan
43+
displayName: 'ApiScan'
44+
dependsOn: []
45+
jobs:
46+
- template: templates/compliance/apiscan.yml
47+
parameters:
48+
parentJobs: []
4249
- stage: notice
4350
displayName: Generate Notice File
4451
dependsOn: []

tools/releaseBuild/azureDevOps/templates/compliance.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ jobs:
99
- name: NugetSecurityAnalysisWarningLevel
1010
value: none
1111

12-
# Defines the variables APIScanClient, APIScanTenant and APIScanSecret
13-
- group: PS-PS-APIScan
14-
1512
displayName: Compliance
1613
dependsOn:
1714
${{ parameters.parentJobs }}
@@ -20,9 +17,6 @@ jobs:
2017
demands:
2118
- ImageOverride -equals PSMMS2019-Secure
2219

23-
# APIScan can take a long time
24-
timeoutInMinutes: 180
25-
2620
steps:
2721
- checkout: self
2822
clean: true
@@ -93,18 +87,6 @@ jobs:
9387

9488
# PreFASt is not applicable
9589

96-
- task: securedevelopmentteam.vss-secure-development-tools.build-task-apiscan.APIScan@2
97-
displayName: 'Run APIScan'
98-
inputs:
99-
softwareFolder: '$(CompliancePath)'
100-
softwareName: PowerShell
101-
softwareVersionNum: '$(ReleaseTagVar)'
102-
isLargeApp: false
103-
preserveTempFiles: true
104-
env:
105-
AzureServicesAuthConnectionString: RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)
106-
continueOnError: true
107-
10890
- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
10991
displayName: 'Publish Security Analysis Logs to Build Artifacts'
11092
continueOnError: true
@@ -129,7 +111,7 @@ jobs:
129111
displayName: 'Create Security Analysis Report'
130112
inputs:
131113
TsvFile: false
132-
APIScan: true
114+
APIScan: false
133115
BinSkim: true
134116
CredScan: true
135117
PoliCheck: true
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
jobs:
2+
- job: APIScan
3+
variables:
4+
- name: runCodesignValidationInjection
5+
value : false
6+
- name: NugetSecurityAnalysisWarningLevel
7+
value: none
8+
- name: ReleaseTagVar
9+
value: fromBranch
10+
# Defines the variables APIScanClient, APIScanTenant and APIScanSecret
11+
- group: PS-PS-APIScan
12+
# PAT permissions NOTE: Declare a SymbolServerPAT variable in this group with a 'microsoft' organizanization scoped PAT with 'Symbols' Read permission.
13+
# 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.
14+
- group: symbols
15+
16+
pool:
17+
name: PowerShell1ES
18+
demands:
19+
- ImageOverride -equals PSMMS2019-Secure
20+
21+
# APIScan can take a long time
22+
timeoutInMinutes: 180
23+
24+
steps:
25+
- template: ../SetVersionVariables.yml
26+
parameters:
27+
ReleaseTagVar: $(ReleaseTagVar)
28+
CreateJson: yes
29+
UseJson: no
30+
31+
- pwsh: |
32+
Import-Module .\build.psm1 -force
33+
Start-PSBootstrap
34+
workingDirectory: '$(Build.SourcesDirectory)'
35+
retryCountOnTaskFailure: 2
36+
displayName: 'Bootstrap'
37+
38+
- pwsh: |
39+
Import-Module .\build.psm1 -force
40+
Find-DotNet
41+
dotnet tool install dotnet-symbol --tool-path $(Agent.ToolsDirectory)\tools\dotnet-symbol
42+
$symbolToolPath = Get-ChildItem -Path $(Agent.ToolsDirectory)\tools\dotnet-symbol\dotnet-symbol.exe | Select-Object -First 1 -ExpandProperty FullName
43+
Write-Host "##vso[task.setvariable variable=symbolToolPath]$symbolToolPath"
44+
displayName: Install dotnet-symbol
45+
retryCountOnTaskFailure: 2
46+
47+
- pwsh: |
48+
Import-Module .\build.psm1 -force
49+
Find-DotNet
50+
Start-PSBuild -Configuration StaticAnalysis -PSModuleRestore -Clean
51+
52+
$OutputFolder = Split-Path (Get-PSOutput)
53+
Write-Host "##vso[task.setvariable variable=BinDir]$OutputFolder"
54+
workingDirectory: '$(Build.SourcesDirectory)'
55+
displayName: 'Build PowerShell Source'
56+
57+
- pwsh: |
58+
Get-ChildItem -Path env:
59+
displayName: Capture Environment
60+
condition: succeededOrFailed()
61+
62+
# Explicitly download symbols for the drop since the SDL image doesn't have http://SymWeb access and APIScan cannot handle https yet.
63+
- pwsh: |
64+
Import-Module .\build.psm1 -force
65+
Find-DotNet
66+
$pat = '$(SymbolServerPAT)'
67+
if ($pat -like '*PAT*' -or $pat -eq '')
68+
{
69+
throw 'No PAT defined'
70+
}
71+
$url = 'https://microsoft.artifacts.visualstudio.com/defaultcollection/_apis/symbol/symsrv'
72+
$(symbolToolPath) --authenticated-server-path $(SymbolServerPAT) $url --symbols -d "$env:BinDir\*" --recurse-subdirectories
73+
displayName: 'Download Symbols for binaries'
74+
retryCountOnTaskFailure: 2
75+
workingDirectory: '$(Build.SourcesDirectory)'
76+
77+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-apiscan.APIScan@2
78+
displayName: 'Run APIScan'
79+
inputs:
80+
softwareFolder: '$(BinDir)'
81+
softwareName: PowerShell
82+
softwareVersionNum: '$(ReleaseTagVar)'
83+
isLargeApp: false
84+
preserveTempFiles: false
85+
verbosityLevel: standard
86+
# write a status update every 5 minutes. Default is 1 minute
87+
statusUpdateInterval: '00:05:00'
88+
env:
89+
AzureServicesAuthConnectionString: RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)
90+
91+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-report.SdtReport@2
92+
continueOnError: true
93+
displayName: 'Guardian Export'
94+
inputs:
95+
GdnExportVstsConsole: true
96+
GdnExportSarifFile: true
97+
GdnExportHtmlFile: true
98+
GdnExportAllTools: false
99+
GdnExportGdnToolApiScan: true
100+
#this didn't do anything GdnExportCustomLogsFolder: '$(Build.ArtifactStagingDirectory)/Guardian'
101+
102+
- pwsh: |
103+
Get-ChildItem -Path env:
104+
displayName: Capture Environment
105+
condition: succeededOrFailed()
106+
107+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@3
108+
displayName: 'Publish Guardian Artifacts'
109+
inputs:
110+
AllTools: false
111+
APIScan: true
112+
ArtifactName: APIScan

0 commit comments

Comments
 (0)