|
| 1 | +name: Security release gate |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'verification/api-explorer-*' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: api-explorer-security-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-test-scan: |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + timeout-minutes: 45 |
| 20 | + env: |
| 21 | + TRIVY_IMAGE: aquasec/trivy:0.73.0@sha256:7cced7cae583819fc7806d4cbc0dbbc7cad18b99f7d3e235192e6da8c091045c |
| 22 | + steps: |
| 23 | + - name: Check out candidate |
| 24 | + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.0.2 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + persist-credentials: false |
| 28 | + |
| 29 | + - name: Install Node.js |
| 30 | + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
| 31 | + with: |
| 32 | + node-version: '24.15.0' |
| 33 | + cache: npm |
| 34 | + |
| 35 | + - name: Verify source identity and lock files |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + set -euo pipefail |
| 39 | + test -z "$(git status --porcelain)" |
| 40 | + test "$(git rev-list --count 80270e0af984025b14afc61c0d0b0a4f08d968bf..HEAD)" -eq 1 |
| 41 | + mkdir -p evidence |
| 42 | + git rev-parse HEAD > evidence/source-revision.txt |
| 43 | + sha256sum package.json package-lock.json .github/workflows/*.yml > evidence/source-locks.sha256 |
| 44 | + node --version | tee evidence/node-version.txt |
| 45 | + npm --version | tee evidence/npm-version.txt |
| 46 | +
|
| 47 | + - name: Install, test, audit, and build twice |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | + npm ci --ignore-scripts --omit=optional --no-audit --no-fund |
| 52 | + npm run test:security |
| 53 | + npm audit --omit=dev --json > evidence/npm-audit-runtime.json |
| 54 | + npm audit --json > evidence/npm-audit-all.json |
| 55 | + npm run ci |
| 56 | + version=$(node -p "require('./package.json').version") |
| 57 | + artifact="dist/${version}.tar.gz" |
| 58 | + cp "$artifact" /tmp/api-explorer-first.tar.gz |
| 59 | + rm -rf dist tmp |
| 60 | + npm run build |
| 61 | + cmp /tmp/api-explorer-first.tar.gz "$artifact" |
| 62 | + sha256sum "$artifact" > evidence/product-artifact.sha256 |
| 63 | + tar -tzf "$artifact" > evidence/product-members.txt |
| 64 | +
|
| 65 | + - name: Generate package SBOM |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + npm exec --yes --package='@cyclonedx/cyclonedx-npm@6.0.1' -- cyclonedx-npm \ |
| 70 | + --output-format JSON \ |
| 71 | + --spec-version 1.6 \ |
| 72 | + --output-file evidence/api-explorer.cdx.json |
| 73 | +
|
| 74 | + - name: Scan immutable source and product |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + set -euo pipefail |
| 78 | + docker pull "$TRIVY_IMAGE" |
| 79 | + cache="$RUNNER_TEMP/trivy-cache" |
| 80 | + source_tree="$(mktemp -d)" |
| 81 | + product_tree="$(mktemp -d)" |
| 82 | + trap 'rm -rf "$source_tree" "$product_tree"' EXIT |
| 83 | + mkdir -p "$cache" "$product_tree" |
| 84 | + git archive --format=tar HEAD | tar -xf - -C "$source_tree" |
| 85 | + version=$(node -p "require('./package.json').version") |
| 86 | + tar -xzf "dist/${version}.tar.gz" -C "$product_tree" |
| 87 | + docker run --rm -v "$cache:/root/.cache/trivy" "$TRIVY_IMAGE" image --download-db-only |
| 88 | + docker run --rm -v "$source_tree:/scan:ro" -v "$PWD/evidence:/evidence" -v "$cache:/root/.cache/trivy" "$TRIVY_IMAGE" fs \ |
| 89 | + --skip-db-update --offline-scan --scanners vuln,secret --format json --output /evidence/source-security.json /scan |
| 90 | + docker run --rm -v "$product_tree:/scan:ro" -v "$PWD/evidence:/evidence" -v "$cache:/root/.cache/trivy" "$TRIVY_IMAGE" rootfs \ |
| 91 | + --skip-db-update --offline-scan --scanners vuln,secret --format json --output /evidence/product-security.json /scan |
| 92 | +
|
| 93 | + - name: Enforce candidate security |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | + : > evidence/security-summary.txt |
| 98 | + for scope in source product; do |
| 99 | + report="evidence/${scope}-security.json" |
| 100 | + secrets=$(jq '[.Results[]?.Secrets[]?] | length' "$report") |
| 101 | + critical=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL")] | length' "$report") |
| 102 | + high=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH")] | length' "$report") |
| 103 | + printf '%s_secrets=%s\n%s_critical=%s\n%s_high=%s\n' "$scope" "$secrets" "$scope" "$critical" "$scope" "$high" | tee -a evidence/security-summary.txt |
| 104 | + test "$secrets" -eq 0 |
| 105 | + test "$critical" -eq 0 |
| 106 | + test "$high" -eq 0 |
| 107 | + done |
| 108 | + jq -e '.metadata.vulnerabilities.critical == 0 and .metadata.vulnerabilities.high == 0' evidence/npm-audit-runtime.json >/dev/null |
| 109 | + jq -e '.metadata.vulnerabilities.critical == 0 and .metadata.vulnerabilities.high == 0' evidence/npm-audit-all.json >/dev/null |
| 110 | + jq -e '.bomFormat == "CycloneDX" and .specVersion == "1.6" and (.components | length) > 0' evidence/api-explorer.cdx.json >/dev/null |
| 111 | +
|
| 112 | + - name: Upload reviewed evidence |
| 113 | + if: always() |
| 114 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 115 | + with: |
| 116 | + name: api-explorer-security-${{ github.sha }} |
| 117 | + path: evidence/ |
| 118 | + if-no-files-found: error |
| 119 | + retention-days: 30 |
| 120 | + compression-level: 9 |
| 121 | + |
| 122 | + - name: Clean runner resources |
| 123 | + if: always() |
| 124 | + shell: bash |
| 125 | + run: | |
| 126 | + set +e |
| 127 | + docker image rm -f "$TRIVY_IMAGE" 2>/dev/null |
| 128 | + docker builder prune --all --force >/dev/null 2>&1 |
| 129 | + rm -rf node_modules dist tmp |
0 commit comments