|
| 1 | +name: Security (OSS-CLI) |
| 2 | +# OSS-CLI security stack — RAN-51 hardening lane. |
| 3 | +# Mirrors the codeiq RAN-46 (B) OSS-CLI stack |
| 4 | +# (Semgrep + osv-scanner + Trivy + Gitleaks + jscpd + sbom-action), |
| 5 | +# adapted for docsiq's Go + React/TS shape. |
| 6 | +# |
| 7 | +# Six independent jobs — fail-fast off so every signal surfaces on a |
| 8 | +# single run. All actions SHA-pinned per Scorecard `Pinned-Dependencies`. |
| 9 | +# Top-level `permissions: read-all` per Scorecard `Token-Permissions`; |
| 10 | +# jobs scope up only when needed (gitleaks needs full git history, |
| 11 | +# the sbom job uploads artifacts). |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main] |
| 15 | + pull_request: |
| 16 | + branches: [main] |
| 17 | + schedule: |
| 18 | + - cron: '21 4 * * 1' # Mondays 04:21 UTC — catch newly-disclosed CVEs |
| 19 | + |
| 20 | +permissions: read-all |
| 21 | + |
| 22 | +jobs: |
| 23 | + osv-scanner: |
| 24 | + name: OSV-Scanner (SCA) |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + env: |
| 29 | + OSV_SCANNER_VERSION: 2.3.5 |
| 30 | + GH_TOKEN: ${{ github.token }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + # Install osv-scanner from the official GitHub release (binary, not |
| 36 | + # the action — google/osv-scanner-action's `action.yml` is composite |
| 37 | + # and fails when invoked as a job step). Using the preinstalled |
| 38 | + # `gh` CLI avoids any external `curl`/`wget`. |
| 39 | + - name: Install osv-scanner |
| 40 | + run: | |
| 41 | + gh release download "v${OSV_SCANNER_VERSION}" \ |
| 42 | + --repo google/osv-scanner \ |
| 43 | + --pattern 'osv-scanner_linux_amd64' \ |
| 44 | + --clobber |
| 45 | + mv osv-scanner_linux_amd64 osv-scanner |
| 46 | + chmod +x osv-scanner |
| 47 | + ./osv-scanner --version |
| 48 | + # Scan the Go module graph and the embedded React UI's npm lockfile. |
| 49 | + # `--recursive` would also find ui/package-lock.json, but being |
| 50 | + # explicit keeps the AC §3 ("Zero High/Critical CVEs") evidence |
| 51 | + # trail clear: Go covered by go.mod, frontend by ui/package-lock.json, |
| 52 | + # cross-ecosystem reactive coverage by Dependabot security updates. |
| 53 | + - name: Run osv-scanner (Go modules) |
| 54 | + run: ./osv-scanner --lockfile=go.mod |
| 55 | + - name: Run osv-scanner (UI npm lockfile) |
| 56 | + run: ./osv-scanner --lockfile=ui/package-lock.json |
| 57 | + |
| 58 | + trivy: |
| 59 | + name: Trivy (filesystem scan) |
| 60 | + runs-on: ubuntu-latest |
| 61 | + permissions: |
| 62 | + contents: read |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 65 | + with: |
| 66 | + persist-credentials: false |
| 67 | + - uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 |
| 68 | + with: |
| 69 | + scan-type: fs |
| 70 | + scan-ref: . |
| 71 | + severity: HIGH,CRITICAL |
| 72 | + exit-code: '1' |
| 73 | + ignore-unfixed: true |
| 74 | + |
| 75 | + semgrep: |
| 76 | + name: Semgrep (SAST) |
| 77 | + runs-on: ubuntu-latest |
| 78 | + permissions: |
| 79 | + contents: read |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 82 | + with: |
| 83 | + persist-credentials: false |
| 84 | + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 85 | + with: |
| 86 | + python-version: '3.12' |
| 87 | + - name: Install semgrep |
| 88 | + run: python -m pip install --quiet --upgrade pip semgrep |
| 89 | + - name: Run semgrep (security-audit + owasp-top-ten + golang + typescript) |
| 90 | + # `p/golang` covers Go-specific patterns (unsafe.Pointer, errcheck |
| 91 | + # families, taint flows). `p/typescript` covers the embedded React |
| 92 | + # UI under ui/. `p/security-audit` and `p/owasp-top-ten` are |
| 93 | + # language-agnostic. `--metrics off` keeps runs offline-friendly. |
| 94 | + run: | |
| 95 | + semgrep scan \ |
| 96 | + --error \ |
| 97 | + --config p/security-audit \ |
| 98 | + --config p/owasp-top-ten \ |
| 99 | + --config p/golang \ |
| 100 | + --config p/typescript \ |
| 101 | + --severity ERROR \ |
| 102 | + --metrics off |
| 103 | +
|
| 104 | + gitleaks: |
| 105 | + name: Gitleaks (secret scan) |
| 106 | + runs-on: ubuntu-latest |
| 107 | + permissions: |
| 108 | + contents: read |
| 109 | + env: |
| 110 | + GITLEAKS_VERSION: 8.30.1 |
| 111 | + GH_TOKEN: ${{ github.token }} |
| 112 | + steps: |
| 113 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 114 | + with: |
| 115 | + fetch-depth: 0 |
| 116 | + persist-credentials: false |
| 117 | + # The official `gitleaks/gitleaks-action` requires a paid licence for |
| 118 | + # GitHub organisations. The underlying CLI is MIT-licensed; install |
| 119 | + # it directly from the upstream release using the preinstalled `gh`. |
| 120 | + - name: Install gitleaks |
| 121 | + run: | |
| 122 | + gh release download "v${GITLEAKS_VERSION}" \ |
| 123 | + --repo gitleaks/gitleaks \ |
| 124 | + --pattern "gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" \ |
| 125 | + --output gitleaks.tar.gz |
| 126 | + tar -xzf gitleaks.tar.gz gitleaks |
| 127 | + chmod +x gitleaks |
| 128 | + - name: Run gitleaks (full git history) |
| 129 | + run: ./gitleaks detect --source . --redact --no-banner --exit-code 1 |
| 130 | + |
| 131 | + jscpd: |
| 132 | + name: jscpd (duplication < 3% on production code) |
| 133 | + runs-on: ubuntu-latest |
| 134 | + permissions: |
| 135 | + contents: read |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 138 | + with: |
| 139 | + persist-credentials: false |
| 140 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 141 | + with: |
| 142 | + node-version: '20' |
| 143 | + - name: Run jscpd |
| 144 | + # Scope to production code only: cmd/ + internal/ (Go) and ui/src/ |
| 145 | + # (React/TS). Tests share fixture/assertion shape by design — that |
| 146 | + # parallelism catches contract regressions and is not a refactor |
| 147 | + # target. `--min-tokens 200` matches a meaningful method body, not |
| 148 | + # language scaffolding (package + imports + struct headers). |
| 149 | + run: | |
| 150 | + npx --yes jscpd@4 \ |
| 151 | + --threshold 3 \ |
| 152 | + --min-tokens 200 \ |
| 153 | + --reporters consoleFull \ |
| 154 | + --format "go,javascript,typescript" \ |
| 155 | + --ignore "**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,**/testdata/**,**/*_test.go,**/*.test.ts,**/*.spec.ts,**/e2e/**,**/.next/**,**/vendor/**" \ |
| 156 | + cmd internal ui/src |
| 157 | +
|
| 158 | + sbom: |
| 159 | + name: SBOM (SPDX + CycloneDX) |
| 160 | + runs-on: ubuntu-latest |
| 161 | + permissions: |
| 162 | + contents: read |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 165 | + with: |
| 166 | + persist-credentials: false |
| 167 | + - name: Generate SPDX SBOM |
| 168 | + uses: anchore/sbom-action@fc46e51fd3cb168ffb36c6d1915723c47db58abb # v0.17.7 |
| 169 | + with: |
| 170 | + format: spdx-json |
| 171 | + output-file: sbom.spdx.json |
| 172 | + upload-artifact: false |
| 173 | + - name: Generate CycloneDX SBOM |
| 174 | + uses: anchore/sbom-action@fc46e51fd3cb168ffb36c6d1915723c47db58abb # v0.17.7 |
| 175 | + with: |
| 176 | + format: cyclonedx-json |
| 177 | + output-file: sbom.cdx.json |
| 178 | + upload-artifact: false |
| 179 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v4.6.2 |
| 180 | + with: |
| 181 | + name: sbom |
| 182 | + path: | |
| 183 | + sbom.spdx.json |
| 184 | + sbom.cdx.json |
| 185 | + retention-days: 90 |
0 commit comments