Repository navigation
504 lines (461 loc) · 23.5 KB
/
Copy pathcodeql.yml
File metadata and controls
504 lines (461 loc) · 23.5 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
name: "CodeQL"
on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
types: [opened, labeled, unlabeled, synchronize]
# Code scanning and required checks must run on merge-queue commits too.
merge_group:
types: [checks_requested]
schedule:
# runs on 19:17 every Tuesday
- cron: "27 19 * * 2"
env:
# No `|direct` fallback: under harden-runner's block mode a direct fetch
# only fans out to blocked vanity-import hosts and burns minutes; see the
# GOPROXY comment in test.yml.
GOPROXY: "https://proxy.golang.org"
# Least-privilege default; every job below declares its own narrower
# job-level permissions that override this baseline.
permissions:
contents: read
jobs:
analyze:
name: Analyze
runs-on: ubuntu-24.04
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["go", "javascript-typescript"]
steps:
- name: Harden Runner
uses: $/.github/actions/harden-runner # nosemgrep: yaml.github-actions.security.github-actions-mutable-action-tag.github-actions-mutable-action-tag
with:
policies: >-
github
github-releases
go-checksums
go-proxy
go-vanity
go-analysis
go-analysis-toolchain
- name: Checkout repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
category: "/language:${{matrix.language}}"
# The merge queue's ephemeral gh-readonly-queue/... ref is deleted as
# soon as the queue cycles, which routinely races the upload for this
# multi-minute analysis and fails it with "ref not found" if the
# action is left to auto-detect ref/sha from GITHUB_REF/GITHUB_SHA
# (the doomed ephemeral ref). Skipping the upload entirely (an
# earlier attempt at this fix) isn't right either: the native
# "CodeQL" required status check is only created when a SARIF
# upload actually happens, so skipping it left that required check
# permanently missing for merge_group commits -- the merge queue
# then waits out its full timeout for a check that will never
# report, exactly like the PR Semver Labels gap. Instead, point the
# upload at the queue's real target branch ref (which persists)
# while still analyzing the actual queued merge commit.
ref: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || '' }}
sha: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || '' }}
# Unlike Dependabot/dependency-review (version-based), govulncheck does
# call-graph reachability analysis: it only flags CVEs in code this binary
# can actually reach, so findings here are high-confidence. Lives alongside
# lint-golangci below rather than its own file, matching that job's
# precedent for SARIF-producing Go tools that aren't CodeQL itself.
govulncheck:
name: govulncheck
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
steps:
- name: Harden Runner
uses: $/.github/actions/harden-runner # nosemgrep: yaml.github-actions.security.github-actions-mutable-action-tag.github-actions-mutable-action-tag
with:
# setup-go reads its version manifest from raw.githubusercontent.com;
# its official fallback follows golang.org -> go.dev -> dl.google.com.
policies: >-
github
github-releases
github-content
go-checksums
go-proxy
go-toolchain
go-vanity
go-analysis
go-vulnerability-db
- name: Checkout code
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
# GOPROXY no longer falls back to direct fetches (they only reach
# blocked vanity hosts under harden-runner's block mode), so every proxy
# request here gets bounded retries: the module graph via the shared
# retry action, and the govulncheck install via the loop below. The
# two steps that follow reproduce what golang/govulncheck-action does
# (install @latest, run with -format/-C) minus its non-retried install.
- name: Set up Go
uses: ./.github/actions/setup-go-cache
with:
go-version-file: go.mod
- name: Download Go module dependencies
uses: ./.github/actions/go-mod-download-retry
- name: Install govulncheck
shell: bash
env:
GOOS: ''
GOARCH: ''
run: |
set -euo pipefail
attempt=1
max_attempts=3
until go install golang.org/x/vuln/cmd/govulncheck@v1.8.0; do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "go install govulncheck failed after $max_attempts attempts" >&2
exit 1
fi
echo "go install govulncheck failed (attempt $attempt/$max_attempts), retrying in 15s..." >&2
sleep 15
attempt=$((attempt + 1))
done
# govulncheck only builds its whole-program call graph when an imported
# package has a known vuln (otherwise it returns early in seconds). On
# this module that pass peaks around 25GB RSS — measured locally when
# GO-2026-6597 (containerd/v2 < 2.3.6) landed — which exceeds the public
# runner's 16GB RAM and gets the runner OOM-killed (seen as `Killed`,
# exit 143 "shutdown signal", or "The operation was canceled"). Swap
# absorbs the overflow; request 30 GiB for the full scan.
- name: Add swap space
uses: ./.github/actions/swap-space
with:
size-gb: '30'
- name: Run govulncheck
shell: bash
# Bounds a swap-thrashing run instead of burning the 6h job default.
# Healthy runs take 13-25 min depending on runner load, so 30 min was
# too tight and timed out a run that a sibling run passed in 22 min.
timeout-minutes: 45
env:
# Atmos ships with CGO disabled (see Makefile/test.yml) — without this,
# the runner's default CGO_ENABLED=1 makes govulncheck try to compile
# the cgo-only half of github.com/bearsh/hid (pulled in transitively via
# saml2aws's U2F support), which needs libudev-dev and fails to load.
CGO_ENABLED: "0"
# Sized to RAM + swap. A limit below the call-graph pass's real ~25GB
# need (the previous 12GiB) can't shrink the live heap; it only keeps
# the GC running near-continuously, and each cycle would page the
# swapped heap back in. GOFLAGS=-p=1 (serializing package builds) was
# tried earlier and rejected: it barely reduced peak memory
# (govulncheck's SSA construction parallelizes via goroutines, which
# -p doesn't govern) while nearly tripling run time.
GOMEMLIMIT: "32GiB"
# Controlled scanner-only comparison against the GOGC=100 baseline.
# GC traces report live heap and collection cost on scanner stderr.
ATMOS_VULNCHECK_GOGC: "50"
ATMOS_VULNCHECK_GCTRACE: "1"
# The target also removes exact duplicate stacks from the report: the
# SARIF schema requires them to be unique and the upload rejects the
# report otherwise. See internal/ci/vulncheck.
# Diagnostics run separately on stderr; the scanner and SARIF output
# are unchanged. They help distinguish pressure from a stalled scan.
run: bash .github/scripts/govulncheck-monitor.sh go tool mage ci:vulncheck govulncheck.sarif
- name: Upload SARIF file
# Setup failures produce no report; preserve the original failure without
# adding a misleading missing-file upload error.
if: ${{ always() && hashFiles('govulncheck.sarif') != '' }}
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
sarif_file: govulncheck.sarif
category: govulncheck
# See the ref/sha override comment on the analyze job's upload step
# above: without it, merge_group uploads race the ephemeral
# gh-readonly-queue/... ref being deleted and fail with "ref not found".
ref: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || '' }}
sha: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || '' }}
semgrep:
name: Semgrep scan
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
steps:
- name: Harden Runner
uses: $/.github/actions/harden-runner # nosemgrep: yaml.github-actions.security.github-actions-mutable-action-tag.github-actions-mutable-action-tag
with:
policies: >-
github
docker-hub
semgrep
- name: Checkout code
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
# Run via `docker run` rather than a job-level `container:` so Harden
# Runner (which needs to instrument the runner VM directly) still works —
# job-level containers run every step inside the container instead.
# Pull separately from `docker run` so a transient registry failure can be
# retried. Harden Runner's egress policy allows the IP addresses it saw
# when it resolved each allowed domain, and Docker Hub rotates
# registry-1.docker.io across many IPs with a ~30s TTL. A pull that lands
# on an IP the agent has not recorded is dropped ("connection refused").
# Resolving the names immediately before each attempt lets the agent
# record the current addresses.
- name: Pull Semgrep image
env:
SEMGREP_IMAGE: semgrep/semgrep@sha256:65dcd4408adda7c183a6b4550cb1e9b19f7f627a6fbb7e0559bd466bedc44d7b
run: |
max_attempts=5
for attempt in $(seq 1 "${max_attempts}"); do
getent hosts registry-1.docker.io auth.docker.io production.cloudfront.docker.com >/dev/null || true
if docker pull "${SEMGREP_IMAGE}"; then
exit 0
fi
echo "::warning::docker pull failed (attempt ${attempt}/${max_attempts}); retrying in $((attempt * 5))s"
sleep $((attempt * 5))
done
echo "::error::docker pull of ${SEMGREP_IMAGE} failed after ${max_attempts} attempts"
exit 1
- name: Run Semgrep
run: |
docker run --rm \
-v "${{ github.workspace }}:/src" \
-w /src \
semgrep/semgrep@sha256:65dcd4408adda7c183a6b4550cb1e9b19f7f627a6fbb7e0559bd466bedc44d7b \
semgrep scan --config=p/ci --sarif --output=semgrep.sarif --metrics=off
# Semgrep keeps nosemgrep findings in SARIF with inSource suppressions,
# which GitHub code scanning does not honor. Keep the raw report intact.
- name: Honor inline Semgrep suppressions
id: semgrep-sarif
if: ${{ !cancelled() && hashFiles('semgrep.sarif') != '' }}
uses: $/.github/actions/filter-semgrep-sarif # nosemgrep: yaml.github-actions.security.github-actions-mutable-action-tag.github-actions-mutable-action-tag
with:
input-file: semgrep.sarif
output-file: semgrep-upload.sarif
- name: Upload SARIF to code-scanning
if: ${{ !cancelled() && steps.semgrep-sarif.outcome == 'success' }}
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
sarif_file: semgrep-upload.sarif
category: semgrep
# See the ref/sha override comment on the analyze job's upload step
# above: without it, merge_group uploads race the ephemeral
# gh-readonly-queue/... ref being deleted and fail with "ref not found".
ref: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || '' }}
sha: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || '' }}
lint-golangci:
name: "Lint (golangci)"
runs-on: ubuntu-24.04
env:
# Match the CGO-disabled release build. Otherwise saml2aws's optional
# native HID dependency prevents type checking on hosted Linux runners.
CGO_ENABLED: "0"
# golangci-lint-action supports merge_group with fetch-depth: 0 below,
# using the merge group's base revision to limit findings to new issues.
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
permissions:
# Required: allow read access to the content for analysis.
contents: read
# allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# allow write access to checks to allow the action to annotate code in the PR.
checks: write
# allow write access to security events to allow the action to upload SARIF files.
security-events: write
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
fetch-depth: 0
# golangci-lint-action@v4.0.0+ requires explicit Go setup
# Without this step, the action may fail intermittently with
# "could not load export data" errors due to cache corruption
- name: Set up Go
uses: ./.github/actions/setup-go-cache
with:
go-version-file: go.mod
# Pre-populate module cache to prevent goanalysis_metalinter failures.
# Without this, the linter may fail with "could not load export data" errors.
# See: https://github.com/golangci/golangci-lint/issues/5437
# With retry: GOPROXY no longer falls back to direct fetches (they only
# hit blocked vanity hosts under harden-runner's block mode).
- name: Download modules
uses: ./.github/actions/go-mod-download-retry
# The custom-gcl binary is a full golangci-lint build with the
# lintroller plugin compiled in — several minutes of compile on every
# run without this cache (the mage target's mtime-based staleness check
# can never pass on a fresh checkout). Key on everything that goes into
# the binary: its build manifest, the plugin source, the module graph,
# and the Go version that compiles it.
- name: Cache the custom golangci-lint binary
id: custom-gcl-cache
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ./custom-gcl
key: custom-gcl-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.custom-gcl.yml', 'tools/lintroller/**', 'go.mod', 'go.sum') }}
# Install the golangci-lint v2 CLI tool (not the linters themselves).
# This tool is needed to run `golangci-lint custom` which builds a custom binary
# that includes both standard linters AND our custom module plugins.
# Skipped on a cache hit: it exists only to build custom-gcl.
- name: Install golangci-lint v2 for custom build
if: steps.custom-gcl-cache.outputs.cache-hit != 'true'
run: |
# Pin to commit that fixes "-c advice.detachedHead=false" bug (PR #6206)
# https://github.com/golangci/golangci-lint/pull/6206
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@101ccaca0df22b2e36dd917ed5d0be423baa6298
# Build a custom golangci-lint binary with our lintroller plugin compiled in.
- name: Build custom golangci-lint with lintroller plugin
if: steps.custom-gcl-cache.outputs.cache-hit != 'true'
run: |
set -e
# Ensure lintroller module is ready
cd tools/lintroller && go mod tidy && cd ../..
# Build custom golangci-lint with plugins (staleness-guarded; see magefiles/)
go tool mage lint:customGCL
- name: Put the custom golangci-lint on PATH
run: |
set -e
# Verify the custom binary exists (built above, or cache-restored)
test -x ./custom-gcl || { echo "Error: custom-gcl not found or not executable"; exit 1; }
# Make our custom build the `golangci-lint` the action below invokes
mkdir -p ~/go/bin
cp ./custom-gcl ~/go/bin/golangci-lint
chmod +x ~/go/bin/golangci-lint
golangci-lint --version
# Run the golangci-lint action using our custom binary with plugins.
#
# Key settings:
# - install-mode: none - Tells the action to use the binary already in PATH
# (our custom-gcl that we just installed)
# - only-new-issues: true - Only report issues in changed code
# - SARIF output - For GitHub Advanced Security / CodeQL integration
# - issues-exit-code: 0 - Always exit 0 so we upload SARIF to CodeQL
#
# The action provides:
# - Inline PR annotations for linting issues
# - Caching for faster runs
# - GitHub UI integration
#
# Our custom binary includes lintroller, so violations of:
# - os.MkdirTemp in tests (should use t.TempDir)
# - os.Setenv in tests (should use t.Setenv)
# - t.Setenv in defer blocks (should use os.Setenv)
# will appear in the SARIF output and GitHub Security tab.
- name: Run golangci-lint with lintroller plugin
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
# Match the custom binary, not the bootstrap CLI used to build it.
version: v2.13.2
install-mode: none
# The action's config verification downloads a remote JSON schema and
# can fail transiently. The subsequent lint command still parses and
# validates the configuration, so skip the duplicate network preflight.
verify: false
only-new-issues: true
args: >
--output.sarif.path=golangci-lint.sarif
--issues-exit-code=0
- name: Upload filtered SARIF results
# merge_group's ephemeral gh-readonly-queue/... ref is deleted as soon
# as the queue cycles, which routinely races this upload and fails it
# with "ref not found" if left to auto-detect ref/sha from
# GITHUB_REF/GITHUB_SHA (the doomed ephemeral ref). Point it at the
# queue's real target branch ref (which persists) while still
# uploading results for the actual queued merge commit, same as the
# CodeQL analyze step above -- skipping the upload outright isn't an
# option here either: it would leave the native "CodeQL" code-scanning
# required check without this SARIF's contribution.
if: always()
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
sarif_file: golangci-lint.sarif
ref: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || '' }}
sha: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || '' }}
pr-semver-labels:
name: PR Semver Labels
# Required checks must also report on the merge queue's synthetic commit
# (github.event_name == 'merge_group'), otherwise the merge queue waits
# out its full check-response timeout for a check that will never exist,
# then dequeues the PR -- even when every other check already passed.
# The label check itself only makes sense against a real pull_request
# event (github.event.pull_request doesn't exist for merge_group), and
# by the time a PR reaches the queue its label was already verified on
# pull_request, so merge_group just needs this job to report a pass.
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
runs-on: ubuntu-24.04
permissions:
pull-requests: write
issues: write
steps:
- name: Harden Runner
uses: $/.github/actions/harden-runner # nosemgrep: yaml.github-actions.security.github-actions-mutable-action-tag.github-actions-mutable-action-tag
with:
# Checkout is required for local composite actions
policies: >-
github
github-archives
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
with:
persist-credentials: false
# Remove Dependabot's auto-added semver labels
# Dependabot PRs should only have the 'no-release' label since
# dependency updates don't determine Atmos releases.
- name: Clean up Dependabot labels
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
uses: ./.github/actions/remove-dependabot-semver-labels
# Check for required semver labels
# Every PR must have exactly one: major, minor, patch, or no-release
# pull_request only: merge_group has no github.event.pull_request for
# this action to check labels against.
- uses: mheap/github-action-required-labels@23e10fde7e062233401931a0eece796cd9bf3177 # v5.6.0
if: github.event_name == 'pull_request'
with:
mode: exactly
count: 1
labels: |
major
minor
patch
no-release
add_comment: true
message: |
> [!WARNING]
> This PR is blocked from merging because a required semver label is missing.
> ```
> {{ provided }}
> ```
> You'll need to add one before this PR can be merged.