|
| 1 | +name: SDK supply chain |
| 2 | + |
| 3 | +# Premortem F4 follow-on: even with caret-pinning fixed and a lockfile, npm |
| 4 | +# publishes can be hijacked by transitive compromise or registry spoofing. |
| 5 | +# This workflow: |
| 6 | +# - asserts that runtime deps in package.json are exact-version (no `^`/`~`), |
| 7 | +# - performs a `npm pack --provenance` dry-run so each PR proves the build |
| 8 | +# can produce a provenance-signed tarball, |
| 9 | +# - runs `npm ci --ignore-scripts` so postinstall scripts can't smuggle |
| 10 | +# side-effects into CI worker images. |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: [develop, main] |
| 14 | + pull_request: |
| 15 | + branches: [develop, main] |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + id-token: write # required for npm provenance |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: sdk-supplychain-${{ github.ref }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + enforce-pin: |
| 28 | + name: Runtime deps must be exact-version |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + - name: Reject `^` / `~` in runtime dependencies |
| 33 | + run: | |
| 34 | + # Premortem F4: caret-pinning lets transitively-compromised minors |
| 35 | + # land without review. This grep-fails fast on any caret/tilde in |
| 36 | + # the runtime block — devDeps may still float. |
| 37 | + node -e " |
| 38 | + const pkg = require('./package.json'); |
| 39 | + const bad = Object.entries(pkg.dependencies || {}).filter(([_, v]) => /^[\^~]/.test(v)); |
| 40 | + if (bad.length) { |
| 41 | + console.error('Floating runtime deps found (must be exact-version):'); |
| 42 | + for (const [n, v] of bad) console.error(' ' + n + ': ' + v); |
| 43 | + process.exit(1); |
| 44 | + } |
| 45 | + console.log('All runtime deps are exact-version.'); |
| 46 | + " |
| 47 | +
|
| 48 | + provenance-pack: |
| 49 | + name: npm pack --provenance dry run |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + - uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: '22' |
| 56 | + cache: 'npm' |
| 57 | + registry-url: 'https://npm.pkg.github.com' |
| 58 | + - name: Install with locked, scriptless deps |
| 59 | + run: npm ci --ignore-scripts |
| 60 | + - name: Build dist/ |
| 61 | + run: npm run build |
| 62 | + - name: Pack with provenance |
| 63 | + # `--dry-run` so we don't push to the registry from PRs; the publish |
| 64 | + # workflow (out-of-scope here) reuses the same flags without --dry-run. |
| 65 | + run: npm pack --provenance --dry-run |
| 66 | + env: |
| 67 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + |
| 69 | + - name: Assert tarball ships no source / secrets |
| 70 | + # SEC-DEP-006: the published tarball must carry only built `dist/` |
| 71 | + # (JS/CJS + `.d.ts` types). A stray `.ts` SOURCE file or a `.env` would |
| 72 | + # leak internals/secrets to every consumer. We inspect the dry-run file |
| 73 | + # list and fail the job on any violation. |
| 74 | + run: | |
| 75 | + npm pack --dry-run --json > /tmp/pack.json |
| 76 | + node -e " |
| 77 | + const arr = JSON.parse(require('fs').readFileSync('/tmp/pack.json', 'utf8')); |
| 78 | + const files = arr.flatMap((p) => (p.files || []).map((f) => f.path)); |
| 79 | + const tsSource = files.filter((f) => f.endsWith('.ts') && !f.endsWith('.d.ts')); |
| 80 | + const envFiles = files.filter((f) => /(^|\/)\.env(\.|$)/.test(f)); |
| 81 | + const bad = [...tsSource, ...envFiles]; |
| 82 | + if (bad.length) { |
| 83 | + console.error('Forbidden files in publish tarball (no .ts source / .env allowed):'); |
| 84 | + for (const f of bad) console.error(' ' + f); |
| 85 | + process.exit(1); |
| 86 | + } |
| 87 | + console.log('Tarball clean: ' + files.length + ' files, no .ts source or .env.'); |
| 88 | + " |
0 commit comments