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:
cargo auditfor RustSec vulnerabilities, unmaintained or unsound advisories, and yanked lockfile entries;cargo denyfor 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
-
Confirm that
Cargo.lockis tracked and that ordinary CI Cargo commands use--locked. -
Determine the current stable
cargo-auditandcargo-denyreleases from their official upstream sources when applying the task. Pin both versions in CI, and install them withcargo install --locked --version ...only when the installed version does not exactly match the pin. -
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 checkBoth 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.
-
Add a tracked
deny.tomlusing the schema supported by the pinnedcargo-denyversion:- 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.
-
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.
-
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.
-
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.