|
1 | | -# Reusable: security-static + CodeQL gate. |
| 1 | +# Reusable: security-static + license gate. |
| 2 | +# CodeQL is not here: PRs do not run it. It runs on push to main, weekly, and |
| 3 | +# inside dry-run.yml / release.yml, which call codeql.yml directly. |
2 | 4 | # Runs independently from lint/test/build — does not block the main pipeline. |
3 | 5 | # Affects overall workflow success status. |
4 | 6 | name: Security Gate |
|
21 | 23 | steps: |
22 | 24 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
23 | 25 | - name: "Layer 1: Static allow-list audit" |
24 | | - run: scripts/security-audit.sh |
| 26 | + run: | |
| 27 | + bash tests/test_security_audit_subprocess_calls.sh |
| 28 | + scripts/security-audit.sh |
25 | 29 | - name: "Layer 6: UI security audit" |
26 | | - run: scripts/security-ui.sh |
| 30 | + run: | |
| 31 | + bash tests/test_security_ui_urls.sh |
| 32 | + scripts/security-ui.sh |
27 | 33 | - name: "Layer 8: Vendored dependency integrity" |
28 | 34 | run: scripts/security-vendored.sh |
29 | 35 |
|
|
34 | 40 | steps: |
35 | 41 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
36 | 42 | - name: Install ScanCode Toolkit |
37 | | - run: pipx install scancode-toolkit |
| 43 | + # Pinned: an unpinned install picked up pluggy 1.7.0, which breaks |
| 44 | + # scancode at import (see .github/scancode-constraints.txt). |
| 45 | + env: |
| 46 | + PIP_CONSTRAINT: ${{ github.workspace }}/.github/scancode-constraints.txt |
| 47 | + run: pipx install scancode-toolkit==32.5.0 |
38 | 48 | - name: "Gate self-test (a planted violation must be detected)" |
39 | 49 | run: scripts/license-gate.sh --selftest |
40 | 50 | - name: "License compliance gate (one finding fails)" |
|
44 | 54 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
45 | 55 | run: scripts/audit-license-provenance.py |
46 | 56 |
|
47 | | - codeql-gate: |
48 | | - if: ${{ inputs.lanes == 'all' || contains(fromJSON(inputs.lanes), 'codeql-gate') }} |
49 | | - runs-on: ubuntu-latest |
50 | | - timeout-minutes: 240 |
51 | | - # Without security-events:read this job inherits the workflow's |
52 | | - # contents:read, the code-scanning alert API answers 403, and the gate |
53 | | - # below reported "0 alerts" on every run it has ever made. actions:read is |
54 | | - # what the CodeQL-run poll above needs for the same reason. |
55 | | - permissions: |
56 | | - contents: read |
57 | | - security-events: read |
58 | | - actions: read |
59 | | - steps: |
60 | | - - name: Wait for CodeQL on current commit (max 150 min) |
61 | | - env: |
62 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
63 | | - run: | |
64 | | - # On pull_request events github.sha is the synthetic merge commit; |
65 | | - # CodeQL runs are recorded against the PR head SHA. |
66 | | - CURRENT_SHA="${{ github.event.pull_request.head.sha || github.sha }}" |
67 | | - echo "Waiting for CodeQL to complete on $CURRENT_SHA..." |
68 | | - # 300 attempts x 30s = 150 min. The previous budget was 90 x 30s = 45 min, |
69 | | - # which is shorter than CodeQL actually takes on this repository: a measured |
70 | | - # run on PR #1426 (head 7b72652a) completed with conclusion=success after |
71 | | - # 124 min, 7 minutes AFTER this gate had already given up. That marked at |
72 | | - # least five contributor PRs red for a scan that passed. The job's own |
73 | | - # timeout-minutes is 240, so 150 still leaves headroom. |
74 | | - for attempt in $(seq 1 300); do |
75 | | - LATEST=$(gh api "repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?head_sha=$CURRENT_SHA&per_page=1" \ |
76 | | - --jq '.workflow_runs[] | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "") |
77 | | - if [ -z "$LATEST" ]; then |
78 | | - echo " $attempt/300: no run yet..."; sleep 30; continue |
79 | | - fi |
80 | | - CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1) |
81 | | - STATUS=$(echo "$LATEST" | cut -d' ' -f2) |
82 | | - if [ "$STATUS" = "completed" ] && [ "$CONCLUSION" = "success" ]; then |
83 | | - echo "=== CodeQL passed ==="; exit 0 |
84 | | - elif [ "$STATUS" = "completed" ]; then |
85 | | - echo "BLOCKED: CodeQL $CONCLUSION"; exit 1 |
86 | | - fi |
87 | | - echo " $attempt/300: $STATUS..."; sleep 30 |
88 | | - done |
89 | | - echo "BLOCKED: CodeQL timeout"; exit 1 |
90 | | -
|
91 | | - - name: Check for open code scanning alerts |
92 | | - env: |
93 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
94 | | - run: | |
95 | | - # FAIL CLOSED. The previous form was `gh api ... 2>/dev/null || echo "0"`, |
96 | | - # which looks defensive and is the opposite. gh writes the API error |
97 | | - # BODY to stdout, so a 403 made ALERTS the string |
98 | | - # {"message":"Resource not accessible by integration",...,"status":"403"}0 |
99 | | - # every `[` comparison then failed as non-integer, the `if` took its |
100 | | - # false branch, and the step printed "CodeQL gate passed (0 alerts)" |
101 | | - # and exited 0. That is exactly how a security gate should NEVER fail: |
102 | | - # silently, in the direction of "everything is fine". An unreadable |
103 | | - # alert list is now an error, not a zero. |
104 | | - # NOTE: this runs in a command substitution, so it must `return`, not |
105 | | - # `exit` -- an `exit` here would only end the subshell and let the |
106 | | - # caller continue with an empty count, recreating the very bug this |
107 | | - # replaces. The callers below check the status explicitly. |
108 | | - count_open_alerts() { |
109 | | - local body status |
110 | | - body=$(gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' \ |
111 | | - --jq 'length' 2>/dev/null) |
112 | | - status=$? |
113 | | - if [ $status -ne 0 ]; then |
114 | | - echo "BLOCKED: cannot read code scanning alerts (gh exit $status)." >&2 |
115 | | - echo " Refusing to treat an unreadable alert list as zero." >&2 |
116 | | - echo " Most likely cause: the job lacks security-events:read." >&2 |
117 | | - return 1 |
118 | | - fi |
119 | | - case "$body" in |
120 | | - ''|*[!0-9]*) |
121 | | - echo "BLOCKED: alert count was not a number: ${body:-<empty>}" >&2 |
122 | | - return 1 |
123 | | - ;; |
124 | | - esac |
125 | | - printf '%s' "$body" |
126 | | - } |
127 | | - echo "Waiting 60s for alert API to settle..." |
128 | | - sleep 60 |
129 | | - ALERTS=$(count_open_alerts) || exit 1 |
130 | | - sleep 15 |
131 | | - ALERTS2=$(count_open_alerts) || exit 1 |
132 | | - [ "$ALERTS" -lt "$ALERTS2" ] && ALERTS=$ALERTS2 |
133 | | - if [ "$ALERTS" -gt 0 ]; then |
134 | | - echo "BLOCKED: $ALERTS open alert(s)" |
135 | | - gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' \ |
136 | | - --jq '.[] | " #\(.number) [\(.rule.security_severity_level // .rule.severity)] \(.rule.id) — \(.most_recent_instance.location.path):\(.most_recent_instance.location.start_line)"' 2>/dev/null || true |
137 | | - exit 1 |
138 | | - fi |
139 | | - echo "=== CodeQL gate passed (0 alerts) ===" |
0 commit comments