diff --git a/.github/workflows/hypatia-scan.yml b/.github/workflows/hypatia-scan.yml index 376f720c..860a2b79 100644 --- a/.github/workflows/hypatia-scan.yml +++ b/.github/workflows/hypatia-scan.yml @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-License-Identifier: PMPL-1.0-or-later # Hypatia Neurosymbolic CI/CD Security Scan name: Hypatia Security Scan @@ -10,12 +10,26 @@ on: schedule: - cron: '0 0 * * 0' # Weekly on Sunday workflow_dispatch: +# Estate guardrail: cancel superseded runs so re-pushes don't pile up +# queued runs across the estate. Safe here because this workflow only +# performs read-only checks/lint/test/scan with no publish or mutation. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true permissions: contents: read # security-events: read lets the built-in GITHUB_TOKEN query this - # repo\'s own Dependabot alerts via the Hypatia DependabotAlerts rule. + # repo's own Dependabot alerts via the Hypatia DependabotAlerts rule + # (DA001-DA004). Without this, `scan_from_path` gets HTTP 403 and + # the rule silently returns no findings. + # See 007-lang/audits/audit-dependabot-automation-gap-2026-04-17.md. security-events: read + # pull-requests: write lets the advisory "Comment on PR with findings" + # step post its summary. Without it the built-in GITHUB_TOKEN gets + # "Resource not accessible by integration" and (absent continue-on-error) + # hard-fails the scan — exactly what the gate-decoupling design forbids. + pull-requests: write jobs: scan: @@ -28,32 +42,49 @@ jobs: with: fetch-depth: 0 # Full history for better pattern analysis + - name: Setup Elixir for Hypatia scanner + uses: erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2 + with: + elixir-version: '1.19.4' + otp-version: '28.3' + - name: Clone Hypatia run: | if [ ! -d "$HOME/hypatia" ]; then git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" fi + - name: Build Hypatia scanner (if needed) + run: | + cd "$HOME/hypatia" + if [ ! -f hypatia ]; then + echo "Building hypatia scanner..." + mix deps.get + mix escript.build + fi + - name: Run Hypatia scan id: scan env: - # Suppress the Dependabot "GITHUB_TOKEN not set" warning. + # Pass the built-in Actions token through to Hypatia so the + # DependabotAlerts rule can query this repo's own alerts. + # For cross-repo scanning (fleet-coordinator scan-supervised), + # a PAT with `security_events` scope is required instead. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "Scanning repository: ${{ github.repository }}" - # Use bash fallback scanner (escript not yet available in CI) - # Scanner exits non-zero when findings exist — capture output regardless - HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli-bash.sh" scan . > hypatia-findings.json || true + # Run scanner (exits non-zero when findings exist — suppress to continue) + HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json || true - # Count findings (handle both array and object JSON formats) - FINDING_COUNT=$(jq 'if type == "array" then length else .count // 0 end' hypatia-findings.json 2>/dev/null || echo 0) + # Count findings + FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0) echo "findings_count=$FINDING_COUNT" >> $GITHUB_OUTPUT - # Extract severity counts (handle format variations gracefully) - CRITICAL=$(jq 'if type == "array" then [.[] | select(.severity == "critical")] | length else .critical // 0 end' hypatia-findings.json 2>/dev/null || echo 0) - HIGH=$(jq 'if type == "array" then [.[] | select(.severity == "high")] | length else .high // 0 end' hypatia-findings.json 2>/dev/null || echo 0) - MEDIUM=$(jq 'if type == "array" then [.[] | select(.severity == "medium")] | length else .medium // 0 end' hypatia-findings.json 2>/dev/null || echo 0) + # Extract severity counts + CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json) + HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json) + MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json) echo "critical=$CRITICAL" >> $GITHUB_OUTPUT echo "high=$HIGH" >> $GITHUB_OUTPUT @@ -185,7 +216,12 @@ jobs: - name: Comment on PR with findings if: github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0 - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v7 + # Advisory only — posting findings as a PR comment must never gate + # the scan (hypatia#213 gate decoupling). Belt-and-braces alongside + # the pull-requests: write permission above: a token/API hiccup or + # a fork PR (read-only token) skips the comment, not the check. + continue-on-error: true + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7 with: script: | const fs = require('fs'); @@ -215,4 +251,4 @@ jobs: repo: context.repo.repo, issue_number: context.issue.number, body: comment - }); + }); \ No newline at end of file