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

Sub 3621 vulnerabilities + workloads structs + enrichments #190

Merged
merged 18 commits into from
Dec 27, 2023
Merged

Conversation

RinaO1234
Copy link
Contributor

@RinaO1234 RinaO1234 commented Dec 25, 2023

Type

Enhancement


Description

  • Added new types and constants related to RiskFactor in armotypes/common.go.
  • Added a new function GetRiskFactors in armotypes/common.go which returns a list of unique risk factors for given control IDs.
  • Added new types and constants related to vulnerabilities in armotypes/vulnerabilitytypes.go.
  • Added new functions EnrichCVSSData, ParseCVSSVector, and UpdateExploitableField in armotypes/vulnerabilitytypes.go to enrich the CVSS data by parsing the CVSS vector and updating the exploitability field.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
2 files
common.go                                                                                                     
    armotypes/common.go

    Added new types and constants related to RiskFactor. Also, a
    new function GetRiskFactors has been added which returns a
    list of unique risk factors for given control IDs.

+40/-0
vulnerabilitytypes.go                                                                             
    armotypes/vulnerabilitytypes.go

    Added new types and constants related to vulnerabilities.
    Also, new functions EnrichCVSSData, ParseCVSSVector, and
    UpdateExploitableField have been added to enrich the CVSS
    data by parsing the CVSS vector and updating the
    exploitability field.

+182/-6

@codiumai-pr-agent-free codiumai-pr-agent-free bot added the enhancement New feature or request label Dec 25, 2023
Copy link

PR Description updated to latest commit (76aa2e0)

Copy link

