|
|
|
|
@ -1,73 +1,57 @@
|
|
|
|
|
# Dependency and CI hardening plan
|
|
|
|
|
# Dependency and CI semi-hardening
|
|
|
|
|
|
|
|
|
|
No single tool can prove that a dependency is safe. Use several independent
|
|
|
|
|
controls: reproducible resolution, known-vulnerability scanning, dependency
|
|
|
|
|
policy, human review, and an isolated build environment.
|
|
|
|
|
This project deliberately uses two supply-chain checks: `cargo audit` and
|
|
|
|
|
`cargo deny`. Cargo Vet and other hardening tools are not part of this policy.
|
|
|
|
|
|
|
|
|
|
## Available controls
|
|
|
|
|
## Enforced controls
|
|
|
|
|
|
|
|
|
|
| Control | What it adds | Advantages | Costs and limits |
|
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
|
| Committed `Cargo.lock` and `--locked` | Exact versions and crates.io checksums | Fast, built into Cargo, reproducible, and prevents silent dependency drift | A checksum proves consistency, not that the first accepted crate was trustworthy; updates are manual |
|
|
|
|
|
| Pinned CI tools | Exact versions of coverage and security tools | Prevents surprise CI changes and makes failures reproducible | Pins become stale and the initial installation still trusts crates.io and its transitive graph |
|
|
|
|
|
| `cargo audit` | RustSec advisory and yanked-crate checks | Low setup cost and good signal for known vulnerabilities | Cannot detect unknown or deliberately malicious code; advisory updates require network access |
|
|
|
|
|
| `cargo deny` | License, source, duplicate, ban, advisory, and wildcard policy | One reviewable policy file; blocks unknown registries and Git sources | Needs license decisions and exception maintenance; duplicate versions are not automatically vulnerabilities |
|
|
|
|
|
| `cargo vet` | Human or imported audits for dependency code | Best direct answer to whether trusted reviewers inspected a crate | Highest maintenance cost; bootstrap requires imports, reviews, or explicit exemptions, and every update can need new evidence |
|
|
|
|
|
| Vendoring with `cargo vendor` | Repository or internal artifact copy of all crate sources | Offline builds, strong availability, and an inspectable frozen source set | Large diffs/storage, frequent refresh work, and vendoring malicious code does not make it safe |
|
|
|
|
|
| Private registry or registry proxy | Central allow-list, cache, and availability control | Useful across many projects; can quarantine versions and reduce external CI access | Becomes critical infrastructure and a concentrated trust/availability dependency |
|
|
|
|
|
| Ephemeral, unprivileged CI | Limits damage from build scripts and proc macros | Contains compromised build-time code and protects other jobs | Requires worker isolation; shared Cargo caches can reintroduce cross-job state |
|
|
|
|
|
| Network-denied build phase | Stops dependencies from calling external services during compilation/tests | Strong containment after sources and advisories are fetched | Requires a separate fetch phase and can expose packages that incorrectly depend on network access |
|
|
|
|
|
| Secretless pull-request jobs | Keeps tokens away from untrusted changes | Prevents straightforward credential theft through modified CI scripts | Publishing and deployment need a separate trusted-branch job or protected stage |
|
|
|
|
|
| SBOM and `cargo auditable` | Records the dependency graph in artifacts | Improves incident response and deployed-binary inventory | Primarily detective; it does not prevent compromise |
|
|
|
|
|
| Automated update proposals | Keeps dependencies and CI tools reviewably current | Small, regular updates are easier to review and audit | Notification noise and unsafe auto-merge rules can reduce review quality |
|
|
|
|
|
| Signed releases and provenance attestations | Connects published binaries to a reviewed build | Helps consumers verify origin and supports incident investigation | Key management and reproducible release infrastructure add substantial complexity |
|
|
|
|
|
`Cargo.lock` is committed, and CI uses `--locked`, so dependency resolution and
|
|
|
|
|
crates.io checksums cannot change implicitly. CI installs exact tool versions:
|
|
|
|
|
|
|
|
|
|
## Recommended rollout
|
|
|
|
|
- Cargo Audit 0.22.2;
|
|
|
|
|
- Cargo Deny 0.20.2.
|
|
|
|
|
|
|
|
|
|
### Phase 1: reproducible baseline
|
|
|
|
|
`cargo audit --deny warnings` refreshes the RustSec advisory database and fails
|
|
|
|
|
for known vulnerabilities as well as warning-level unmaintained, unsound, or
|
|
|
|
|
yanked dependencies. It needs outbound access to GitHub and crates.io and does
|
|
|
|
|
not permit a stale database.
|
|
|
|
|
|
|
|
|
|
1. Keep `Cargo.lock` committed because this repository builds an executable.
|
|
|
|
|
2. Require `--locked` in CI, installation documentation, and release builds.
|
|
|
|
|
3. Declare Rust 1.85.1 in `Cargo.toml` and test both that exact toolchain and
|
|
|
|
|
current stable.
|
|
|
|
|
4. Pin third-party CI tool versions. Review and update them deliberately.
|
|
|
|
|
`cargo deny check` applies the tracked `deny.toml` to the complete all-features
|
|
|
|
|
dependency graph. The policy:
|
|
|
|
|
|
|
|
|
|
These controls are implemented now.
|
|
|
|
|
- allows only licenses present in the current resolved graph;
|
|
|
|
|
- denies wildcard dependency requirements;
|
|
|
|
|
- reports duplicate crate versions for review without automatically rejecting
|
|
|
|
|
them;
|
|
|
|
|
- denies registries other than crates.io;
|
|
|
|
|
- denies every Git dependency;
|
|
|
|
|
- contains no advisory ignores, license exceptions, banned-crate exceptions, or
|
|
|
|
|
duplicate-version skips.
|
|
|
|
|
|
|
|
|
|
The initial pass also removes four direct dependencies that Cargo reports or
|
|
|
|
|
source inspection confirms are unused; the safest dependency is one the program
|
|
|
|
|
does not need.
|
|
|
|
|
The initial policy review also corrected the package's deprecated `GPL-2.0`
|
|
|
|
|
metadata to `LGPL-2.0-only`, matching the GNU Library General Public License v2
|
|
|
|
|
text in `LICENSE`.
|
|
|
|
|
|
|
|
|
|
### Phase 2: policy gates
|
|
|
|
|
Run the same gates locally from the repository root:
|
|
|
|
|
|
|
|
|
|
1. Add pinned `cargo-audit` and fail on RustSec findings and yanked packages.
|
|
|
|
|
2. Add `cargo-deny` with explicit allowed licenses, crates.io as the only
|
|
|
|
|
registry, unknown Git sources denied, wildcards denied, and duplicate
|
|
|
|
|
versions reported for review.
|
|
|
|
|
3. Permit exceptions only with a reason, an owner, and a removal condition.
|
|
|
|
|
4. Run advisory refresh in a network-enabled stage, then run compilation and
|
|
|
|
|
tests without outbound network access where the Jenkins worker supports it.
|
|
|
|
|
```sh
|
|
|
|
|
cargo install cargo-audit --locked --version 0.22.2
|
|
|
|
|
cargo install cargo-deny --locked --version 0.20.2
|
|
|
|
|
cargo audit --deny warnings
|
|
|
|
|
cargo deny check
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This is the best next cost/security tradeoff for this small project.
|
|
|
|
|
Both tools require network access when refreshing their databases and index
|
|
|
|
|
data. A new dependency license or source must be reviewed before changing
|
|
|
|
|
`deny.toml`. A vulnerability exception must not be added merely to restore a
|
|
|
|
|
green build; it requires an explicit decision, rationale, owner, and removal
|
|
|
|
|
condition.
|
|
|
|
|
|
|
|
|
|
### Phase 3: isolate and attest releases
|
|
|
|
|
## Limits
|
|
|
|
|
|
|
|
|
|
1. Run untrusted branches without credentials on disposable workers with
|
|
|
|
|
read-only base images and per-job Cargo directories.
|
|
|
|
|
2. Move package publication, coverage publication, tagging, and signing to a
|
|
|
|
|
protected trusted-branch job that consumes already-tested source revisions.
|
|
|
|
|
3. Generate an SBOM and build releases with `cargo auditable`.
|
|
|
|
|
4. Sign release checksums and publish provenance that records the commit,
|
|
|
|
|
toolchain, lockfile, and Jenkins build.
|
|
|
|
|
|
|
|
|
|
### Phase 4: stronger dependency trust when justified
|
|
|
|
|
|
|
|
|
|
Adopt `cargo vet` if the project becomes widely distributed or handles a more
|
|
|
|
|
sensitive boundary. Start with carefully selected audit imports, record every
|
|
|
|
|
exemption honestly, and require review of dependency diffs. Consider a private
|
|
|
|
|
registry proxy or vendoring if builds must continue without crates.io or policy
|
|
|
|
|
requires centralized dependency admission.
|
|
|
|
|
|
|
|
|
|
Do not begin with `cargo vet` or full vendoring for this bridge: their ongoing
|
|
|
|
|
review cost is disproportionate until the basic audit, policy, isolation, and
|
|
|
|
|
test gates are healthy.
|
|
|
|
|
These checks are useful gates, not proof that dependencies are trustworthy.
|
|
|
|
|
RustSec can identify only reported problems. License and source metadata can be
|
|
|
|
|
incorrect, and crates.io checksums establish consistency rather than safety.
|
|
|
|
|
Build scripts and procedural macros still execute code during a build. This is
|
|
|
|
|
therefore a semi-hardened dependency policy, intentionally limited to Cargo
|
|
|
|
|
Audit and Cargo Deny.
|
|
|
|
|
|