Security Audit #1337
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Security Audit | |
| on: | |
| schedule: | |
| # Run daily at 00:00 UTC | |
| - cron: '0 0 * * *' | |
| push: | |
| branches: [main] | |
| paths: | |
| - '**/Cargo.toml' | |
| - '**/Cargo.lock' | |
| # No paths filter: a required status check that a pull request never produces | |
| # waits at Expected forever. | |
| pull_request: | |
| merge_group: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| audit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| # Prebuilt binary: `cargo audit` only parses Cargo.lock, so it needs no | |
| # toolchain. rustsec/audit-check instead compiled cargo-audit from source | |
| # with the repo-pinned toolchain, which broke once cargo-audit's own | |
| # dependency tree outgrew that toolchain's version. | |
| - uses: taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853 # v2.83.2 | |
| with: | |
| tool: cargo-audit | |
| - name: cargo audit | |
| id: root-audit | |
| run: cargo audit | |
| # fuzz/ is a self-contained workspace with its own committed lockfile, | |
| # which a bare `cargo audit` never reads. Run from the repo root so | |
| # .cargo/audit.toml applies to both lockfiles, and run even when the | |
| # root audit fails so one lockfile cannot mask the other. | |
| - name: cargo audit (fuzz lockfile) | |
| if: success() || steps.root-audit.outcome == 'failure' | |
| run: cargo audit --file fuzz/Cargo.lock | |
| - name: Open or update advisory issue | |
| if: failure() && github.event_name == 'schedule' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| title="Security audit found vulnerable dependencies" | |
| run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| body=$(printf 'The scheduled security audit failed: a RustSec advisory matches a dependency in the root or fuzz Cargo.lock.\n\nFailed run: %s\n\nUpdate the affected dependency to a patched version shown in the run log.' "$run_url") | |
| existing=$(gh issue list --state open --search "in:title \"$title\"" --json number --jq '.[0].number') | |
| if [ -n "$existing" ]; then | |
| gh issue comment "$existing" --body "$body" | |
| else | |
| gh issue create --title "$title" --body "$body" | |
| fi |