Repository navigation
210 lines (190 loc) · 8 KB
/
Copy path_codeql-scan.yml
File metadata and controls
210 lines (190 loc) · 8 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
name: CodeQL Scan (reusable)
# Reusable workflow called by validate-plugin.yml. Runs CodeQL over the changed
# plugins of a PR merge commit and turns the SARIF into PR-comment inputs.
# pluginctl always runs from the base branch (checked out into _trusted), never
# from the untrusted merge tree.
on:
workflow_call:
inputs:
matrix:
required: true
type: string
pr_number:
required: true
type: string
base_ref:
required: true
type: string
outputs:
codeql_status:
value: ${{ jobs.analyze.outputs.codeql_status }}
codeql_errors:
value: ${{ jobs.analyze.outputs.codeql_errors }}
codeql_warnings:
value: ${{ jobs.analyze.outputs.codeql_warnings }}
codeql_mediums:
value: ${{ jobs.analyze.outputs.codeql_mediums }}
codeql_lows:
value: ${{ jobs.analyze.outputs.codeql_lows }}
codeql_unscanned_langs:
value: ${{ jobs.analyze.outputs.codeql_unscanned_langs }}
codeql_suppressed:
value: ${{ jobs.analyze.outputs.codeql_suppressed }}
codeql_sandbox_bypass:
value: ${{ jobs.analyze.outputs.codeql_sandbox_bypass }}
codeql_sandbox_bypass_detected:
value: ${{ jobs.analyze.outputs.codeql_sandbox_bypass_detected }}
codeql_capability_contract:
value: ${{ jobs.analyze.outputs.codeql_capability_contract }}
codeql_capability_contract_detected:
value: ${{ jobs.analyze.outputs.codeql_capability_contract_detected }}
permissions:
actions: read
contents: read
security-events: write
pull-requests: write
issues: write
env:
PYTHONPATH: ${{ github.workspace }}/_trusted/.github/pluginctl/src
jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
codeql_status: ${{ steps.status.outputs.codeql_status }}
codeql_errors: ${{ steps.status.outputs.codeql_errors }}
codeql_warnings: ${{ steps.status.outputs.codeql_warnings }}
codeql_mediums: ${{ steps.status.outputs.codeql_mediums }}
codeql_lows: ${{ steps.status.outputs.codeql_lows }}
codeql_unscanned_langs: ${{ steps.status.outputs.codeql_unscanned_langs }}
codeql_suppressed: ${{ steps.status.outputs.codeql_suppressed }}
codeql_sandbox_bypass: ${{ steps.status.outputs.codeql_sandbox_bypass }}
codeql_sandbox_bypass_detected: ${{ steps.status.outputs.codeql_sandbox_bypass_detected }}
codeql_capability_contract: ${{ steps.status.outputs.codeql_capability_contract }}
codeql_capability_contract_detected: ${{ steps.status.outputs.codeql_capability_contract_detected }}
steps:
- name: Checkout PR merge commit for analysis
uses: actions/checkout@v6
with:
ref: refs/pull/${{ inputs.pr_number }}/merge
sparse-checkout: .gitignore
sparse-checkout-cone-mode: false
# Merge ref is analyzed statically by CodeQL only; fork code is not executed.
allow-unsafe-pr-checkout: true
- name: Checkout trusted pluginctl (base)
uses: actions/checkout@v6
with:
repository: ${{ github.repository }}
ref: ${{ inputs.base_ref }}
path: _trusted
sparse-checkout: |
.github/pluginctl
.github/codeql
sparse-checkout-cone-mode: false
- name: Limit checkout to changed plugin folders only
run: |
echo '${{ inputs.matrix }}' | jq -r '.[] | "plugins/\(.)"' | git sparse-checkout set --stdin
git checkout
- name: Populate external plugin source for analysis
run: |
while IFS= read -r plugin_name; do
plugin_json="plugins/$plugin_name/plugin.json"
[[ ! -f "$plugin_json" ]] && continue
source_type=$(jq -r '.source_type // "local"' "$plugin_json")
[[ "$source_type" != "external" ]] && continue
version=$(jq -r '.version' "$plugin_json")
source_url_template=$(jq -r '.source_url // ""' "$plugin_json")
source_url="${source_url_template//\{version\}/$version}"
echo "Fetching release ZIP for CodeQL: $source_url"
curl -fsSL "$source_url" -o "/tmp/${plugin_name}-release.zip"
python -m pluginctl.release_archive "/tmp/${plugin_name}-release.zip" "plugins/$plugin_name"
rm -f "/tmp/${plugin_name}-release.zip"
done < <(echo '${{ inputs.matrix }}' | jq -r '.[]')
- name: Detect supported languages
id: detect-langs
run: python -m pluginctl detect-langs
- name: Expose trusted CodeQL pack
if: steps.detect-langs.outputs.found == 'true'
run: |
mkdir -p .github
cp -R _trusted/.github/codeql .github/codeql
- name: Initialize CodeQL
if: steps.detect-langs.outputs.found == 'true'
uses: github/codeql-action/init@v4
with:
languages: ${{ steps.detect-langs.outputs.languages }}
build-mode: none
# Query suite (security-extended: all security severities, no quality queries) and
# per-language alert-suppression packs (so inline `codeql[<rule-id>]` comments work)
# both live in this config file - see .github/codeql/codeql-config.yml for why. Sourced
# from the trusted base-branch checkout, never the untrusted PR merge tree.
config-file: _trusted/.github/codeql/codeql-config.yml
- name: Perform CodeQL Analysis
if: steps.detect-langs.outputs.found == 'true'
id: analyze
uses: github/codeql-action/analyze@v4
with:
category: pr-${{ inputs.pr_number }}
output: sarif-results
upload: false
continue-on-error: true
- name: Parse SARIF and set CodeQL status
id: status
if: always()
env:
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
python -m pluginctl sarif \
--results-dir sarif-results \
--repo "${{ github.repository }}" \
--sha "$(git rev-parse HEAD)" \
--matrix '${{ inputs.matrix }}' \
--analyze-outcome "${{ steps.analyze.outcome }}" \
--found "${{ steps.detect-langs.outputs.found }}" \
--languages "${{ steps.detect-langs.outputs.languages }}" \
--unscanned-langs "${{ steps.detect-langs.outputs.unscanned_langs }}"
- name: Upload findings detail for PR comment
if: always() && steps.status.outputs.codeql_status == 'failure'
uses: actions/upload-artifact@v7
with:
name: codeql-findings
path: codeql-findings.md
if-no-files-found: ignore
- name: Upload medium findings detail for PR comment
if: always()
uses: actions/upload-artifact@v7
with:
name: codeql-medium-findings
path: codeql-medium-findings.md
if-no-files-found: ignore
- name: Upload low findings detail for PR comment
if: always()
uses: actions/upload-artifact@v7
with:
name: codeql-low-findings
path: codeql-low-findings.md
if-no-files-found: ignore
- name: Upload suppressed findings detail for PR comment
if: always()
uses: actions/upload-artifact@v7
with:
name: codeql-suppressed-findings
path: codeql-suppressed-findings.md
if-no-files-found: ignore
- name: Upload sandbox-bypass findings detail for PR comment
if: always()
uses: actions/upload-artifact@v7
with:
name: codeql-sandbox-findings
path: codeql-sandbox-findings.md
if-no-files-found: ignore
- name: Upload capability-contract findings detail for PR comment
if: always()
uses: actions/upload-artifact@v7
with:
name: codeql-capability-contract-findings
path: codeql-capability-contract-findings.md
if-no-files-found: ignore
- name: Fail job if CodeQL found high/error/critical issues
if: always() && steps.status.outputs.codeql_status == 'failure'
run: exit 1