Skip to content

Commit e7a1be7

Browse files
authored
Filter vendor and test CodeQL results (microsoft#2243)
Skip scanning for files under the `test/` or `vendor/` directories, or for `_test.go` files. Neither the Go or C/C++ CodeQL scanning support the `path-ignore` config options, raising the warning: ``` Path filters have no effect for Go Go does not support path-based filtering. The paths and paths-ignore configuration properties will have no effect for this language. ``` Use the recommended `advanced-security/filter-sarif` action to instead filter results, based on [provided example](https://github.com/advanced-security/filter-sarif?tab=readme-ov-file#example). Remove the config file since there is nothing to configure. Additionally, build the `securitypolicy.exe` and `dmverity-vhd` binaries during CodeQL, and `securitypolicy` during the normal build CI. Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 00640ef commit e7a1be7

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

.github/codeql/codeql-config.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ jobs:
698698
name: Build networkagent.exe
699699
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy
700700
name: Build securitypolicy.exe
701+
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy
702+
name: Build securitypolicy
703+
env:
704+
GOOS: linux
705+
GOARCH: amd64
701706
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/uvmboot
702707
name: Build uvmboot.exe
703708
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/zapdir
@@ -719,6 +724,7 @@ jobs:
719724
grantvmgroupaccess.exe
720725
networkagent.exe
721726
securitypolicy.exe
727+
securitypolicy
722728
uvmboot.exe
723729
zapdir.exe
724730

.github/workflows/codeql.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ jobs:
6868
internal/tools/extendedtask,
6969
internal/tools/grantvmgroupaccess,
7070
internal/tools/networkagent,
71+
internal/tools/securitypolicy
7172
internal/tools/uvmboot,
7273
internal/tools/zapdir,
7374
7475
- goos: linux
7576
language: go, c-cpp
7677
targets: >-
78+
cmd/dmverity-vhd,
7779
cmd/gcs,
7880
cmd/gcstools,
7981
cmd/hooks/wait-paths,
@@ -100,7 +102,6 @@ jobs:
100102
with:
101103
build-mode: manual
102104
languages: ${{matrix.language}}
103-
config-file: ./.github/codeql/codeql-config.yml
104105

105106
# build binaries
106107
- name: Build go binaries
@@ -122,7 +123,44 @@ jobs:
122123
if: ${{ matrix.goos == 'linux' }}
123124
run: make bin/vsockexec bin/init
124125

126+
# only upload results if the analysis fails
127+
# otherwise, save the output and use `advanced-security/filter-sarif` to filter paths
125128
- name: CodeQL Analyze
126129
uses: github/codeql-action/analyze@v3
127130
with:
128131
category: "/language:${{matrix.language}}"
132+
output: sarif-results
133+
upload: failure-only
134+
135+
- name: Filter Go SARIF Results
136+
uses: advanced-security/filter-sarif@v1
137+
with:
138+
patterns: |
139+
+**/*.go
140+
-**/*_test.go
141+
-test/**/*.go
142+
-vendor/**/*.go
143+
input: sarif-results/go.sarif
144+
output: sarif-results/go.sarif
145+
146+
- name: Filter C/C++ SARIF Results
147+
uses: advanced-security/filter-sarif@v1
148+
if: ${{ matrix.goos == 'linux' }}
149+
with:
150+
patterns: |
151+
+**/*
152+
-vendor/**/*
153+
input: sarif-results/cpp.sarif
154+
output: sarif-results/cpp.sarif
155+
156+
- name: Upload SARIF
157+
uses: github/codeql-action/upload-sarif@v3
158+
with:
159+
sarif_file: sarif-results
160+
161+
- name: Upload SARIF Results as Build Artifact
162+
uses: actions/upload-artifact@v4
163+
with:
164+
name: sarif-results-${{ matrix.goos }}
165+
path: sarif-results
166+
retention-days: 1

0 commit comments

Comments
 (0)