zc2 0.0.26

P2P compute broker with credit-based billing, WAL, and broker mesh support
# Security scanning for zakuro-ai/zc.
#
# Closes #44. Hardened per #99.
#
# Three lanes:
#   - cargo-audit + cargo-deny — Rust advisory DB + licence/source policy.
#                                cargo-audit is a REQUIRED check: a new CVE
#                                in the dependency tree blocks merge. The
#                                cargo-deny sub-steps remain advisory.
#   - gitleaks                 — secrets in history / working tree (advisory).
#   - trivy fs                 — filesystem-level CVEs (catches Dockerfile
#                                base-image issues + lockfile vulns; advisory).
#
# To finish the rollout: add the `cargo-audit` job to branch-protection
# required checks (see the PR for the gh api command), then drop the
# remaining `continue-on-error` blocks lane-by-lane as each baseline is
# confirmed.

name: security

on:
  # cargo-audit gates pull requests (blocking); gitleaks + trivy run
  # alongside but stay advisory. Also runs post-merge on the trunk (master)
  # and on release branches, plus a weekly cron, plus on demand.
  push:
    branches:
      - master
      - main
      - 'release/**'
    paths-ignore:
      - "**.md"
      - "docs/**"
  pull_request:
    paths-ignore:
      - "**.md"
      - "docs/**"
  schedule:
    # Weekly Monday 07:00 UTC re-scan against the latest advisory DBs so
    # newly-disclosed CVEs are surfaced even on a quiet week.
    - cron: "0 7 * * 1"
  workflow_dispatch:

concurrency:
  group: security-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ !startsWith(github.ref, 'refs/heads/master') && !startsWith(github.ref, 'refs/heads/main') && !startsWith(github.ref, 'refs/heads/release/') }}

jobs:
  cargo-audit:
    runs-on: cpu
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8  # stable
        with:
          toolchain: "stable"

      - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32  # v2

      # Pull prebuilt cargo-audit / cargo-deny binaries instead of
      # `cargo install --locked` (which compiled both from source and was
      # ~8 min of this job's runtime). taiki-e/install-action fetches
      # pinned release binaries in seconds.
      - name: Install cargo-audit + cargo-deny
        uses: taiki-e/install-action@9e1e5806d4a4822de933115878265be9aaa786d9  # v2
        with:
          tool: cargo-audit,cargo-deny

      - name: cargo audit
        run: cargo audit --ignore RUSTSEC-0000-0000

      - name: cargo deny check advisories
        run: cargo deny check advisories
        continue-on-error: true

      - name: cargo deny check bans + licenses + sources
        run: cargo deny check bans licenses sources
        continue-on-error: true

  gitleaks:
    runs-on: cpu
    timeout-minutes: 10
    continue-on-error: true
    permissions:
      contents: read
      security-events: write
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0
        with:
          fetch-depth: 0

      - name: gitleaks
        uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e  # v3
        with:
          args: detect --source . --report-format sarif --report-path gitleaks.sarif
        continue-on-error: true

      - name: Upload gitleaks SARIF
        if: always()
        uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e  # v4
        with:
          sarif_file: gitleaks.sarif
          category: gitleaks
        continue-on-error: true

  trivy-fs:
    runs-on: cpu
    timeout-minutes: 10
    continue-on-error: true
    permissions:
      contents: read
      security-events: write
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0

      - name: Trivy filesystem scan
        uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25  # v0.36.0
        with:
          scan-type: fs
          scan-ref: .
          format: sarif
          output: trivy.sarif
          severity: CRITICAL,HIGH
          ignore-unfixed: true

      - name: Upload Trivy SARIF
        if: always()
        uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e  # v4
        with:
          sarif_file: trivy.sarif
          category: trivy-fs
        continue-on-error: true