Repository navigation
217 lines (189 loc) · 8.64 KB
/
Copy pathcodeql.yml
File metadata and controls
217 lines (189 loc) · 8.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: CodeQL
# CodeQL's C/C++ analysis of the files the machine's patches touch, in the trees its builds make:
# each part's pinned upstream source with its patches applied (spin-machine-dev patched tree).
# The kernel and QEMU are compiled under CodeQL's tracer, only the files their patches touch
# (spin-machine-dev patched compile); qboot, swtpm, systemd and OpenSSH are analysed without a build, from
# a tree with every other C file taken out. A result on a line the patches added or changed fails
# the job and goes to code scanning, under the part's category, unless a codeql[<rule>] comment
# the patch put on the line before says why it stays; so does a touched C file the analysis did
# not extract (spin-machine-dev patched scope). Upstream's own results in the touched
# files are kept as the job's artifact, not sent to code scanning: an alert nobody here fixes is noise, and
# would block a merge once a ruleset requires CodeQL (#653).
#
# Beside them, the analysis of this repository's own Go and workflows (`own`). A Go result of medium
# security severity or above fails it (spin-machine-dev patched severe), unless a codeql[<rule>]
# comment in the source suppresses it and says why.
#
# Once a day on main, and by hand. Not on a pull request: the analysis cost every PR 2 minutes and
# one that reached a patch 5-10 more, and a patch is already held on its PR by checkpatch and
# sparse in its build (kernel/Dockerfile, #656). So a result on a patch line is found the day after
# its merge, not before it. A failed run opens an issue, as release.yml's pause job does, because a
# red scheduled run is seen by nobody.
on:
schedule:
- cron: "17 5 * * *"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: codeql
cancel-in-progress: false
env:
GITHUB_TOKEN: ${{ github.token }}
jobs:
analyze:
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
part: [qboot, swtpm, systemd, openssh]
build-mode: [none]
# Their files include headers only their builds generate: compiled, under the tracer
# (internal/patched, Part).
include:
- part: kernel
build-mode: manual
- part: qemu
build-mode: manual
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
# spin-machine-dev built and on the PATH, so a step's exit status is the verb's (go run makes
# it 1): the verbs below are the ones a person types (docs/cli.md).
- name: spin-machine-dev
run: go tool task bin
- name: Make the patched tree
run: spin-machine-dev patched tree ${{ matrix.part }}
- name: What a traced build needs
if: ${{ matrix.build-mode == 'manual' }}
run: go tool task patched-build-deps
# Before the tracer starts: what is built here is not extracted, and the analysis reads only
# what the step under it compiles (the kernel's vmlinux, built here when a touched file is one
# only it builds, would be the whole kernel).
- name: Build what compiling the touched files needs, untraced
if: ${{ matrix.build-mode == 'manual' }}
run: spin-machine-dev patched prepare ${{ matrix.part }}
- name: Initialize CodeQL
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with:
languages: c-cpp
build-mode: ${{ matrix.build-mode }}
source-root: _output/patched/${{ matrix.part }}/src
# As own's: a result under a codeql[<rule>] comment a patch added, which says why it
# stays, is reported suppressed, and scope passes it.
queries: security-extended
packs: codeql/cpp-queries:AlertSuppression.ql
- name: Compile what the patches touch, traced
if: ${{ matrix.build-mode == 'manual' }}
run: spin-machine-dev patched compile ${{ matrix.part }}
- name: Analyze
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with:
category: patched-${{ matrix.part }}
output: _output/patched/${{ matrix.part }}/sarif
upload: never
- name: Keep the results on lines the patches added, fail on one, and on a file not read
run: spin-machine-dev patched scope ${{ matrix.part }}
# Upstream's results in the files the patches touch, one a line: kept here, never uploaded as
# alerts.
- name: Keep upstream's results in the touched files
if: ${{ !cancelled() && hashFiles(format('_output/patched/{0}/upstream.txt', matrix.part)) != '' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: upstream-results-${{ matrix.part }}
path: _output/patched/${{ matrix.part }}/upstream.txt
retention-days: 90
# The analysis' own SARIF, whose diagnostics say what it extracted, for a scope that failed.
- name: Keep the SARIF
if: ${{ failure() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: sarif-${{ matrix.part }}
path: _output/patched/${{ matrix.part }}/sarif
retention-days: 14
# The touched files' results, whether or not the step above failed on one.
- name: Upload to code scanning
if: ${{ !cancelled() && hashFiles(format('_output/patched/{0}/scoped.sarif', matrix.part)) != '' }}
uses: github/codeql-action/upload-sarif@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with:
sarif_file: _output/patched/${{ matrix.part }}/scoped.sarif
category: patched-${{ matrix.part }}
# This repository's own Go and its workflows, which default setup cannot analyse beside this
# advanced workflow (#653).
own:
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: go
build-mode: autobuild
- language: actions
build-mode: none
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Go
if: ${{ matrix.language == 'go' }}
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
- name: Initialize CodeQL
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# The suppression query marks a result under a codeql[<rule>] comment, which says why it
# stays, so that severe below and code scanning pass it by.
queries: security-extended
packs: ${{ matrix.language == 'go' && 'codeql/go-queries:AlertSuppression.ql' || '' }}
- name: Analyze
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
with:
category: own-${{ matrix.language }}
output: _output/codeql/${{ matrix.language }}
- name: spin-machine-dev
if: ${{ matrix.language == 'go' }}
run: go tool task bin
- name: Fail on a result of medium security severity or above
if: ${{ matrix.language == 'go' }}
run: spin-machine-dev patched severe _output/codeql/go
# A failed day is an issue, opened once a day: the run's log says which job and why.
# Only main's: the issue is titled "failed on main", and a run dispatched on a branch is its
# author's to read (#731 was a branch's).
report:
needs: [analyze, own]
if: ${{ failure() && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
issues: write
env:
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
- name: spin-machine-dev
run: go tool task bin
- name: Open an issue for the failed analysis
run: spin-machine-dev failed CodeQL --run "$RUN"