feat(audit): weekly CodeQL audit that files code-scanning alerts as issues

Merged
DO
1mo ago
+1006-0

Summary

Adds an org-wide CodeQL Audit, the code-scanning counterpart of the SonarCloud audit. Until now nothing turned open CodeQL alerts into work: the compliance audit only counts them into a score, and the code_scanning ruleset only blocks new merges.

  • scripts/codeql-audit.sh reads GET repos/{owner}/{repo}/code-scanning/alerts?state=open&tool_name=CodeQL (paginated) for every non-archived repo and groups alerts per repo × language family into one idempotent issue titled CodeQL: <family>, keyed by a hidden <!-- codeql-audit:key=<repo>/<family> --> marker.
  • Labels: codeql-audit (marker), dev-lead, priority:<level> from the group's worst security_severity_level (else the rule severity), and security for security alerts. It uses the same priority scale as the Sonar audit and creates shared labels only when they are missing, so their descriptions are never overwritten.
  • Re-runs refresh the body, comment, and re-trigger dev-lead through scripts/lib/dev-lead-retrigger.sh. A group with no open alerts is closed automatically.
  • .github/workflows/codeql-audit.yml: Wednesdays 17:02 UTC, between the Tuesday Sonar audit and the Friday compliance audit (minute from cron_offset_minute). Has target_repo and dry_run dispatch inputs.
  • .github/workflows/codeql-audit-tests.yml runs shellcheck and bats on test/scripts/codeql-audit/ (42 tests).
  • Docs: standards/ci-standards.md § CodeQL Audit, plus a row in the github-settings.md org-workflows table.

No duplicate issues

AlertHandlingWhy
actions/unpinned-tag on a combsmith/* refsuppressedFirst-party channel tags are exempt from SHA-pinning by policy. Filing them would send dev-lead to break the stubs. Today this is all 69 unpinned-tag alerts.
actions/unpinned-tag, third-partysuppressedAlready filed as Compliance: unpinned-actions-<wf>
actions/missing-workflow-permissionssuppressedAlready filed as Compliance: missing-permissions-<wf>
Scorecard SARIF alertsexcluded by tool_name=CodeQLOwned by org-scorecard.yml
SonarCloud findingsn/aThe Sonar audit uses a different source, marker label, title prefix and body key, so neither audit adopts or closes the other's issues

Suppressed alerts appear in the run summary with their reason, so they are visible but never filed.

Fail closed: if a repo's alerts can't be read (anything other than GitHub's no analysis found), the repo is marked inconclusive and its issues are left untouched. The run then fails after the summary is written.

Dry run (.github-private, local token)

[info] CodeQL audit — org=combsmith dry_run=true create_issues=true target=.github-private
[info] Scanning .github-private
[info] [dry-run] .github-private :: CodeQL: GitHub Actions workflow security [codeql-audit,dev-lead,priority:major,security] (4 alert(s))
[info] [dry-run] .github-private :: CodeQL: JavaScript/TypeScript alerts [codeql-audit,dev-lead,priority:critical,security] (32 alert(s))
[info] Done. Filed alerts: 36; suppressed: 13; groups: 2; added=0 existing=0 removed=0

Whole-org dry run: 15 repos read, 0 inconclusive, 36 alerts filed as 2 issues, 69 suppressed.

Before the first scheduled run

  • Confirm ORG_SCORECARD_TOKEN has Code scanning alerts: Read-only on all repos. The local dry run used a different token. The compliance workflow's own code-scanning read treats errors as 0, so it does not prove the scope. If the scope is missing, every repo comes back inconclusive and the run goes red; no issues are written.
  • Optional: dispatch with dry_run: true once after merge.

Test plan

  • bats test/scripts/codeql-audit/ — 42/42
  • shellcheck --severity=warning -x scripts/codeql-audit.sh, actionlint, check-cron-timing.sh, markdownlint on the changed docs
  • Action SHAs checked with the GitHub API (actions/checkout v7.0.1 3d3c42e5…, actions/upload-artifact v7.0.2 cf430e03…, both current latest)
  • Local dry runs, one repo and whole org

🤖 Generated with Claude Code