Skip to content

[K9VULN-9195] Add Cargo.toml matcher to resolve metadata for rust dependencies#96

Merged
rjcoulter22 merged 16 commits intomainfrom
rjcoulter/k9vuln-9195
Feb 3, 2026
Merged

[K9VULN-9195] Add Cargo.toml matcher to resolve metadata for rust dependencies#96
rjcoulter22 merged 16 commits intomainfrom
rjcoulter/k9vuln-9195

Conversation

@rjcoulter22
Copy link
Copy Markdown
Contributor

@rjcoulter22 rjcoulter22 commented Jan 7, 2026

🚀 Motivation

The SBOM generator was not capturing metadata such as file location and transtivity information for Rust dependencies, making it difficult to identify where direct dependencies are declared in Cargo.toml files.

📚 Documentation

Document Link or Detail
RFC N/A
Incident N/A
Jira Ticket K9VULN-9195

📝 Summary

This PR implements a Cargo.toml matcher for the Rust ecosystem to enrich package data with location evidence. At a high level the matcher takes in the dependencies we parse from the Cargo.lock file, and matches it against the user defined Cargo.toml file to try and resolve metadata for these dependencies (see this doc for details on these two files).

The new matcher:

  • Parses the Cargo.toml file to give us the different dependencies defined (regular, build, dev, workspace)
  • Processes these different dependency sections by trying to match it against the raw toml file to get dependency location data

🧪 Testing

  • New tests were added for new logic.
  • Existing tests were updated for new logic, and not only so that they pass!
  • Benchmark results prove that performance is the same or better.

🚧 Staging validation

  • Deployed and monitored using Datadog dashboards.
  • Proof that it works as expected, including profiling or UX screenshots.

🆘 Recovery

Notes for on-call - select only one:

  • The change can be rolled back.
  • Do not roll back. Why?:

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 7, 2026

Go test coverage report

Total test coverage: 90.4% (4396/4862)

Test coverage has changed in the current files, with 11 lines missing coverage.
file: uncovered: current coverage: base coverage:
pkg/lockfile/rust/match-cargo-toml.go 11 84.5% (60/71) /

@rjcoulter22 rjcoulter22 force-pushed the rjcoulter/k9vuln-9195 branch from 31414c3 to a8bcfac Compare January 7, 2026 19:14
@rjcoulter22 rjcoulter22 changed the title Add cargo matcher [K9VULN-9195] Support parsing rust dependency locations Jan 7, 2026
@rjcoulter22
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@DataDog DataDog deleted a comment from chatgpt-codex-connector bot Jan 7, 2026
@rjcoulter22 rjcoulter22 marked this pull request as ready for review January 7, 2026 19:59
@rjcoulter22 rjcoulter22 requested a review from a team as a code owner January 7, 2026 19:59
@DataDog DataDog deleted a comment from chatgpt-codex-connector bot Jan 7, 2026
@rjcoulter22
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@rjcoulter22 rjcoulter22 force-pushed the rjcoulter/k9vuln-9195 branch from d827fdf to 3bc234e Compare January 7, 2026 21:13
@rjcoulter22 rjcoulter22 changed the title [K9VULN-9195] Support parsing rust dependency locations [K9VULN-9195] Add Cargo.toml matcher to resolve metadata for rust dependencies Jan 9, 2026
@rjcoulter22
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Copy link
Copy Markdown
Contributor

@piloulacdog piloulacdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback related to tests:

  • to facilitate review examples, could we have,n the fixtures, always both the Cargo.toml and associated Cargo.lock. It would facilitate later tests and understanding as we know what A (Cargo.toml) should lead to B (Cargo.lock). Even if for some we might not use Cargo.lock, I think it's important for our understand to have both. An example here is that me who doesn't really know how A lead to B, I could quickly glance at the two files and quickly create the mental mapping. Having mostly only 1/2 makes it more complex.

  • Could we also create a "complex" test in cmd/datadog-sbom-generator/fixtures which would be covered by main_test.go

Copy link
Copy Markdown
Contributor

@piloulacdog piloulacdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we for sure make decision on what we support and what we don't when it comes to enrichment of Cargo.lock with Cargo.toml (ie, not supporting workspaces), we should make sure to clarify it here:

### Rust
#### Crates
- This tool only supports extracting packages from `Cargo.lock`.

@@ -0,0 +1,23 @@
[package]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add to this example:

  • same library, multiple version (based on the scope)
  • renamed library: example: serde09 = { package = "serde", version = "0.9" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the first but I think I will add the second in a separate task (or leave it to whoever picks up said task)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it might still be worth it listing it in the test case, and with a test that clearly state that we don't support it. Hopefully in the future we only have to fix the test, and not have to work on the fixture!

@rjcoulter22 rjcoulter22 force-pushed the rjcoulter/k9vuln-9195 branch 2 times, most recently from 6fdc821 to 7060b6b Compare January 21, 2026 20:10
@rjcoulter22
Copy link
Copy Markdown
Contributor Author

Before updating the README I want to align on what we want to support in this PR - I think for now we can leave off library aliasing and workspaces and create two separate tickets for each to do later

piloulacdog
piloulacdog previously approved these changes Jan 22, 2026
Copy link
Copy Markdown
Contributor

@piloulacdog piloulacdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving to not block.
But we should before merging:

  1. increase complexity of our integration case in rust (having the library name override: we should correctly not match it currently)
  2. update the readme to make sure that we explain what we do not support (workspace, version alias)

@rjcoulter22 rjcoulter22 merged commit 58935dd into main Feb 3, 2026
10 checks passed
@rjcoulter22 rjcoulter22 deleted the rjcoulter/k9vuln-9195 branch February 3, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants