Skip to content

Commit af26973

Browse files
authored
Tweak vulnerability checks (fix broken builds) (#1684)
* Turn off vulnerability checks (we have `scan-vulnerable-dependencies.yml` for that) * Use `dotnet list package --vulnerable --include-transitive` to detect vulnerable packages * Make Sonar aware of vulnerable packages
1 parent c4c6820 commit af26973

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

.github/workflows/Steeltoe.All.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
persist-credentials: false
8585

8686
- name: Restore packages
87-
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release --verbosity minimal
87+
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release /p:NuGetAudit=false --verbosity minimal
8888

8989
- name: Build solution
9090
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal

.github/workflows/component-shared-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
persist-credentials: false
7676

7777
- name: Restore packages
78-
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release --verbosity minimal
78+
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release /p:NuGetAudit=false --verbosity minimal
7979

8080
- name: Build solution
8181
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal

.github/workflows/package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
persist-credentials: false
4646

4747
- name: Restore packages
48-
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release --verbosity minimal
48+
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release /p:NuGetAudit=false --verbosity minimal
4949

5050
- name: Calculate package version (for release)
5151
if: ${{ github.event_name == 'release' }}

.github/workflows/scan-vulnerable-dependencies.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,19 @@ jobs:
4141
persist-credentials: false
4242

4343
- name: Report vulnerable dependencies
44-
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal /p:NuGetAudit=true /p:NuGetAuditMode=all /p:NuGetAuditLevel=low /p:TreatWarningsAsErrors=True
44+
shell: pwsh
45+
run: |
46+
$ErrorActionPreference = 'Stop'
47+
$PSNativeCommandUseErrorActionPreference = $true
48+
49+
$output = dotnet list ${{ env.SOLUTION_FILE }} package --vulnerable --include-transitive --format json --output-version 1 2>&1
50+
$text = ($output | Out-String).TrimEnd()
51+
$json = $text | ConvertFrom-Json
52+
53+
foreach ($project in $json.projects) {
54+
if ($project.frameworks) {
55+
Write-Host 'Vulnerable package references were found.'
56+
dotnet list ${{ env.SOLUTION_FILE }} package --vulnerable --include-transitive
57+
exit 1
58+
}
59+
}

.github/workflows/sonarcube.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
DOTNET_CLI_TELEMETRY_OPTOUT: 1
2323
DOTNET_NOLOGO: true
2424
SOLUTION_FILE: 'src/Steeltoe.All.slnx'
25+
NUGET_VULNERABLE_PACKAGE_WARNINGS: '"NU1901;NU1902;NU1903;NU1904"'
2526
SONAR_TEST_ARGS: >-
2627
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/TestOutput
2728
--settings coverlet.runsettings -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.UseSourceLink=false
@@ -66,9 +67,6 @@ jobs:
6667
# Sonar: Shallow clones should be disabled for a better relevancy of analysis.
6768
fetch-depth: 0
6869

69-
- name: Restore packages
70-
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release --verbosity minimal
71-
7270
- name: Begin Sonar .NET scanner
7371
id: sonar_begin
7472
env:
@@ -77,8 +75,11 @@ jobs:
7775
dotnet sonarscanner begin /k:"SteeltoeOSS_steeltoe" /o:"steeltoeoss" /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
7876
/d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
7977
78+
- name: Restore packages
79+
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal /p:Configuration=Release /p:NuGetAuditLevel=low /p:WarningsNotAsErrors='${{ env.NUGET_VULNERABLE_PACKAGE_WARNINGS }}'
80+
8081
- name: Build solution
81-
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal
82+
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:NuGetAuditLevel=low /p:WarningsNotAsErrors='${{ env.NUGET_VULNERABLE_PACKAGE_WARNINGS }}'
8283

8384
- name: Test
8485
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" ${{ env.SONAR_TEST_ARGS }}

0 commit comments

Comments
 (0)