Skip to content

Enhancement: Use SBOM generated by Cargo #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SDAChess opened this issue Mar 18, 2025 · 6 comments
Open

Enhancement: Use SBOM generated by Cargo #192

SDAChess opened this issue Mar 18, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@SDAChess
Copy link

Hello,

With the merge of the Cargo SBOM into Cargo Nightly (rust-lang/cargo@7ea222d), it would be a valuable addition to the cargo-auditable code to ingest the dependencies from the generated SBOM.

It would probably solve a lot of common issues related to cargo metadata command.

I think cargo-auditable is still very relevant in generating the SBOMs from tools like syft when using containers that have their own dependencies and would love to see this work in cargo-auditable.

let me know if there is anything I could do to help this effort, if you need help with contributions especially.

@bjorn3
Copy link

bjorn3 commented Mar 18, 2025

I think the Cargo SBOM is produced after compiling a crate, while cargo-auditable needs to know it before compiling the crate to be able to inject an object file with the sbom when linking.

@Shnatsel
Copy link
Member

Yes, this is absolutely on my radar, both for cargo-auditable and cargo-cyclonedx. It would indeed work around all the issues with cargo-metadata.

I am currently seeking funding to be able to work full-time on cargo-auditable and cargo-cyclonedx for a while, specifically to implement this. But I'd be happy to accept a pull request that implements this as well.

@Shnatsel
Copy link
Member

Shnatsel commented Mar 18, 2025

Regarding the time when the SBOM is written:

I specifically called out in the RFC for this functionality that the SBOM has to be written before the crate is actually compiled to be usable to cargo-auditable. I've checked just now, and the SBOM does seem to be generated before the crate is compiled.

Here's a quick Linux-only test to prove that the native SBOM is usable for cargo-auditable:

Name this wrapper.sh and put it in your home directory:

#!/bin/sh

env > "$HOME"/env.dump
cp "$CARGO_SBOM_PATH" "$HOME"
"$@"

And run this on your Cargo project: cargo clean; RUSTC_WORKSPACE_WRAPPER="$HOME"/wrapper.sh CARGO_BUILD_SBOM=true cargo +nightly build -Z sbom

If it all worked, you will see env.dump and a SBOM JSON file in your home directory.

The script ignores multi-target crates for simplicity, so best run this on a "hello world".

@Shnatsel Shnatsel added the enhancement New feature or request label Mar 18, 2025
@SDAChess
Copy link
Author

I am currently seeking funding to be able to work full-time on cargo-auditable and cargo-cyclonedx for a while, specifically to implement this. But I'd be happy to accept a pull request that implements this as well.

Will ask around if funding is available for such a project from our company.

I specifically called out in the rust-lang/rfcs#3553 that the SBOM has to be written before the crate is actually compiled to be usable to cargo-auditable. I've checked just now, and the SBOM does seem to be generated before the crate is compiled.

Good to know! Will try and see if that works

@Shnatsel
Copy link
Member

That might not be needed, if we're lucky. I've already found an entity that is quite enthusiastic about funding this work. We'll see if it converts into actual funding. Once it's clear if this works out or falls through, I'll let you know.

@arlosi
Copy link

arlosi commented Apr 17, 2025

Please let me know if there are issues using Cargo's SBOM support in cargo-auditable.

Having more projects (especially OSS projects) using the feature gets us closer to stabilization in Cargo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants