Add Cargo dependency policy gates

This commit is contained in:
Dandaedre 2026-10-02 21:45:16 +02:00
parent eade00b5b1
commit b220546800
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 126 additions and 64 deletions

View File

@ -5,7 +5,7 @@ version = "0.1.0"
edition = "2021"
rust-version = "1.85.1"
categories =["developement-tools"]
license = "GPL-2.0"
license = "LGPL-2.0-only"
keywords = ["lsp", "bridge"]
repository = "https://proxy.dandaedre.com/gitea/MadGobblins/vsg-bridge-ls"
authors = ["dandaedre"]

40
Jenkinsfile vendored
View File

@ -9,6 +9,8 @@ pipeline {
RUST_BACKTRACE = '1'
MSRV = '1.85.1'
CARGO_TARPAULIN_VERSION = '0.37.5'
CARGO_AUDIT_VERSION = '0.22.2'
CARGO_DENY_VERSION = '0.20.2'
COVERAGE_PUBLISH_ROOT = '/mnt/assets/coverage'
}
@ -57,6 +59,40 @@ pipeline {
--locked \
--version "${CARGO_TARPAULIN_VERSION}"
fi
installed_audit=$(cargo audit --version 2>/dev/null || true)
if [ "${installed_audit}" != "cargo-audit-audit ${CARGO_AUDIT_VERSION}" ]; then
cargo install cargo-audit \
--locked \
--version "${CARGO_AUDIT_VERSION}"
fi
installed_deny=$(cargo deny --version 2>/dev/null || true)
if [ "${installed_deny}" != "cargo-deny ${CARGO_DENY_VERSION}" ]; then
cargo install cargo-deny \
--locked \
--version "${CARGO_DENY_VERSION}"
fi
'''
}
}
stage('Cargo audit') {
steps {
sh '''
set -eu
cargo audit --deny warnings
'''
}
}
stage('Cargo deny') {
steps {
sh '''
set -eu
cargo deny check
'''
}
}
@ -191,7 +227,7 @@ pipeline {
conclusion: 'SUCCESS',
name: 'Rust CI',
summary: 'vsg_bridge_ls passed CI.',
text: 'MSRV/stable checks, formatting, tests, Clippy, and coverage completed successfully.',
text: 'Dependency audit/policy, MSRV/stable checks, formatting, tests, Clippy, and coverage completed successfully.',
title: 'Build Successful'
)
@ -203,7 +239,7 @@ pipeline {
conclusion: 'FAILURE',
name: 'Rust CI',
summary: 'vsg_bridge_ls failed CI.',
text: 'An MSRV/stable, formatting, test, Clippy, or coverage check failed. Check the Jenkins log.',
text: 'A dependency audit/policy, MSRV/stable, formatting, test, Clippy, or coverage check failed. Check the Jenkins log.',
title: 'Build Failed'
)

View File

@ -77,7 +77,7 @@ buffer with the fork.
- [Installation alternatives and PATH troubleshooting](doc/installation.md)
- [Helix, Vim, and VSCodium setup](doc/editor-configuration.md)
- [Development and packaging](doc/development.md)
- [Dependency and CI hardening plan](doc/supply-chain-hardening.md)
- [Dependency and CI semi-hardening policy](doc/supply-chain-hardening.md)
The bridge is deliberately small. Contributions should preserve clean LSP
standard output and keep the VSG subprocess boundary explicit.

33
deny.toml Normal file
View File

@ -0,0 +1,33 @@
# Build the same dependency graph checked by the rest of CI.
[graph]
all-features = true
# Advisory exceptions require an explicit, documented decision.
[advisories]
ignore = []
# This is the complete set needed by the current resolved graph.
[licenses]
allow = [
"Apache-2.0",
"LGPL-2.0-only",
"MIT",
"Unicode-3.0",
]
confidence-threshold = 0.8
exceptions = []
[bans]
multiple-versions = "warn"
wildcards = "deny"
highlight = "all"
allow = []
deny = []
skip = []
skip-tree = []
[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []

View File

@ -26,6 +26,15 @@ cargo test --locked --all-targets --all-features
cargo clippy --locked --all-targets --all-features -- -D warnings
```
The two network-enabled dependency policy gates are documented in
[`supply-chain-hardening.md`](supply-chain-hardening.md). Run them before the
core checks:
```sh
cargo audit --deny warnings
cargo deny check
```
## Coverage
Jenkins uses pinned Cargo Tarpaulin 0.37.5 with its LLVM engine and the current

View File

@ -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.