From 56bd57c9689ac8a023886cee57aa46eb551d385b Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Tue, 1 Sep 2026 08:33:40 +0900 Subject: [PATCH] ci: run cargo audit on a schedule and open a fix PR The audit job in ci.yml only fires on push/PR, so a new advisory against an unchanged dependency sits unnoticed until someone opens a PR. Run the same check every other day and hand a red result to claude-code-action to fix, guarded by an open-PR dedupe check. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01GDiqUGkJRdMfb4b9Xak7DJ --- .github/workflows/audit.yml | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/audit.yml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 00000000..342da6d4 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,75 @@ +name: Security Audit + +# The `audit` job in ci.yml only runs on push/PR, so a new RustSec advisory +# against an unchanged dependency goes unnoticed until someone happens to open +# a PR. This runs the same check on a schedule and hands a red result to Claude +# to fix, the way #214 (h2 / RUSTSEC-2026-0258) was fixed by hand. + +on: + schedule: + # ponytail: every other day-of-month, so the 31st→1st gap runs back to + # back. Harmless for a dedupe-guarded job; switch to a weekday list if it + # ever matters. + - cron: "0 7 */2 * *" + workflow_dispatch: + +jobs: + audit: + name: Scheduled Security Audit + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: write + pull-requests: write + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v2 + - name: Install cargo-audit + uses: taiki-e/install-action@v2 + with: + tool: cargo-audit + + - name: cargo audit + id: audit + continue-on-error: true + run: cargo audit + + - name: Open a fix PR + if: steps.audit.outcome == 'failure' + uses: anthropics/claude-code-action@v1 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + claude_args: | + --allowedTools "Bash(cargo audit),Bash(cargo update:*),Bash(cargo tree:*),Bash(cargo check:*),Bash(git checkout:*),Bash(git switch:*),Bash(git branch:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(gh pr list:*),Bash(gh pr create:*),Bash(gh pr view:*)" + prompt: | + `cargo audit` is failing on the default branch. + + First run `gh pr list --state open --search "cargo audit in:title"`. If a PR + for these same advisories is already open, stop and do nothing. + + Otherwise: run `cargo audit` to see the advisories and fix them. Prefer + `cargo update -p `; bump the version in Cargo.toml only if the + lockfile alone can't reach a patched release. If an advisory has no fixed + version (unmaintained or unsound crates), or the fix needs a transitive + dependency we don't control, don't force it — open the PR with whatever you + could fix and say plainly in the description what is left and why. + + Verify both `cargo audit` and `cargo check --target wasm32-unknown-unknown` + pass before opening the PR. + + Then create a branch `claude/audit-` off the default branch, + commit as `fix(deps): for `, push, read + `.github/pull_request_template.md`, fill each section (removing the HTML + comment instructions), write it to a temp file and run + `gh pr create --body-file `. Title the PR so it contains the words + "cargo audit", so the dedupe check above finds it next run. + + - name: Fail the run + # A red run is the visible alarm; the PR above is the fix. Same reason + # contract.yml stays red instead of quietly filing and passing. + if: steps.audit.outcome == 'failure' + run: exit 1