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

feat(issueVariant): allow for creation of issue variant with only a severity rating #362

Merged
merged 7 commits into from
Nov 19, 2024

Conversation

BlakePatterson
Copy link
Collaborator

Description

As part of the Openstack scanner development, we needed to be able to create issue variants with a severity that just has a rating and no cvss vector.

This PR adds a "rating" field to SeverityInput of type SeverityValues and also adds logic throughout the resolver implementation to handle the separate cases of whether a vector has been passed in SeverityInput or just a rating. There is also a new query in the queryCollection/issueVariant folder for the case of creating a query with only a severity rating and no vector.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

I created a new query for the case of creating an issue variant with only a severity rating and added a new e2e test case for it. I also updated any tests involving queries that contained SeverityInput wherever necessary.

All tests passed locally, and I also tested various queries in the playground to ensure issue variant creation worked.

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@@ -150,6 +150,26 @@ type Cursor struct {
Limit int
}

func NewSeverityFromRating(rating SeverityValues) Severity {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a comment where this values come from. There might also be an adjustment depending on the CVSS version.
https://nvd.nist.gov/vuln-metrics/cvss

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a comment about the CVSS specification with links, but I'm not sure how I would handle doing adjustments based on which CVSS specification since there is no information being passed other than the rating. Should I just do something else here instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For now that's okay

"description": evidence.Description,
"severity": model.SeverityInput{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed in the evidence test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed this now as it's not needed and works without the severity input now.

"secondaryName": issueVariant.SecondaryName,
"severity": model.SeverityInput{
Rating: &model.AllSeverityValues[0],
Vector: &issueVariant.Severity.Cvss.Vector,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we check if rating and vector match?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added logic now to check if rating & vector don't match when they are both passed. If they match it works like normal, if not the issue variant creation errors out.

Copy link
Collaborator

@drochow drochow left a comment

Choose a reason for hiding this comment

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

LGTM, but i would suggest the below 👍

return entity.Severity{}
}
if severity.Rating != nil && severity.Vector != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a vector is there, let's take the vector by default and simply overrule the "normal" severity.

@MR2011 @dorneanu WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated it now so that it just uses the vector and ignores the rating when both are passed.

logrus.WithError(err).WithField("request", req).Fatalln("Error while unmarshaling")
}

Expect(string(*respData.IssueVariant.Severity.Value)).To(Equal(issueVariant.Severity.Value))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should check if the vector is empty after updating the rating

@MR2011 MR2011 merged commit 8ba6e3f into main Nov 19, 2024
7 checks passed
@MR2011 MR2011 deleted the BlakePatterson/issue-361/issue-variant-rating-creation branch November 19, 2024 13:47
dustindemmerle added a commit that referenced this pull request Nov 25, 2024
…everity rating (#362)

* feat(issueVariant): added optional rating field to severity input

* feat(issueVariant): added comments and check for when rating doesn't match vector

* fix(tests): removed severity input from tests where not needed

* feat(issueVariant): changed iv creation to just use vector when both rating and vector are passed

* feat(issueVariant): changed update handler for iv to overwrite existing vector if passed and added test

* adding test

---------

Co-authored-by: dustindemmerle <[email protected]>
Co-authored-by: Michael Reimsbach <[email protected]>
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.

feat(issueVariant): Allow for issue variant creation with just severity rating
4 participants