agent-tasks/tasks/semi-harden-ci.task.md

3.6 KiB

Add Cargo audit and dependency-policy gates to CI

Apply this task to one Cargo-based Rust repository at a time. Read its local agent instructions, preserve unrelated work, follow its commit policy, and do not push unless explicitly requested. Adapt names and documentation to the repository; do not copy identifiers, paths, versions, or branch names from a different project.

Scope

Add exactly these two supply-chain gates:

  1. cargo audit for RustSec vulnerabilities, unmaintained or unsound advisories, and yanked lockfile entries;
  2. cargo deny for dependency licenses, sources, wildcard requirements, duplicate-version visibility, and its advisory check.

Do not add cargo vet, SBOM generation, vendoring, registry proxies, provenance tools, or other security scanners as part of this task.

Implementation

  1. Confirm that Cargo.lock is tracked and that ordinary CI Cargo commands use --locked.

  2. Determine the current stable cargo-audit and cargo-deny releases from their official upstream sources when applying the task. Pin both versions in CI, and install them with cargo install --locked --version ... only when the installed version does not exactly match the pin.

  3. Add a dedicated CI stage for each command after checkout and tool setup but before build, test, coverage, packaging, or publication:

    cargo audit --deny warnings
    cargo deny check
    

    Both stages require network access to refresh advisory and registry data and must fail the build on findings or tool errors. Do not silently accept a stale advisory database.

  4. Add a tracked deny.toml using the schema supported by the pinned cargo-deny version:

    • inspect the resolved dependency graph and allow only licenses it currently needs;
    • set license confidence to 0.8;
    • deny wildcard requirements;
    • warn on duplicate versions so they remain visible without making every duplicate a vulnerability;
    • deny unknown registries and unknown Git sources;
    • explicitly allow crates.io and allow no Git sources;
    • enable all features for dependency-graph construction;
    • begin with empty advisory ignores, crate bans, duplicate skips, license exceptions, and license clarifications.
  5. Do not add an exception merely to make CI green. If a real finding prevents completion, report the advisory, crate, or license and its dependency path. Every exception needs an explicit user decision, a reason, and a removal condition.

  6. Document the pinned versions, exact local commands, network requirement, enforced policy, and limits of both tools in the repository's existing development or security documentation. State that no other hardening tools are in scope.

  7. Update CI success and failure summaries so both gates are visible, while preserving all unrelated existing checks.

Verification

Run, in this order:

cargo audit --deny warnings
cargo deny check
cargo fmt --all -- --check
cargo check --locked --all-targets --all-features
cargo test --locked --all-targets --all-features
cargo clippy --locked --all-targets --all-features -- -D warnings

Also run repository-specific MSRV, documentation, or packaging gates. Review cargo deny warnings instead of hiding them; duplicate-version warnings are expected only when unavoidable transitive constraints explain them. Commit the completed repository change and report tool versions, findings, checks, and the commit ID.