diff --git a/.github/actions/trivy-scan/action.yml b/.github/actions/trivy-scan/action.yml new file mode 100644 index 0000000000..9bb4a20613 --- /dev/null +++ b/.github/actions/trivy-scan/action.yml @@ -0,0 +1,45 @@ +name: Trivy image scan +description: + Report fixable HIGH and CRITICAL CVEs in a locally loaded image to the job + summary and GitHub code scanning. Report-only; never fails on findings. +inputs: + image: + description: Image reference already loaded into the local Docker daemon + required: true + category: + description: Code scanning category, unique per image + required: true +runs: + using: composite + steps: + # Pinned by SHA: trivy-action's tags were rewritten by an attacker in 2026. + - name: Scan image + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 + with: + image-ref: ${{ inputs.image }} + scanners: vuln + severity: HIGH,CRITICAL + ignore-unfixed: true + format: json + output: trivy.json + exit-code: '0' + version: v0.76.2 + - name: Write summary and SARIF + shell: bash + env: + CATEGORY: ${{ inputs.category }} + run: | + { + echo "### Trivy: ${CATEGORY} (fixable high and critical)" + echo '```' + trivy convert --format table trivy.json + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + trivy convert --format sarif --output trivy.sarif trivy.json + # PR uploads would add a code scanning check that fails on new alerts. + - name: Upload to code scanning + if: github.event_name != 'pull_request' + uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + with: + sarif_file: trivy.sarif + category: trivy-${{ inputs.category }} diff --git a/.github/workflows/dependency-scan.yml b/.github/workflows/dependency-scan.yml new file mode 100644 index 0000000000..3b971db4f2 --- /dev/null +++ b/.github/workflows/dependency-scan.yml @@ -0,0 +1,120 @@ +name: Dependency Scan +# Report-only: findings go to the job summary and code scanning and never fail +# the run. The daily schedule catches advisories published against unchanged +# dependencies. Image scanning lives in docker-build.yml. +on: + pull_request: + branches: [main] + paths: + - '**/package.json' + - yarn.lock + - .yarnrc.yml + - packages/otel-collector/go.mod + - packages/otel-collector/go.sum + - packages/otel-collector/cmd/** + - docker/otel-collector/Dockerfile + - .github/workflows/dependency-scan.yml + push: + branches: [main] + schedule: + - cron: '0 9 * * *' + workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +permissions: + contents: read +jobs: + yarn-audit: + name: yarn npm audit + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Setup node + uses: actions/setup-node@v6 + with: + node-version-file: '.nvmrc' + # Reads yarn.lock directly, so no install is needed. Dev tooling is skipped, + # except in the CLI, which bundles its devDependencies into the release. + - name: Audit dependencies + run: | + status=0 + { + echo '### yarn npm audit (high and critical)' + echo '#### Production dependencies, all workspaces' + echo '```' + yarn npm audit --all --recursive --environment production \ + --severity high 2>&1 || status=$? + echo '```' + echo '#### @hyperdx/cli, including bundled devDependencies' + echo '```' + yarn workspace @hyperdx/cli npm audit --recursive \ + --severity high 2>&1 || status=$? + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + if [ "$status" -ne 0 ]; then + echo "::warning title=yarn npm audit::Advisories found or audit failed, see the job summary" + fi + + govulncheck: + name: govulncheck + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + contents: read + security-events: write + defaults: + run: + working-directory: packages/otel-collector + steps: + - name: Checkout + uses: actions/checkout@v6 + # govulncheck reports stdlib advisories for the Go on PATH, so match the + # release the shipped binary is built with rather than go.mod's minimum. + - name: Read Go version from the Dockerfile + id: go-version + working-directory: . + run: | + version=$(sed -nE 's/^FROM golang:([0-9.]+)-.* AS migrate-builder$/\1/p' \ + docker/otel-collector/Dockerfile) + if [ -z "$version" ]; then + echo "::error::No golang version found on the migrate-builder FROM line in docker/otel-collector/Dockerfile" + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ steps.go-version.outputs.version }} + cache-dependency-path: packages/otel-collector/go.sum + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@v1.10.0 + # Text mode exits 3 on findings; SARIF mode always exits 0. The SARIF + # paths are relative to the module, so prefix them for code scanning. + - name: Scan the migrate tool + continue-on-error: true + run: | + status=0 + govulncheck ./... > report.txt 2>&1 || status=$? + { + echo '### govulncheck (packages/otel-collector)' + echo '```' + cat report.txt + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + if [ "$status" -ne 0 ]; then + echo "::warning title=govulncheck::Vulnerabilities found or scan failed, see the job summary" + fi + govulncheck -format sarif ./... > raw.sarif + jq '(.. | objects | select(.uriBaseId? == "%SRCROOT%") | .uri) |= "packages/otel-collector/" + .' \ + raw.sarif > govulncheck.sarif + # PR uploads would add a code scanning check that fails on new alerts. + - name: Upload to code scanning + if: github.event_name != 'pull_request' + continue-on-error: true + uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + with: + sarif_file: packages/otel-collector/govulncheck.sarif + category: govulncheck diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 513261b0d1..536b1d52e7 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -48,17 +48,21 @@ jobs: name: Build OTel Collector Image runs-on: ubuntu-24.04 timeout-minutes: 25 + permissions: + contents: read + security-events: write steps: - name: Checkout uses: actions/checkout@v6 - name: Get changed files id: changed-files if: github.event_name == 'pull_request' - uses: tj-actions/changed-files@v47.0.6 + uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 with: files: | docker/otel-collector/** packages/otel-collector/** + .github/actions/trivy-scan/** - name: Setup Docker Buildx if: github.event_name != 'pull_request' || @@ -75,10 +79,22 @@ jobs: target: prod platforms: linux/amd64 push: false + load: true + tags: clickstack-otel-collector:ci cache-from: | type=gha,scope=otel-collector-nightly-amd64 type=gha,scope=docker-build-pr-otel-collector cache-to: type=gha,mode=max,scope=docker-build-pr-otel-collector + - name: Scan image + if: + github.event_name != 'pull_request' || + steps.changed-files.outputs.any_changed == 'true' + continue-on-error: true + timeout-minutes: 10 + uses: ./.github/actions/trivy-scan + with: + image: clickstack-otel-collector:ci + category: otel-collector # App/prod image (API + App + common-utils Node build) — docker/hyperdx target prod. # This is the image the nightly css.d.ts failure surfaced in; the same builder @@ -87,13 +103,16 @@ jobs: name: Build App Image runs-on: ubuntu-24.04 timeout-minutes: 25 + permissions: + contents: read + security-events: write steps: - name: Checkout uses: actions/checkout@v6 - name: Get changed files id: changed-files if: github.event_name == 'pull_request' - uses: tj-actions/changed-files@v47.0.6 + uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 with: files: | packages/api/** @@ -124,6 +143,8 @@ jobs: target: prod platforms: linux/amd64 push: false + load: true + tags: clickstack:ci build-contexts: | hyperdx=./docker/hyperdx api=./packages/api @@ -134,6 +155,16 @@ jobs: type=gha,scope=app-nightly-amd64 type=gha,scope=docker-build-pr-app cache-to: type=gha,mode=max,scope=docker-build-pr-app + - name: Scan image + if: + github.event_name != 'pull_request' || + steps.changed-files.outputs.any_changed == 'true' + continue-on-error: true + timeout-minutes: 10 + uses: ./.github/actions/trivy-scan + with: + image: clickstack:ci + category: app # All-in-one image (adds ClickHouse, MongoDB, OTel Collector to the app build) # — docker/hyperdx targets all-in-one-auth AND all-in-one-noauth (the Local @@ -155,13 +186,16 @@ jobs: name: Build All-in-One Image runs-on: ubuntu-24.04 timeout-minutes: 40 + permissions: + contents: read + security-events: write steps: - name: Checkout uses: actions/checkout@v6 - name: Get changed files id: changed-files if: github.event_name == 'pull_request' - uses: tj-actions/changed-files@v47.0.6 + uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 with: files: | packages/otel-collector/** @@ -232,3 +266,13 @@ jobs: steps.changed-files.outputs.any_changed == 'true' timeout-minutes: 10 run: scripts/ci/smoke-all-in-one.sh hyperdx-aio-smoke:pr + - name: Scan image + if: + github.event_name != 'pull_request' || + steps.changed-files.outputs.any_changed == 'true' + continue-on-error: true + timeout-minutes: 10 + uses: ./.github/actions/trivy-scan + with: + image: hyperdx-aio-smoke:pr + category: all-in-one