PR Analysis

  • 🎯 Main theme: Enhancing the vulnerability and risk factor handling in the codebase
  • 📝 PR summary: This PR introduces new types and constants related to RiskFactor and vulnerabilities. It also adds new functions to enrich the CVSS data by parsing the CVSS vector and updating the exploitability field. The changes are primarily in armotypes/common.go and armotypes/vulnerabilitytypes.go.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 4, because the PR introduces a significant amount of new code and logic related to vulnerabilities and risk factors, which requires domain knowledge to review effectively.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the code is generally clean. However, it would be beneficial to add unit tests to ensure the new functions work as expected. Also, consider removing the 'todo' comments or addressing them before merging.

  • 🤖 Code feedback:
    relevant filearmotypes/common.go
    suggestion      

    Consider using a more efficient data structure for riskFactorSet. A slice could be used instead of a map to reduce memory usage and improve performance. [medium]

    relevant lineriskFactorSet := make(map[RiskFactor]bool)

    relevant filearmotypes/vulnerabilitytypes.go
    suggestion      

    The function EnrichCVSSData could be split into smaller functions to improve readability and maintainability. [medium]

    relevant linefunc EnrichCVSSData(vuln *Vulnerability) {

    relevant filearmotypes/vulnerabilitytypes.go
    suggestion      

    It would be better to handle the case where cvssInfo.Vector is an empty string at the beginning of the ParseCVSSVector function to avoid unnecessary computations. [important]

    relevant linefunc ParseCVSSVector(cvssInfo *CvssInfo) {

    relevant filearmotypes/vulnerabilitytypes.go
    suggestion      

    The UpdateExploitableField function could be improved by adding error handling or returning a boolean to indicate whether the operation was successful. [medium]

    relevant linefunc UpdateExploitableField(vuln *Vulnerability) {

    How to use

    Instructions

    To invoke the PR-Agent, add a comment using one of the following commands:
    /review: Request a review of your Pull Request.
    /describe: Update the PR title and description based on the contents of the PR.
    /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    /ask <QUESTION>: Ask a question about the PR.
    /update_changelog: Update the changelog based on the PR's contents.
    /add_docs: Generate docstring for new components introduced in the PR.
    /generate_labels: Generate labels for the PR based on the PR's contents.
    see the tools guide for more details.

    To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
    For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
    To list the possible configuration parameters, add a /config comment.

Comment on lines 17 to 27
var RiskFactorMapping = map[string]RiskFactor{
"C-0256": RiskFactorInternetFacing,
"C-0046": RiskFactorPrivileged,
"C-0057": RiskFactorPrivileged,
"C-0255": RiskFactorSecretAccess,
"C-0257": RiskFactorDataAccess,
"C-0038": RiskFactorHostAccess,
"C-0041": RiskFactorHostAccess,
"C-0044": RiskFactorHostAccess,
"C-0048": RiskFactorHostAccess,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is better to put this mapping in the BL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not sure whether it's the only place we need it

@@ -9,11 +21,175 @@ type VulnerabilityJobParams struct {
JobID string `json:"jobID,omitempty"`
}

type VulnerabilityWorkload struct {
Id string `json:"id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What is ID?
Workload unique identifiers is a combination of cluster, namespace, kind, name
We do not have GUID for this element

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have wlid

Id string `json:"id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Type string `json:"type"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also here I was confused because they changed it in ui to kind

armotypes/vulnerabilitytypes.go Outdated Show resolved Hide resolved
TopCves []TopCveDetails `json:"topCves"`
}

type TopCveDetails struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why Top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fetching top is the same as fetching the whole cves list? the goal is to avoid fetching redundant data

Copy link
Contributor

Choose a reason for hiding this comment

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

in my query i bring all cves by severity

Copy link
Contributor

Choose a reason for hiding this comment

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

We fetch all cves name sorted by severity according to the filter (if only critical is on so will be the list of CVEs)

Name string `json:"name"`
}

type VulnerabilitiesImage struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be container

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we show images in UI not containers

Copy link
Contributor

Choose a reason for hiding this comment

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

But an image does not have a container and cluster
a container has an image and cluster

Comment on lines 67 to 68
WorkloadsIds []string `json:"wlids"`
NameSpace string `json:"namespace"`
Copy link
Contributor

Choose a reason for hiding this comment

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

How can we have many wlids and one namespace and container ?

Comment on lines 63 to 64
ImageTag string `json:"imageTag"`
ImageHash string `json:"imageHash"`
Copy link
Contributor

Choose a reason for hiding this comment

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

component should have many images

}

// EnrichCVSSData enriches the CVSS data by parsing the CVSS vector and updating the exploitability field
func EnrichCVSSData(vuln *Vulnerability) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am ot sure armo types is a good place for these functions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are we sure that enrichment will happen only in BL? I thought about having it in common place

Comment on lines 88 to 89
EpssInfo EpssInfo `json:"epssInfo"`
CisaKevInfo CisaKevInfo `json:"cisaKevInfo"`
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe inline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inline means the fields are under the object, here we want it as inner feild


type CisaKevInfo struct {
// todo : verify tooltip and additional feilds
Date time.Time `json:"date"`
Copy link
Contributor

Choose a reason for hiding this comment

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

missing fields:

DateAdded                  string `json:"dateAdded"`
DueDate                    string `json:"dueDate"`
KnownRansomwareCampaignUse string `json:"knownRansomwareCampaignUse"`
Notes                      string `json:"notes"`

also if possible change the type to string, otherwise we will need to manually format each item during the enrichment task

Name string `json:"name"`
}

type VulnerabilitiesImage struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

But an image does not have a container and cluster
a container has an image and cluster

TopCves []TopCveDetails `json:"topCves"`
}

type TopCveDetails struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

We fetch all cves name sorted by severity according to the filter (if only critical is on so will be the list of CVEs)

Copy link
Contributor

@avrahams avrahams left a comment

Choose a reason for hiding this comment

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

approved by mistake

@@ -9,11 +20,100 @@ type VulnerabilityJobParams struct {
JobID string `json:"jobID,omitempty"`
}

type VulnerabilityWorkload struct {
Wlid string `json:"wlid"`
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not have a wlid in container scan
let's drop this field we do not need it - a workload id is a combination of cluster namespace kind and name

}

type SeverityDetails struct {
Total int `json:"total"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to put the counter as fields
like CriticalCount etc
how do you send a sort by SeverityStats[Critical].total
it is much simpler to sort by criticalCount:desc,hightCount:desc ...

if we do that than maybe we can make all this SeverityStats simpler like map[string][]string (and name it CEVs)

IsRCE bool `json:"isRCE"`
Links []string `json:"links"`
Description string `json:"description"`
Id string `json:"id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

the cve id is internal to the dal no need to add it

}

type ImagePathInfo struct {
WorkloadId string `json:"wlid"`
Copy link
Contributor

Choose a reason for hiding this comment

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

no wlid in container scan it is only for posture
We have workload hash but it is just combination of cluster, namespace ,kind, name, container-name

CveNames []string `json:"topCves"`
}

type ImagePathInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

container name

ClusterName string `json:"clusterName"`
ClusterShortName string `json:"clusterShortName"`
CustomerGUID string `json:"customerGUID"`
ImagesCount int `json:"imagesCount"`
Copy link
Contributor

Choose a reason for hiding this comment

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

CriticalCount     int
HighCount         int
MediumCount       int
LowCount          int
ImagesCount       int
RiskControlsCount int

Copy link
Contributor

Choose a reason for hiding this comment

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

LastScanTime time.Time

@RinaO1234 RinaO1234 merged commit 757c589 into main Dec 27, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

4 participants