Support multiple configurable OSV data sources - #7113
sahibamittal wants to merge 8 commits into
Conversation
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 24 |
🟢 Coverage 89.33% diff coverage · +0.00% coverage variation
Metric Results Coverage variation ✅ +0.00% coverage variation (-1.00%) Diff coverage ✅ 89.33% diff coverage (70.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (8e0f33f) 44902 39270 87.46% Head commit (501058f) 44956 (+54) 39319 (+49) 87.46% (+0.00%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#7113) 75 67 89.33% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
nscuro
left a comment
There was a problem hiding this comment.
Mostly looks good with a few issues to fix and tweaks to make.
But this also introduces a new hazard where multiple feeds can contribute information for the same vulnerability. They'd override each other's data because our data model (i.e. VULNERABILITY.SOURCE column) is not granular enough to discern "OSV" from "OSV, feed XYZ". Should be documented.
Separately, so you know of any public OSV feed that this could be tested with? I checked Chainguard but they appear to use a different feed format that OSV? https://packages.cgr.dev/chainguard/osv/all.json
| if (currentDataSource == null) { | ||
| throw new IllegalStateException("No current data source to mark processed"); | ||
| } | ||
| currentDataSource.markProcessed(bom); |
There was a problem hiding this comment.
MirrorVulnDataSourceActivity buffers up to 25 BOVs before marking them as processed. If during this buffering currentDataSource has transitioned from source A to source B, all BOVs are attributed to source B.
| for (final var source : config.getSources()) { | ||
| if (source.getName() == null || source.getName().isBlank()) { | ||
| throw new InvalidRuntimeConfigException("No data source name provided"); | ||
| } | ||
| if (!source.isEnabled()) { | ||
| continue; | ||
| } | ||
| if (source.getDataUrl() == null) { | ||
| throw new InvalidRuntimeConfigException("No data URL provided"); | ||
| } | ||
| if (source.getEcosystems() == null || source.getEcosystems().isEmpty()) { | ||
| throw new InvalidRuntimeConfigException("At least one ecosystem must be specified"); | ||
| } |
There was a problem hiding this comment.
Add a validation that no duplicate source names can exist, so sources can't corrupt each other's watermarks etc.
| try { | ||
| dataSource.close(); | ||
| } catch (final Exception e) { | ||
| LOGGER.warn("Failed to close data source: {}", dataSource, e); |
There was a problem hiding this comment.
OsvVulnDataSource doesn't implement toString so this will log something like OsvVulnDataSource@1a2b3c. Did you mean to call dataSource.getDataSourceName()?
| "name": { | ||
| "type": "string", | ||
| "title": "Name", | ||
| "description": "The name of the OSV data source.", | ||
| "minLength": 1 | ||
| }, |
There was a problem hiding this comment.
This is a free-text string that is used in watermark keys and other places. We should restrict this to a certain length and characters.
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| @WireMockTest |
| /** | ||
| * @since 5.0.0 | ||
| */ | ||
| final class OsvCompositeVulnDataSource implements VulnDataSource { |
There was a problem hiding this comment.
Consider adding the name of the current source to SLF4J's MDC so log statements show what source is currently being processed. Must be cautious though that the new MDC field doesn't leak, so probably best to only set it around calls to currentDataSource.
| "format": "uri" | ||
| }, | ||
| "ecosystems": { | ||
| "sources": { |
There was a problem hiding this comment.
Nit: consider using the term "feed" for this instead, i.e. users would be consuming from the default and the Chainguard feeds using the OSV data source.
"source" is a bit overloaded since the overarching thing is already a source, vulnerabilities also have a source field.
Docs updated DependencyTrack/docs#237
Not likely public, they provide OSV feed via API which is auth protected (via token). |
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
Signed-off-by: Sahiba Mittal <sahiba.mittal@citi.com>
Description
OsvVulnDataSourceper enabled source, namespace watermark keys per source name.Addressed Issue
Closes #6331
Additional Details
Frontend: DependencyTrack/frontend#1783
Docs update: DependencyTrack/docs#237
Checklist
docs/adr/