Skip to content
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

New option to only return outdated components and/or only direct dependencies in the ComponentResource #2568

Merged
merged 3 commits into from Jun 28, 2023

Conversation

walterdeboer
Copy link

@walterdeboer walterdeboer commented Mar 6, 2023

Description

Added onlyOutdated ApiParam and onlyDirect ApiParam to /v1/component/project endpoind to only show outdated components and/or only direct dependencies

Addressed Issue

closes #2567, adresses #1833

Additional Details

Only direct dependencies are reported when onlyOutdated is true. Also added a directDepencies switch for those who want to overwrite them in their project

image

image

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@walterdeboer walterdeboer changed the title Feature/2567 New option to only return outdated components in the ComponentResource Mar 6, 2023
@UWollesen
Copy link

Thank you for this feature. But you can actually upgrade indirect dependencies. In Gradle projects you can force versions of transitive dependencies. Of course you have to test the compatibility to your direct dependencies but sometimes it's the only way to get rid of some known vulnerabilities. So maybe showing of transitive dependencies or another switch to filter them would be a nice idea.

@walterdeboer
Copy link
Author

walterdeboer commented Mar 29, 2023 via email

@UWollesen
Copy link

No, I meant that I want to see all outdated dependencies, direct and transitive. ;)
And here is the link to the documentation of this Gradle feature: https://docs.gradle.org/current/userguide/dependency_constraints.html

@walterdeboer
Copy link
Author

walterdeboer commented Mar 30, 2023

Oh sorry, of course. I was under the temporary illusion this functionality already existed.. I'll add an extra switch 👍

@UWollesen
Copy link

Thank you very much. This will help a lot.

@walterdeboer walterdeboer changed the title New option to only return outdated components in the ComponentResource New option to only return outdated components and/or only direct dependenncies in the ComponentResource Mar 31, 2023
@nscuro nscuro added this to the 4.9 milestone Apr 18, 2023
@msymons
Copy link
Member

msymons commented Apr 27, 2023

@walterdeboer, following the release of v4.8.0, this PR now has conflicts that need to be resolved before it can be merged. Please can you fix things? Then the PR can be reviewed.

…ect dependencies of the project

Signed-off-by: Walter de Boer <walterdeboer@dbso.nl>
final PaginatedResult result;
String querySring ="SELECT FROM org.dependencytrack.model.Component WHERE project == :project ";
if (filter != null) {
querySring += " && (project == :project) && name.toLowerCase().matches(:name)";
}
if (onlyOutdated) {
// Components are considered outdated when metadata does exists, but the version is different than latestVersion
// Different should always mean version < latestVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

@walterdeboer @nscuro have we given any thought to latest version in a repo may be a BETA vs "prod/GA/GTM/stable" code? if the version we have is the last stable release, but the repo is showing a beta release...do we want to flag that as outdated?

Copy link
Member

Choose a reason for hiding this comment

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

@melba-lopez That's a good point, and I fear it is somewhat subjective. That said, the focus is on flagging risk, so the question becomes "am I at risk of being outdated when there's a new BETA version available?". Unless the latest stable version has risky vulns (which would be flagged separately), relying on BETA software in itself would be an operational risk.

What @walterdeboer is trying to solve here is risk being flagged despite there not being any sane way forward (no stable version to update to).

An extension of this feature could be to capture both latest stable and latest unstable version from remote repositories, and then letting the users decide what they want to consider "latest".

public PaginatedResult getComponents(final Project project, final boolean includeMetrics, final boolean onlyOutdated) {
return getComponentQueryManager().getComponents(project, includeMetrics, onlyOutdated);
public PaginatedResult getComponents(final Project project, final boolean includeMetrics, final boolean onlyOutdated, final boolean onlyDirect) {
return getComponentQueryManager().getComponents(project, includeMetrics, onlyOutdated, onlyDirect);
Copy link
Contributor

Choose a reason for hiding this comment

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

@walterdeboer Now seeing this PR. If i understand this right, this is enabling a new toggle switch to show only direct dependencies, hence why the previous PR #2537 has code comments about direct dependencies only?

Copy link
Author

Choose a reason for hiding this comment

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

I've mixed up the code in #2537 I hope i've got it right now...

Copy link
Author

Choose a reason for hiding this comment

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

I've mixed things up in PR #2537 with this one... I've pushed the right code in the other PR now

metaComponent.setLastCheck(new Date());
qm.persist(metaComponent);
} else {
// 500 components with no version metadata, all transitive dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

@walterdeboer Is the test here trying to state that if there is no metadata provided in the SBOM, or if a manually created component is made without metadata, that we assume it is transitive? Just trying to understand this comment here.

Copy link
Author

Choose a reason for hiding this comment

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

This has nothing to do with the SBOM, when DT detects new versions in the remote repository, it creates a RepositoryMetaComponent. The components here have no RepositoryMetaComponent, so they represent te most current versions

Signed-off-by: Walter de Boer <walterdeboer@dbso.nl>
@melba-lopez
Copy link
Contributor

@walterdeboer unfortunately the CI Test is failing 😞

image

Signed-off-by: Walter de Boer <walterdeboer@dbso.nl>
@walterdeboer
Copy link
Author

@walterdeboer unfortunately the CI Test is failing 😞

@nscuro Hmm, the PolicyEngineTest fails randomly. I hope I fixed it

@walterdeboer walterdeboer requested a review from nscuro June 27, 2023 20:03
Copy link
Contributor

@melba-lopez melba-lopez left a comment

Choose a reason for hiding this comment

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

Thanks for the quick turnaround for fixing the test failures!

Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

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

Thanks @walterdeboer, this is going to be super useful! 🚀

And of course thanks @melba-lopez for reviewing!

@nscuro nscuro merged commit a7e5122 into DependencyTrack:master Jun 28, 2023
10 checks passed
@nscuro nscuro changed the title New option to only return outdated components and/or only direct dependenncies in the ComponentResource New option to only return outdated components and/or only direct dependencies in the ComponentResource Jul 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New option to only return outdated components in the ComponentResource
5 participants