Skip to content

Commit ef88a9d

Browse files
ci: add report-only Trivy, govulncheck and yarn npm audit scans (#3735)
## Summary CI now reports known vulnerabilities in our Docker images, the collector's Go code and our npm dependencies, using free tools only. Findings appear in each run's job summary, and runs on main and the daily schedule also send them to the Security tab. Nothing fails a build on findings yet, because main already has some to work through. - Trivy reports fixable HIGH and CRITICAL CVEs in the collector, app and all-in-one images whenever `docker-build.yml` builds them. - `yarn npm audit` covers production dependencies in every workspace, plus all of `@hyperdx/cli`, which bundles its devDependencies into the release. - govulncheck reports only the vulnerabilities the migrate tool's code actually reaches. It checks against the Go release the Dockerfile builds with, not go.mod's minimum version. - The dependency scans run on PRs that touch dependency files, on every push to main, and daily, so new advisories against dependencies that haven't changed still show up. - No breaking changes. This only adds CI steps, none of which can fail a build on findings. ### Key decisions - Report-only for now. The baseline on main is 6 high npm advisories in production deps, 2 reachable Go vulnerabilities in the migrate tool, and HIGH findings in the collector and all-in-one images. The app image is clean. Gating today would turn every PR red. - PR runs write to the job summary but don't upload SARIF. An upload adds a code scanning check that fails on any alert missing from main's last analysis, so a Trivy DB refresh alone could turn an unrelated PR red. - The all-in-one scan doesn't use `.vex/openssl-mongodb.vex.json`. Its statements name the Docker Scout product, which Trivy can't match on a locally built image, so it suppressed nothing. - `tj-actions/changed-files` in `docker-build.yml` is now pinned by SHA, because those jobs now hold `security-events: write`. The new trivy-action and upload-sarif steps are pinned the same way. ### How to reproduce **On this branch:** 1. Open the "Build OTel Collector Image" job on this PR (the scan action is in its path filter) and check the job summary for the Trivy table. 2. Open the "Dependency Scan" workflow run and check its summary for both audits and the govulncheck report. <details> <summary>Implementation detail</summary> - The Trivy steps live in `.github/actions/trivy-scan` and run with `continue-on-error` and a 10 minute timeout, so a Trivy DB outage can't fail or stall an image build. - `load: true` is now set on the collector and app builds so Trivy can read the image from the local daemon. - govulncheck covers `cmd/migrate` only. Trivy covers the OCB-built collector binary by matching the Go modules embedded in it. - I checked each command locally against main and the `2-nightly` images, and ran actionlint and zizmor on the workflows. </details>
1 parent cae0d09 commit ef88a9d

3 files changed

Lines changed: 212 additions & 3 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Trivy image scan
2+
description:
3+
Report fixable HIGH and CRITICAL CVEs in a locally loaded image to the job
4+
summary and GitHub code scanning. Report-only; never fails on findings.
5+
inputs:
6+
image:
7+
description: Image reference already loaded into the local Docker daemon
8+
required: true
9+
category:
10+
description: Code scanning category, unique per image
11+
required: true
12+
runs:
13+
using: composite
14+
steps:
15+
# Pinned by SHA: trivy-action's tags were rewritten by an attacker in 2026.
16+
- name: Scan image
17+
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
18+
with:
19+
image-ref: ${{ inputs.image }}
20+
scanners: vuln
21+
severity: HIGH,CRITICAL
22+
ignore-unfixed: true
23+
format: json
24+
output: trivy.json
25+
exit-code: '0'
26+
version: v0.76.2
27+
- name: Write summary and SARIF
28+
shell: bash
29+
env:
30+
CATEGORY: ${{ inputs.category }}
31+
run: |
32+
{
33+
echo "### Trivy: ${CATEGORY} (fixable high and critical)"
34+
echo '```'
35+
trivy convert --format table trivy.json
36+
echo '```'
37+
} >> "$GITHUB_STEP_SUMMARY"
38+
trivy convert --format sarif --output trivy.sarif trivy.json
39+
# PR uploads would add a code scanning check that fails on new alerts.
40+
- name: Upload to code scanning
41+
if: github.event_name != 'pull_request'
42+
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
43+
with:
44+
sarif_file: trivy.sarif
45+
category: trivy-${{ inputs.category }}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Dependency Scan
2+
# Report-only: findings go to the job summary and code scanning and never fail
3+
# the run. The daily schedule catches advisories published against unchanged
4+
# dependencies. Image scanning lives in docker-build.yml.
5+
on:
6+
pull_request:
7+
branches: [main]
8+
paths:
9+
- '**/package.json'
10+
- yarn.lock
11+
- .yarnrc.yml
12+
- packages/otel-collector/go.mod
13+
- packages/otel-collector/go.sum
14+
- packages/otel-collector/cmd/**
15+
- docker/otel-collector/Dockerfile
16+
- .github/workflows/dependency-scan.yml
17+
push:
18+
branches: [main]
19+
schedule:
20+
- cron: '0 9 * * *'
21+
workflow_dispatch:
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
permissions:
26+
contents: read
27+
jobs:
28+
yarn-audit:
29+
name: yarn npm audit
30+
runs-on: ubuntu-24.04
31+
timeout-minutes: 5
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v6
35+
- name: Setup node
36+
uses: actions/setup-node@v6
37+
with:
38+
node-version-file: '.nvmrc'
39+
# Reads yarn.lock directly, so no install is needed. Dev tooling is skipped,
40+
# except in the CLI, which bundles its devDependencies into the release.
41+
- name: Audit dependencies
42+
run: |
43+
status=0
44+
{
45+
echo '### yarn npm audit (high and critical)'
46+
echo '#### Production dependencies, all workspaces'
47+
echo '```'
48+
yarn npm audit --all --recursive --environment production \
49+
--severity high 2>&1 || status=$?
50+
echo '```'
51+
echo '#### @hyperdx/cli, including bundled devDependencies'
52+
echo '```'
53+
yarn workspace @hyperdx/cli npm audit --recursive \
54+
--severity high 2>&1 || status=$?
55+
echo '```'
56+
} >> "$GITHUB_STEP_SUMMARY"
57+
if [ "$status" -ne 0 ]; then
58+
echo "::warning title=yarn npm audit::Advisories found or audit failed, see the job summary"
59+
fi
60+
61+
govulncheck:
62+
name: govulncheck
63+
runs-on: ubuntu-24.04
64+
timeout-minutes: 10
65+
permissions:
66+
contents: read
67+
security-events: write
68+
defaults:
69+
run:
70+
working-directory: packages/otel-collector
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v6
74+
# govulncheck reports stdlib advisories for the Go on PATH, so match the
75+
# release the shipped binary is built with rather than go.mod's minimum.
76+
- name: Read Go version from the Dockerfile
77+
id: go-version
78+
working-directory: .
79+
run: |
80+
version=$(sed -nE 's/^FROM golang:([0-9.]+)-.* AS migrate-builder$/\1/p' \
81+
docker/otel-collector/Dockerfile)
82+
if [ -z "$version" ]; then
83+
echo "::error::No golang version found on the migrate-builder FROM line in docker/otel-collector/Dockerfile"
84+
exit 1
85+
fi
86+
echo "version=$version" >> "$GITHUB_OUTPUT"
87+
- name: Setup Go
88+
uses: actions/setup-go@v5
89+
with:
90+
go-version: ${{ steps.go-version.outputs.version }}
91+
cache-dependency-path: packages/otel-collector/go.sum
92+
- name: Install govulncheck
93+
run: go install golang.org/x/vuln/cmd/govulncheck@v1.10.0
94+
# Text mode exits 3 on findings; SARIF mode always exits 0. The SARIF
95+
# paths are relative to the module, so prefix them for code scanning.
96+
- name: Scan the migrate tool
97+
continue-on-error: true
98+
run: |
99+
status=0
100+
govulncheck ./... > report.txt 2>&1 || status=$?
101+
{
102+
echo '### govulncheck (packages/otel-collector)'
103+
echo '```'
104+
cat report.txt
105+
echo '```'
106+
} >> "$GITHUB_STEP_SUMMARY"
107+
if [ "$status" -ne 0 ]; then
108+
echo "::warning title=govulncheck::Vulnerabilities found or scan failed, see the job summary"
109+
fi
110+
govulncheck -format sarif ./... > raw.sarif
111+
jq '(.. | objects | select(.uriBaseId? == "%SRCROOT%") | .uri) |= "packages/otel-collector/" + .' \
112+
raw.sarif > govulncheck.sarif
113+
# PR uploads would add a code scanning check that fails on new alerts.
114+
- name: Upload to code scanning
115+
if: github.event_name != 'pull_request'
116+
continue-on-error: true
117+
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
118+
with:
119+
sarif_file: packages/otel-collector/govulncheck.sarif
120+
category: govulncheck

‎.github/workflows/docker-build.yml‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,21 @@ jobs:
4848
name: Build OTel Collector Image
4949
runs-on: ubuntu-24.04
5050
timeout-minutes: 25
51+
permissions:
52+
contents: read
53+
security-events: write
5154
steps:
5255
- name: Checkout
5356
uses: actions/checkout@v6
5457
- name: Get changed files
5558
id: changed-files
5659
if: github.event_name == 'pull_request'
57-
uses: tj-actions/changed-files@v47.0.6
60+
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
5861
with:
5962
files: |
6063
docker/otel-collector/**
6164
packages/otel-collector/**
65+
.github/actions/trivy-scan/**
6266
- name: Setup Docker Buildx
6367
if:
6468
github.event_name != 'pull_request' ||
@@ -75,10 +79,22 @@ jobs:
7579
target: prod
7680
platforms: linux/amd64
7781
push: false
82+
load: true
83+
tags: clickstack-otel-collector:ci
7884
cache-from: |
7985
type=gha,scope=otel-collector-nightly-amd64
8086
type=gha,scope=docker-build-pr-otel-collector
8187
cache-to: type=gha,mode=max,scope=docker-build-pr-otel-collector
88+
- name: Scan image
89+
if:
90+
github.event_name != 'pull_request' ||
91+
steps.changed-files.outputs.any_changed == 'true'
92+
continue-on-error: true
93+
timeout-minutes: 10
94+
uses: ./.github/actions/trivy-scan
95+
with:
96+
image: clickstack-otel-collector:ci
97+
category: otel-collector
8298

8399
# App/prod image (API + App + common-utils Node build) — docker/hyperdx target prod.
84100
# This is the image the nightly css.d.ts failure surfaced in; the same builder
@@ -87,13 +103,16 @@ jobs:
87103
name: Build App Image
88104
runs-on: ubuntu-24.04
89105
timeout-minutes: 25
106+
permissions:
107+
contents: read
108+
security-events: write
90109
steps:
91110
- name: Checkout
92111
uses: actions/checkout@v6
93112
- name: Get changed files
94113
id: changed-files
95114
if: github.event_name == 'pull_request'
96-
uses: tj-actions/changed-files@v47.0.6
115+
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
97116
with:
98117
files: |
99118
packages/api/**
@@ -123,6 +142,8 @@ jobs:
123142
target: prod
124143
platforms: linux/amd64
125144
push: false
145+
load: true
146+
tags: clickstack:ci
126147
build-contexts: |
127148
hyperdx=./docker/hyperdx
128149
api=./packages/api
@@ -133,6 +154,16 @@ jobs:
133154
type=gha,scope=app-nightly-amd64
134155
type=gha,scope=docker-build-pr-app
135156
cache-to: type=gha,mode=max,scope=docker-build-pr-app
157+
- name: Scan image
158+
if:
159+
github.event_name != 'pull_request' ||
160+
steps.changed-files.outputs.any_changed == 'true'
161+
continue-on-error: true
162+
timeout-minutes: 10
163+
uses: ./.github/actions/trivy-scan
164+
with:
165+
image: clickstack:ci
166+
category: app
136167

137168
# All-in-one image (adds ClickHouse, MongoDB, OTel Collector to the app build)
138169
# — docker/hyperdx targets all-in-one-auth AND all-in-one-noauth (the Local
@@ -154,13 +185,16 @@ jobs:
154185
name: Build All-in-One Image
155186
runs-on: ubuntu-24.04
156187
timeout-minutes: 40
188+
permissions:
189+
contents: read
190+
security-events: write
157191
steps:
158192
- name: Checkout
159193
uses: actions/checkout@v6
160194
- name: Get changed files
161195
id: changed-files
162196
if: github.event_name == 'pull_request'
163-
uses: tj-actions/changed-files@v47.0.6
197+
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
164198
with:
165199
files: |
166200
packages/otel-collector/**
@@ -231,3 +265,13 @@ jobs:
231265
steps.changed-files.outputs.any_changed == 'true'
232266
timeout-minutes: 10
233267
run: scripts/ci/smoke-all-in-one.sh hyperdx-aio-smoke:pr
268+
- name: Scan image
269+
if:
270+
github.event_name != 'pull_request' ||
271+
steps.changed-files.outputs.any_changed == 'true'
272+
continue-on-error: true
273+
timeout-minutes: 10
274+
uses: ./.github/actions/trivy-scan
275+
with:
276+
image: hyperdx-aio-smoke:pr
277+
category: all-in-one

0 commit comments

Comments
 (0)