Skip to content

Commit 13ce464

Browse files
authored
ci: add CodeQL scanning
Add Python CodeQL scanning for pull requests, main pushes, and weekly scheduled runs, plus docs and a policy test that keep the public security posture visible. Tests: ruff check src/ tests/; python3 -m pytest tests/test_distribution_policy.py -q -p no:cacheprovider; python3 -m pytest -q -p no:cacheprovider
1 parent 8b090e4 commit 13ce464

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

.github/workflows/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ Steps:
1616

1717
No secrets are required for CI.
1818

19+
## `codeql.yml` — Code Scanning
20+
21+
Runs CodeQL analysis for Python on pushes and pull requests to `main`, plus a
22+
weekly scheduled scan. This uses advanced setup so the workflow is visible and
23+
reviewable in the repository.
24+
25+
Steps:
26+
1. Check out the repository.
27+
2. Initialize CodeQL for Python with the security-extended and security-and-quality
28+
query suites.
29+
3. Upload results to GitHub code scanning.
30+
31+
No secrets are required. The workflow grants `security-events: write` only so the
32+
CodeQL action can upload SARIF results to GitHub code scanning.
33+
1934
## `pypi.yml` — Manual PyPI Publish
2035

2136
Runs manually via `workflow_dispatch` after PyPI Trusted Publishing has been

.github/workflows/codeql.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
schedule:
9+
- cron: "23 9 * * 1"
10+
11+
permissions:
12+
actions: read
13+
contents: read
14+
security-events: write
15+
16+
concurrency:
17+
group: codeql-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
analyze:
22+
name: Analyze (${{ matrix.language }})
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 10
25+
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
language: ["python"]
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v6
34+
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v4
37+
with:
38+
languages: ${{ matrix.language }}
39+
queries: security-extended,security-and-quality
40+
41+
- name: Perform CodeQL Analysis
42+
uses: github/codeql-action/analyze@v4
43+
with:
44+
category: "/language:${{ matrix.language }}"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
## [Unreleased]
99

1010
### Changed
11+
- Added a CodeQL code-scanning workflow and documented the public security
12+
coverage.
1113
- Replaced placeholder README badges with live CI, PyPI, release, Python, and
1214
license badges for the public repository.
1315
- Refreshed public contributor, security, release-gate, and workflow docs now

docs/security-model.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ GithubRepoAuditor now treats security posture as a merged intelligence model ins
88
- **GitHub-native**: dependency graph/SBOM availability, code scanning status, secret scanning status, open alert counts
99
- **Scorecard**: optional public-repo enrichment from OpenSSF Scorecard
1010

11+
## Repository Security Coverage
12+
13+
This public repository runs CodeQL code scanning through
14+
`.github/workflows/codeql.yml`. The workflow analyzes Python on pushes and pull
15+
requests to `main`, plus a weekly scheduled scan, and uploads results to GitHub code
16+
scanning with `security-events: write`.
17+
18+
Dependabot alerting is enabled for the repository, and dependency plus GitHub Actions
19+
updates are configured in `.github/dependabot.yml`.
20+
1121
## Availability Rules
1222

1323
- `unavailable` means the provider could not be observed because of permissions, feature availability, or endpoint access.

tests/test_distribution_policy.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ def test_pypi_workflow_is_manual_trusted_publishing_only() -> None:
6060
assert "pypa/gh-action-pypi-publish@release/v1" in workflow
6161
assert "actions/upload-artifact" in workflow
6262
assert "actions/download-artifact" in workflow
63+
64+
65+
def test_public_repo_has_code_scanning_workflow_documented() -> None:
66+
workflow = (ROOT / ".github" / "workflows" / "codeql.yml").read_text()
67+
workflows_readme = (ROOT / ".github" / "workflows" / "README.md").read_text()
68+
security_model = (ROOT / "docs" / "security-model.md").read_text()
69+
70+
assert "github/codeql-action/init@v4" in workflow
71+
assert "github/codeql-action/analyze@v4" in workflow
72+
assert "security-events: write" in workflow
73+
assert "pull_request:" in workflow
74+
assert "schedule:" in workflow
75+
assert 'language: ["python"]' in workflow
76+
assert "security-extended,security-and-quality" in workflow
77+
assert "`codeql.yml` — Code Scanning" in workflows_readme
78+
assert ".github/workflows/codeql.yml" in security_model
79+
assert "Dependabot alerting is enabled" in security_model

0 commit comments

Comments
 (0)