Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

ci(rust): audit ai-gateway and native addon dependencies with cargo-deny and cargo-machete (#18882)

Tobias Wochingera15686861abc
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 3ff5f0cbc0..c06c79d703 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -33,3 +33,20 @@ updates:
rust-dependencies:
patterns:
- "*"
+
+ # Dependabot resolves without the clickhouse overlay from
+ # packages/native/scripts/prepare-clickhouse-rs.sh, so its Cargo.lock adds
+ # `source` and `checksum` lines to the `clickhouse` entry. Drop those two
+ # lines before merging, or CI's `--locked` builds reject the lockfile.
+ - package-ecosystem: cargo
+ directory: "/packages/native"
+ assignees:
+ - "sumerman"
+ schedule:
+ interval: "weekly"
+ cooldown:
+ default-days: 7
+ groups:
+ rust-dependencies:
+ patterns:
+ - "*"
diff --git a/.github/workflows/licencecheck.yml b/.github/workflows/licencecheck.yml
index 9b9eb3f4d6..99ec29e1ad 100644
--- a/.github/workflows/licencecheck.yml
+++ b/.github/workflows/licencecheck.yml
@@ -11,11 +11,13 @@ on:
permissions:
contents: read
- checks: write # Needed to create a check run for the license compliance check results
jobs:
license_check:
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ checks: write # Needed to create a check run for the license compliance check results
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -66,3 +68,58 @@ jobs:
run: echo "::error::${STEPS_LICENSE_CHECK_REPORT_OUTPUTS_REPORT}"
env:
STEPS_LICENSE_CHECK_REPORT_OUTPUTS_REPORT: ${{ steps.license_check_report.outputs.report }}
+
+ rust_license_check:
+ # Same policy as license_check, applied to the Rust crates in the
+ # ai-gateway binary and in the native addon shipped in the worker image;
+ # the shared allow-list lives in the repository-root deny.toml.
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Install pinned Rust toolchains
+ run: |
+ (cd ai-gateway && rustup toolchain install --no-self-update)
+ (cd packages/native && rustup toolchain install --no-self-update)
+
+ - name: Install cargo-deny
+ uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
+ with:
+
+ - name: Check ai-gateway dependency licenses
+ working-directory: ai-gateway
+ run: cargo deny --locked check licenses
+
+ # Cargo.lock is resolved against the patched clickhouse overlay.
+ - name: Prepare patched clickhouse crate for the native addon
+ working-directory: packages/native
+ run: sh scripts/prepare-clickhouse-rs.sh
+
+ - name: Check native addon dependency licenses
+ working-directory: packages/native
+ run: cargo deny --locked check licenses
+
+ # License checks are not required for merging, so a failure on main would
+ # otherwise go unnoticed. PR failures already show on the PR.
+ notify_failure:
+ needs: [license_check, rust_license_check]
+ if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ actions: read # notify-slack-failure reads the failed jobs' logs
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - name: Notify Slack
+ uses: ./.github/actions/notify-slack-failure
+ with:
+ message: "❌ License check failed on ${{ github.ref_name }}"
+ webhook-url: ${{ secrets.SLACK_CI_FAILURE_WORKFLOW_WEBHOOK_URL }}
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index 22a8696f7c..6843cfbff0 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -198,6 +198,17 @@ jobs:
run: cargo fmt --all -- --check
- name: Lint Rust targets
run: cargo clippy --locked --all-targets -- -D warnings
+ - uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
+ with:
+ - name: Check for unused Rust dependencies
+ run: cargo machete
+ # Licenses also run in licencecheck.yml next to the pnpm license check,
+ # but only all-ci-passed gates merges, so they are enforced here too.
+ # Advisories come from Dependabot alerts, so a new advisory never blocks
+ # merges.
+ - name: Check Rust dependency bans, licenses, and sources
+ run: cargo deny --locked check bans licenses sources
- name: Run Rust tests
run: bash "$GITHUB_WORKSPACE/scripts/ci/retry-on-merge-queue.sh" cargo test --locked
- name: Build runtime image
@@ -282,6 +293,14 @@ jobs:
# above, so they run outside that invocation (ai-gateway in its own job).
- name: lint native addon (rustfmt, clippy)
run: pnpm --filter @langfuse/native run lint
+ - name: Install Rust dependency checkers
+ uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
+ with:
+ - name: check native addon for unused Rust dependencies
+ run: pnpm --filter @langfuse/native run rust:unused-deps
+ - name: check native addon Rust dependency bans, licenses, and sources
+ run: pnpm --filter @langfuse/native run rust:deny bans licenses sources
- name: typecheck
run: pnpm run typecheck --filter=!ai-gateway
diff --git a/ai-gateway/Cargo.lock b/ai-gateway/Cargo.lock
index 4e6c5e5eb0..ea0e37c9b9 100644
--- a/ai-gateway/Cargo.lock
+++ b/ai-gateway/Cargo.lock
@@ -1316,9 +1316,9 @@ dependencies = [
[[package]]
name = "rustls"
-version = "0.23.45"
+version = "0.23.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634"
+checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
dependencies = [
"aws-lc-rs",
"once_cell",
diff --git a/ai-gateway/package.json b/ai-gateway/package.json
index b1a3f99802..59ecb3d81a 100644
--- a/ai-gateway/package.json
+++ b/ai-gateway/package.json
@@ -13,6 +13,8 @@
"rust:lint": "cargo fmt --all -- --check && cargo clippy --locked --all-targets -- -D warnings",
"test": "pnpm run rust:test",
"rust:test": "cargo test --locked",
+ "rust:deny": "cargo deny --locked check",
+ "rust:unused-deps": "cargo machete",
"format": "cargo fmt --all"
},
"devDependencies": {
diff --git a/deny.toml b/deny.toml
new file mode 100644
index 0000000000..2166b6a584
--- /dev/null
+++ b/deny.toml
@@ -0,0 +1,53 @@
+# cargo-deny configuration: https://embarkstudios.github.io/cargo-deny/
+# Shared by the Rust crates in this repository, ai-gateway and packages/native;
+# cargo-deny finds it by searching parent directories of the crate. Run with
+# `pnpm --filter ai-gateway run rust:deny` or
+# `pnpm --filter @langfuse/native run rust:deny`.
+
+[graph]
+all-features = true
+
+[advisories]
+# RustSec advisories. Vulnerabilities and unsound crates fail the check; add an
+# entry with a reason here only after confirming an advisory does not apply.
+yanked = "deny"
+ignore = []
+
+[licenses]
+confidence-threshold = 0.93
+# Same policy as .github/workflows/licencecheck.yml for pnpm packages: no weak,
+# strong, or network copyleft (LGPL, MPL, EPL, GPL, AGPL, SSPL, ...), since both
+# crates are open source and ship to self-hosters as binaries: the gateway as a
+# statically linked executable, the native addon inside the worker image.
+# This is an allow-list, so source-available or non-commercial licenses (BUSL,
+# Elastic, CC-BY-NC, ...) and unknown licenses also fail. A dual-licensed crate
+# passes when one of its options is listed here.
+allow = [
+ "0BSD",
+ "Apache-2.0",
+ "Apache-2.0 WITH LLVM-exception",
+ "BSD-2-Clause",
+ "BSD-3-Clause",
+ "CC0-1.0",
+ "CDLA-Permissive-2.0",
+ "ISC",
+ "MIT",
+ "MIT-0",
+ "Unicode-3.0",
+ "Unlicense",
+ "Zlib",
+]
+
+[licenses.private]
+ignore = true
+
+[bans]
+multiple-versions = "warn"
+wildcards = "deny"
+allow-wildcard-paths = true
+
+[sources]
+unknown-registry = "deny"
+unknown-git = "deny"
+allow-registry = ["https://github.com/rust-lang/crates.io-index"]
+allow-git = []
diff --git a/packages/native/package.json b/packages/native/package.json
index 691b4bc972..654baed0de 100644
--- a/packages/native/package.json
+++ b/packages/native/package.json
@@ -25,7 +25,9 @@
"lint:fix": "pnpm run rust:lint:fix",
"rust:lint:fix": "pnpm run prepare-clickhouse-rs && cargo fmt && cargo clippy --all-targets --fix --allow-dirty -- -D warnings",
"test": "pnpm run rust:test",
- "rust:test": "pnpm run prepare-clickhouse-rs && cargo test --locked --features napi/dyn-symbols"
+ "rust:test": "pnpm run prepare-clickhouse-rs && cargo test --locked --features napi/dyn-symbols",
+ "rust:deny": "pnpm run prepare-clickhouse-rs && cargo deny --locked check",
+ "rust:unused-deps": "cargo machete"
},
"napi": {
"binaryName": "langfuse-native",