Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,9 @@ updates:
patterns: ["*"]
update-types: [minor, patch] # majors stay separate: they change action.yml for users

# The project is locked with uv (uv.lock), so use the uv ecosystem rather than pip.
# Users never install uv.lock (action.yml resolves dependencies at runtime), so these
# bumps use `chore`, which release-please does not release.
- package-ecosystem: uv
directory: /
schedule:
interval: monthly
commit-message:
prefix: "chore"
include: scope
cooldown:
default-days: 7
allow:
- dependency-type: all # also refresh transitive pins (urllib3, idna, pip, ...)
groups:
python:
patterns: ["*"]
python-security:
applies-to: security-updates
patterns: ["*"]
# No entry for the root project: it commits no lock. action.yml resolves its dependencies on
# every run with a 7-day cooldown, and the CI security audit checks that resolution on every
# push and weekly.

# integration-tests/cases/* are fixtures: never update them. The vulnerable ones are pinned
# on purpose; the clean ones are unpinned and unlocked, so CI audits the latest releases.
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches: [main]
pull_request:
schedule:
- cron: "17 6 * * 1" # weekly: dependencies resolve fresh, so test and audit what users get now

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -12,6 +14,10 @@ concurrency:
permissions:
contents: read

# The same cooldown as action.yml, so tests and the self-audit resolve what users get.
env:
UV_EXCLUDE_NEWER: 7 days

jobs:
pre-commit:
name: Pre-commit
Expand Down Expand Up @@ -54,10 +60,7 @@ jobs:
with:
persist-credentials: false
- uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
# action.yml resolves dependencies at runtime (`uv run --no-project --with`):
# audit that resolution, as users get it, not the committed dev lock.
- name: Resolve dependencies as users get them
run: uv lock --upgrade
# No committed lock: `uv export` resolves one with the cooldown above, as users get it.
- uses: ./
with:
bandit_scan_dirs: src
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ bandit-report.json
pip-audit-report.json
*-requirements.txt
.claude/
/uv.lock
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ The job fails (non-zero exit) when **either** tool finds issues above its config
| `github_token` | `${{ github.token }}` | Token used for posting PR comments (only needed when `comment_on` is not `never`) |
| `artifact_name` | `security-audit-reports` | Name of the uploaded artifact |
| `debug` | `false` | Enable verbose debug logging; also activates automatically when re-running a workflow with "Enable debug logging" |
| `dependency_cooldown_days` | `7` | Skip releases of the action's own dependencies younger than this many days; `0` turns it off (needed for an index without upload times) |

## Outputs

Expand All @@ -357,6 +358,10 @@ The job fails (non-zero exit) when **either** tool finds issues above its config
- **Artifact** — `pip-audit-report.json` and `results.sarif` uploaded under the name set by `artifact_name` (default: `security-audit-reports`) for download or downstream steps. The `results.sarif` file is the bandit SARIF report; it is also uploaded to GitHub Code Scanning with `github/codeql-action/upload-sarif`, making findings visible in the repository's Security tab when the job has `security-events: write` permission.
- **Exit code** — non-zero when blocking issues are found, or when a tool could not run fully (for bandit: a missing scan dir, a file it cannot parse, or no Python file to scan), so the job fails and branch protections can enforce it.

## How the action installs its tools

Each run resolves bandit, pip-audit and their dependencies fresh, so fixes reach you without updating the action, but skips any release published in the last 7 days (`dependency_cooldown_days`). A hijacked release on PyPI is usually caught and removed within that window. If uv installs from an index that does not publish upload times (some private mirrors), set `dependency_cooldown_days: 0`, or nothing can be resolved.

## Development

```bash
Expand Down
19 changes: 18 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ inputs:
debug:
description: Enable debug logging for the Python audit module
default: 'false'
dependency_cooldown_days:
description: Skip releases of the action's own dependencies younger than this many days; 0 turns it off (needed for an index without upload times)
default: '7'

runs:
using: composite
Expand All @@ -51,6 +54,9 @@ runs:
- name: Set up uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0

# Dependencies resolve fresh on every run but skip releases younger than the cooldown, the
# window in which a hijacked PyPI release is usually caught. A flag, not UV_EXCLUDE_NEWER, so
# the caller's own `uv export` still audits their lock as committed.
- name: Run security audit
id: audit
shell: bash
Expand All @@ -69,7 +75,18 @@ runs:
PR_NUMBER: ${{ github.event.pull_request.number }}
INPUT_DEBUG: ${{ inputs.debug }}
RUNNER_DEBUG: ${{ runner.debug }}
run: uv run --python 3.13 --no-project --with "$GITHUB_ACTION_PATH" python -m python_security_auditing
COOLDOWN_DAYS: ${{ inputs.dependency_cooldown_days }}
run: |
cooldown=()
if [ "$COOLDOWN_DAYS" != 0 ]; then
[[ "$COOLDOWN_DAYS" =~ ^[0-9]+$ ]] || { echo "::error::dependency_cooldown_days must be a whole number of days"; exit 1; }
# An absolute time: uv before 0.9.17 rejects "7 days", and setup-uv installs the uv a
# caller pins. GNU date (Linux, Windows) first, then BSD date (macOS).
cutoff=$(date -u -d "$COOLDOWN_DAYS days ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null ||
date -u -v-"$COOLDOWN_DAYS"d +%Y-%m-%dT%H:%M:%SZ)
cooldown=(--exclude-newer "$cutoff")
fi
uv run --python 3.13 --no-project "${cooldown[@]}" --with "$GITHUB_ACTION_PATH" python -m python_security_auditing

# results.sarif exists only if bandit scanned every file in this job: the first step removes
# an earlier one, and the audit deletes it when bandit fails or skips files (an empty or
Expand Down
Loading
Loading