# Add cargo-deny to a Rust Library Workspace

Yes. An agent writes a deny.toml that passes on your workspace's real dependency graph, adds a deny job beside your existing audit and opens a PR with the output.

[Run this on Rush](https://cloud.getrush.ai/run/add-cargo-deny/rust-library/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the workspace and the CI gate it has to fit into. In a repository shaped like rust-lang/mdBook, `Cargo.toml` is a workspace with the root `mdbook` crate, `crates/*` (`mdbook-core`, `mdbook-driver`, `mdbook-html`, `mdbook-markdown`, `mdbook-preprocessor`, `mdbook-renderer`, `mdbook-summary`, `mdbook-compare`, `xtask`), an example preprocessor and a guide helper, all on `edition = "2024"` with `rust-version = "1.88.0"` and `license = "MPL-2.0"` inherited from the workspace, except `mdbook-html`, whose license field reads `MPL-2.0 AND Apache-2.0 AND BSD-3-Clause AND CC-BY-4.0 AND MIT AND OFL-1.1` because it ships fonts and vendored assets. `Cargo.lock` resolves 273 packages, and `pulldown-cmark` carries a comment saying not to update it because it is part of the public API. `.github/workflows/main.yml` already runs `cargo audit` in an `audit` job, `cargo semver-checks` from a downloaded release tarball in `check-version-bump`, clippy, rustfmt, typos, docs and a test matrix, and ends in a `success` gate job whose `needs` list is what branch protection requires. `.github/renovate.json5` schedules updates monthly and tracks the `cargo-semver-checks` version in the workflow with a custom regex manager, while `update-dependencies.yml` runs `cargo upgrade` on the first of the month.

The agent installs `cargo-deny` in the sandbox and runs `cargo deny check` with no config to see what the graph contains, then writes `deny.toml` from that output rather than from a template. `[licenses]` gets an `allow` list of exactly the license identifiers found in the 273 packages, with `OFL-1.1` and `CC-BY-4.0` either allowed or added as an `exceptions` entry for `mdbook-html` alone, since they come from that crate's own assets and not from a dependency. `[bans]` sets `multiple-versions = "warn"` with a `skip` list for the duplicates the first run names, and `wildcards = "deny"`. `[sources]` allows crates.io only. For `[advisories]`, the agent proposes replacing the existing `audit` job with the deny job, since both read the same RustSec database and two jobs failing on one advisory is noise; it leaves that as a choice in the pull request and, if the maintainers prefer, disables the `advisories` check in `deny.toml` so the two do not overlap.

In `main.yml` it adds a `deny` job in the style of `check-version-bump`: download a pinned `cargo-deny` release tarball into `installed-bins`, add it to `GITHUB_PATH`, run `cargo deny check`. It adds `deny` to the `success` gate's `needs` list, because that list is what makes a job required, and extends `renovate.json5` with a second regex manager entry so Renovate bumps the `cargo-deny` version in the workflow the same way it bumps `cargo-semver-checks`. It does not touch `pulldown-cmark` or any dependency version; a license finding is answered in `deny.toml`, not with an upgrade.

Before opening the pull request it runs `cargo deny check` until it passes with the written config, runs `cargo test --workspace --locked` on the stable toolchain to show nothing else changed, and pastes the final `cargo deny check` output and the `cargo deny list` summary of licenses in the description, with a sentence for each `skip`, `exception` and allowed license.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add cargo-deny to this Rust workspace and open a pull request. Read Cargo.toml, every crates/*/Cargo.toml, Cargo.lock, .github/workflows/main.yml and .github/renovate.json5 first. Install cargo-deny in the sandbox and run cargo deny check with no config to see what the dependency graph contains, then write deny.toml from that output: a licenses allow list of exactly the identifiers present, with the asset licenses that only the mdbook-html crate's own license expression carries handled as an exception for that crate; bans with multiple-versions set to warn, a skip list for the duplicates the first run reports, and wildcards set to deny; sources allowing crates.io only; and for advisories, since CI already runs cargo audit, either disable the advisories check in deny.toml or propose removing the audit job, and say which you chose and why. Add a deny job to main.yml in the same style as the semver-checks job, downloading a pinned cargo-deny release tarball, and add the job to the success gate's needs list. Extend renovate.json5 with a regex manager entry that tracks the cargo-deny version in the workflow as the existing one tracks cargo-semver-checks. Do not change any dependency version. Run cargo deny check until it passes and cargo test --workspace --locked on stable, and paste the final check output and the license summary in the pull request description with one sentence per skip, exception and allowed license.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with a new `deny.toml`, a `deny` job and one more entry in the `success` gate's `needs` in `.github/workflows/main.yml`, and a second custom manager in `.github/renovate.json5`. If the agent proposed folding the advisory check into cargo-deny, the `audit` job is removed in the same diff and the description says so; otherwise `[advisories]` is disabled in `deny.toml` and both jobs stay. The description quotes the passing `cargo deny check`, the license summary, and the reasons behind every skip and exception.

The new job runs on the pull request, so the first enforced `cargo deny check` happens beside clippy, rustfmt, the test matrix and semver-checks, and the `success` gate waits for it. Renovate's next monthly run will offer the `cargo-deny` version bump through the new manager.

A reviewer reads the `allow` list against the project's own policy, decides whether `multiple-versions` should be `deny` once the skips are cleared, and confirms that `pulldown-cmark` and every other version in `Cargo.lock` is untouched.

## Run it on every monthly dependency update

Once `deny.toml` is merged, the check runs on every pull request, and the one most likely to trip it is the monthly `cargo upgrade` branch that `update-dependencies.yml` opens on the first of the month. That branch is pushed by a bot, and a bot sender fires no `github` trigger, so a maintainer starts the run with `POST /o/{org}/sessions` and `https://github.com/<owner>/<repo>/pull/<n>` in `resources`. The run reads the `cargo deny check` failure on the new graph, proposes the narrowest `deny.toml` change or names the crate to hold back, and posts that as a review comment on the pull request, as the prompt says.

For pull requests people open, an automation in the Project with a `github` trigger on `pull_request.opened` starts one run per pull request with the pull request as its context; the trigger has no path filter, so the prompt tells the run to stop unless the diff touches `Cargo.lock` or `deny.toml`. An automation has its own `max_runs_per_hour` cap, separate from any API key.

## Why run it on Rush?

A `deny.toml` written from a template is a guess about 273 crates' licenses and duplicates, and the first CI run shows where the guess was wrong. The agent runs the check against the real lockfile in its own sandbox first, writes the config from what the tool reports, and runs it again until it passes, so the file that lands is the one that already works. The allow list, the skips and the one crate-specific exception are each explained in the pull request, and every `cargo deny check` the agent ran is in the run's record.

Fitting into this repository's CI is half the job. A job that is not in the `success` gate's `needs` list is not required, a tool version that Renovate does not track goes stale, and a second advisory check beside `cargo audit` doubles every alert. The agent reads those conventions from the files and follows them, so the pull request is about policy and not about plumbing.

## Frequently asked questions

### Does this duplicate the existing cargo audit job?

It would, if both stayed on. `cargo deny check advisories` reads the same RustSec database as `cargo audit`. The agent either disables `[advisories]` in `deny.toml` and keeps the `audit` job, or proposes removing `audit` so one job covers advisories, licenses, bans and sources; the pull request says which and why, and the maintainers pick.

### How does it handle the mdbook-html license expression?

That crate's own `license` field names `OFL-1.1` and `CC-BY-4.0` for the fonts and assets it bundles. Those identifiers come from a workspace member, not a dependency, so the agent adds them as an `exceptions` entry for `mdbook-html` rather than allowing them for the whole graph, and says so in the config.

### Will it bump dependencies to clear duplicate versions?

No. The prompt forbids version changes, and `pulldown-cmark` in particular is pinned with a comment that it is part of the public API. Duplicates reported on the first run go into the `[bans] skip` list with the crate name, and clearing them is left to the monthly update flow.

### Why download a release tarball instead of cargo install?

Because that is how `main.yml` already installs `cargo-semver-checks`: a pinned tarball into `installed-bins`, added to `GITHUB_PATH`, which takes seconds where `cargo install` compiles for minutes on every run. Following the same pattern also lets Renovate track the version with a regex manager, as it does for semver-checks.

## More Rust library jobs

- [Add cargo-semver-checks to CI for a Rust Library](https://getrush.ai/run/add-cargo-semver-checks-to-ci/rust-library/)
- [Label Feature-Gated Items on docs.rs for a Rust Library](https://getrush.ai/run/add-docs-rs-metadata/rust-library/)
- [Add release-plz to a Rust Library](https://getrush.ai/run/add-release-plz/rust-library/)

## The same job on other stacks

- [Add cargo-deny to a Tokio Project](https://getrush.ai/run/add-cargo-deny/tokio/)
- [Add cargo-deny to a Rust Workspace](https://getrush.ai/run/add-cargo-deny/rust/)
- [Add cargo-deny to a Rust CLI's CI](https://getrush.ai/run/add-cargo-deny/rust-cli/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
