ci: add Cargo supply-chain gates

This commit is contained in:
Dandaedre 2026-10-04 02:18:04 +02:00
parent 46dd9ac3a0
commit af5f84808e
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
8 changed files with 1169 additions and 33 deletions

4
.gitignore vendored
View File

@ -4,10 +4,6 @@
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

1052
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,22 +3,20 @@ name = "rust_autobadges"
version = "0.1.0"
edition = "2024"
resolver = "2"
license = "0BSD"
rust-version = "1.85"
[dependencies]
anyhow = "1.0.92"
badge-maker = "0.3.1"
badge-maker-rs = "=0.1.0"
clap = { version = "4.5.31", features = ["derive"] }
console = "0.15.11"
indicatif = "0.17.11"
console = "0.16.6"
indicatif = "0.18.6"
logos = "0.15.0"
regex = "1.11.1"
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.44.1", features = ["full", "process"] } #["process", "rt", "io-util", "macros"] }
toml = "0.8.20"
xshell = "0.2.6"
[workspace.package]
rust-version = "1.85"
[dev-dependencies]
insta = "1.42.2"

55
Jenkinsfile vendored
View File

@ -7,6 +7,8 @@ pipeline {
environment {
CARGO_TERM_COLOR = 'never'
RUST_BACKTRACE = '1'
CARGO_AUDIT_VERSION = '0.22.2'
CARGO_DENY_VERSION = '0.20.2'
}
stages {
@ -46,6 +48,45 @@ pipeline {
}
}
stage('Setup Supply-Chain Tools') {
steps {
sh '''
set -eu
audit_version="$(cargo audit --version 2>/dev/null | awk '{print $2}' || true)"
if [ "$audit_version" != "$CARGO_AUDIT_VERSION" ]; then
cargo install --locked --version "$CARGO_AUDIT_VERSION" cargo-audit
fi
deny_version="$(cargo deny --version 2>/dev/null | awk '{print $2}' || true)"
if [ "$deny_version" != "$CARGO_DENY_VERSION" ]; then
cargo install --locked --version "$CARGO_DENY_VERSION" cargo-deny
fi
cargo audit --version
cargo deny --version
'''
}
}
stage('Cargo Audit') {
steps {
sh '''
set -eu
cargo audit --deny warnings
'''
}
}
stage('Dependency Policy') {
steps {
sh '''
set -eu
cargo deny check
'''
}
}
stage('Format') {
steps {
sh '''
@ -59,7 +100,7 @@ pipeline {
steps {
sh '''
set -eu
cargo test --all-targets --all-features
cargo test --locked --all-targets --all-features
'''
}
}
@ -68,7 +109,7 @@ pipeline {
steps {
sh '''
set -eu
cargo clippy --all-targets --all-features
cargo clippy --locked --all-targets --all-features
'''
}
}
@ -77,7 +118,7 @@ pipeline {
steps {
sh '''
set -eu
cargo build --release --all-features
cargo build --locked --release --all-features
'''
}
}
@ -89,7 +130,7 @@ pipeline {
conclusion: 'SUCCESS',
name: 'Rust CI',
summary: 'rust_autobadges passed CI.',
text: 'Formatting, tests, Clippy and release build completed successfully.',
text: 'Cargo audit, dependency policy, formatting, tests, Clippy and release build completed successfully.',
title: 'Build Successful'
)
}
@ -99,7 +140,7 @@ pipeline {
conclusion: 'FAILURE',
name: 'Rust CI',
summary: 'rust_autobadges failed CI.',
text: 'One or more Rust checks failed. See the Jenkins log.',
text: 'Cargo audit, dependency policy, or another Rust check failed. See the Jenkins log.',
title: 'Build Failed'
)
}
@ -109,9 +150,9 @@ pipeline {
conclusion: 'ACTION_REQUIRED',
name: 'Rust CI',
summary: 'rust_autobadges CI is unstable.',
text: 'The Jenkins build completed with an unstable status.',
text: 'Cargo audit, dependency policy, or another Rust check completed with an unstable status.',
title: 'Build Unstable'
)
}
}
}
}

View File

@ -3,6 +3,23 @@
Runs cargo-tarpaulin to generate coverage and automatically create a badges/ folder with the generated coverage.svg, test.svg and version.svg
## Dependency security and policy
CI pins `cargo-audit` 0.22.2 and `cargo-deny` 0.20.2. Run the same supply-chain gates locally from the repository root:
```sh
cargo audit --deny warnings
cargo deny check
```
Both commands require network access so they can refresh RustSec advisory and crates.io registry data. A failed refresh is an error; CI does not silently accept stale data.
`cargo audit` checks the tracked `Cargo.lock` for RustSec vulnerabilities, unmaintained or unsound advisories, and yanked packages. It is limited to advisories present in RustSec and cannot detect undisclosed vulnerabilities or assess source-code behavior.
`cargo deny` enforces `deny.toml`: only the licenses used by the current dependency graph are allowed (with a confidence threshold of 0.8), wildcard requirements are denied, duplicate versions are reported as warnings, unknown registries and Git sources are denied, crates.io is the only allowed registry, and no Git sources are allowed. It builds the graph with all features enabled. Advisory ignores, crate bans, duplicate skips, license exceptions, and license clarifications start empty. The tool validates dependency metadata and known advisories; it is not a source-code or runtime scanner.
No other hardening tools are in scope for these CI gates.
# Usage
```

32
deny.toml Normal file
View File

@ -0,0 +1,32 @@
[graph]
all-features = true
[advisories]
ignore = []
[licenses]
allow = [
"0BSD",
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"MIT",
"Unicode-3.0",
"Unlicense",
]
confidence-threshold = 0.8
exceptions = []
clarify = []
[bans]
multiple-versions = "warn"
wildcards = "deny"
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

@ -1,4 +1,4 @@
//! Basic badge generation using badge-maker and cargo-tarpaulin
//! Basic badge generation using Shields-compatible SVGs and cargo-tarpaulin
#![warn(clippy::missing_docs_in_private_items)]
// TODO: Testing and helper structs/methods

View File

@ -7,7 +7,7 @@ use std::{
};
use anyhow::Context;
use badge_maker::BadgeBuilder;
use badge_maker_rs::{BadgeOptions, Color, Style, make_badge};
use indicatif::{MultiProgress, ProgressBar};
use xshell::Shell;
@ -31,10 +31,10 @@ pub fn load_status(args: &CLIArgs) -> LastRuns {
let _ = args; // Always try to load from disk
if let Ok(mut f) = File::open(".run_status.toml") {
let mut content = String::new();
if f.read_to_string(&mut content).is_ok()
&& let Ok(deserde) = toml::from_str(&content)
{
return deserde;
if f.read_to_string(&mut content).is_ok() {
if let Ok(deserde) = toml::from_str(&content) {
return deserde;
}
}
}
LastRuns::default()
@ -174,7 +174,7 @@ pub fn run_version(sh: &Shell, pb: ProgressBar, args: &CLIArgs) -> Result<(), an
// Ok(())
// }
/// Write the badge to a specific directory using badge-maker
/// Write the badge to a specific directory
pub fn write_badge(
name: &str,
value: &str,
@ -182,14 +182,14 @@ pub fn write_badge(
test_name: &str,
args: &CLIArgs,
) -> Result<(), anyhow::Error> {
let svg = BadgeBuilder::new()
.label(name)
.message(value)
.color_parse(color)
.style(badge_maker::Style::Plastic)
.build()
.context("Running badge-maker to export the badge")?
.svg();
let svg = make_badge(
&BadgeOptions::new(value)
.label(name)
.color(color.parse::<Color>().context("Parsing badge color")?)
.style(Style::Plastic)
.build(),
)
.context("Rendering badge SVG")?;
let mut f = File::create(format!("{}/{}.svg", args.output, test_name)).unwrap();
write!(f, "{}", svg).context("Writing badge")?;