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

Add Istio request handler and business logics for fetching Istio CVEs #984

Merged
merged 13 commits into from
Nov 14, 2022

Conversation

daynewlee
Copy link
Contributor

@daynewlee daynewlee commented Oct 19, 2022

Add functionalities of fetch Istio CVEs, converting Istio CVEs to responses and handling Istio CVE get requests.

@ghost
Copy link

ghost commented Oct 19, 2022

Images are ready for the commit at abc1e5c.

To use the images, use the tag 2.26.x-24-gabc1e5cb92.

@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch 2 times, most recently from 8193288 to f07e6ce Compare October 19, 2022 16:50
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch 4 times, most recently from f18bb0b to 8b08c6e Compare October 25, 2022 02:51
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch 5 times, most recently from a93bbcb to 8038896 Compare October 26, 2022 00:44
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 8038896 to b48d8ad Compare October 26, 2022 01:45
@daynewlee daynewlee requested review from c-du and RTann October 26, 2022 01:46
@daynewlee
Copy link
Contributor Author

daynewlee commented Oct 26, 2022

Manual test with http request

curl "https://localhost:8443/v1/orchestrator/istio/vulnerabilities/1.13.6" -k

{"scannerVersion":"2.26.x-15-g341eca297c","vulnerabilities":[{"name":"ISTIO-SECURITY-2022-006","description":"Ill-formed headers sent to Envoy in certain configurations can lead to unexpected memory access resulting in undefined behavior or crashing","link":"https://istio.io/latest/news/security/istio-security-2022-006/","metadataV2":{"publishedDateTime":"2022-07-26T00:00Z","lastModifiedDateTime":"","cvssV2":null,"cvssV3":{"vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H","score":5.9,"exploitabilityScore":2.2,"impactScore":3.6}},"fixedBy":"1.13.7","severity":"Moderate"}]}

@daynewlee daynewlee changed the title Personal/yli3/add istio service Add Istio request handler and business logics for fetching Istio CVEs Oct 27, 2022
Copy link
Collaborator

@RTann RTann left a comment

Choose a reason for hiding this comment

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

A few changes requested. Also, be sure to rebase to get the new *zip.Reader updates

tools/allowed-large-files Outdated Show resolved Hide resolved
proto/scanner/api/v1/orchestrator_scan_service.proto Outdated Show resolved Hide resolved

// GetIstioVulnerabilities returns Istio vulnerabilities for requested Kubernetes version.
func (s *serviceImpl) GetIstioVulnerabilities(_ context.Context, req *v1.GetIstioVulnerabilitiesRequest) (*v1.GetIstioVulnerabilitiesResponse, error) {
var err error
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: declare this closer to where it's used

Copy link
Collaborator

Choose a reason for hiding this comment

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

bump ^

api/v1/orchestratorscan/service.go Outdated Show resolved Hide resolved
}
version, err := convert.TruncateVersion(version)
if err != nil {
log.Warnf("Unable to convert version of %s - %v. Skipping...", version, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unable to convert Istio version etc

api/v1/convert/istio.go Outdated Show resolved Hide resolved
"github.com/stackrox/rox/pkg/stringutils"
v1 "github.com/stackrox/scanner/generated/scanner/api/v1"
stackroxTypes "github.com/stackrox/scanner/pkg/types"

Copy link
Collaborator

Choose a reason for hiding this comment

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

remove newline

)

// IstioVulnerabilities converts istio cve schema to vulnerability.
func IstioVulnerabilities(version string, istioVulns []types.Vuln) ([]*v1.Vulnerability, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to ever return an error, so no need for that return type

pkg/types/types.go Outdated Show resolved Hide resolved
pkg/types/types.go Outdated Show resolved Hide resolved
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 231ed03 to 95bcca4 Compare October 28, 2022 16:13
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch 3 times, most recently from f54d492 to 96b5f2a Compare November 7, 2022 20:04
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 4059e5b to 9301d72 Compare November 7, 2022 21:31
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 9301d72 to 807c953 Compare November 7, 2022 23:02
@daynewlee daynewlee enabled auto-merge (squash) November 8, 2022 16:34
@daynewlee daynewlee requested review from RTann and removed request for RTann November 8, 2022 16:58
Copy link
Collaborator

@RTann RTann left a comment

Choose a reason for hiding this comment

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

Almost there!

ScannerVersion: s.version,
}

getIstioVuln := func(version string) ([]*v1.Vulnerability, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs to be a closure. Why not just run these steps and then eventually set resp.Vulnerabilities = filterInvalidVulns(converted)

@@ -20,6 +20,34 @@ var (
patchRegex = regexp.MustCompile(`^[0-9]+\.[0-9]+\.([0-9]+)$`)
)

func TestGRPCGetIstioVulnerabilities(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it may be more worthwhile to give an Istio version and ensure we find specific vulnerabilities. For example, we know Istio verison 1.13.6 is affected by ISTIO-SECURITY-2022-007, which has a specific description and CVSS and is fixed by 1.13.9

@@ -0,0 +1,26 @@
package istioUtil
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit the directory and package name should be all lowercase: istioutil

)

// IstioIsAffected gets the fixed-by version for vStr in Istion vuln.
func IstioIsAffected(vStr string, vuln types.Vuln) (bool, string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can probably just rename to IsAffected since it's clear this is about Istio from the package name

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we pass in a version.Version instead of a string?


var vulns []types.Vuln
for _, vuln := range c.cache {
isAffected, _, _ := istioUtil.IstioIsAffected(version, vuln)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment why we ignore errors here?

@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 6c24339 to 8c49906 Compare November 11, 2022 17:09
@daynewlee daynewlee requested a review from RTann November 11, 2022 17:11
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch 9 times, most recently from 3b56631 to 27f2d4e Compare November 13, 2022 18:28
@daynewlee daynewlee requested a review from RTann November 13, 2022 23:24
@daynewlee daynewlee force-pushed the personal/yli3/addIstioService branch from 1d1e63f to abc1e5c Compare November 14, 2022 16:25
@openshift-ci
Copy link

openshift-ci bot commented Nov 14, 2022

@daynewlee: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-tests abc1e5c link false /test e2e-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Collaborator

@RTann RTann left a comment

Choose a reason for hiding this comment

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

a few minor nits. Going to approve to avoid having to do another review cycle, but please take a look at the suggestions

@@ -107,6 +110,29 @@ func (s *serviceImpl) GetKubeVulnerabilities(_ context.Context, req *v1.GetKubeV
return resp, nil
}

// GetIstioVulnerabilities returns Istio vulnerabilities for requested Kubernetes version.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Istio version

"github.com/stackrox/istio-cves/types"
)

// IsAffected gets the fixed-by version for vStr in Istion vuln.
Copy link
Collaborator

Choose a reason for hiding this comment

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

// IsAffected returns whether the given version of Istio is affected by the given vulnerability.
// If it is, then the fixed-by version is returned as well.

return nil
}
for _, vuln := range c.cache {
isAffected, _, error := istioutil.IsAffected(v, vuln)
Copy link
Collaborator

Choose a reason for hiding this comment

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

missed this before, sorry. Let's call this err instead, as error is the type

Comment on lines +29 to +37
c.cacheRWLock.RLock()
defer c.cacheRWLock.RUnlock()

var vulns []types.Vuln
v, err := version.NewVersion(vStr)
if err != nil {
log.Infof("Failed to get version: %s", vStr)
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
c.cacheRWLock.RLock()
defer c.cacheRWLock.RUnlock()
var vulns []types.Vuln
v, err := version.NewVersion(vStr)
if err != nil {
log.Infof("Failed to get version: %s", vStr)
return nil
}
var vulns []types.Vuln
v, err := version.NewVersion(vStr)
if err != nil {
log.Infof("Failed to get version: %s", vStr)
return nil
}
c.cacheRWLock.RLock()
defer c.cacheRWLock.RUnlock()

Copy link
Collaborator

Choose a reason for hiding this comment

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

This way, we only lock when we have to

}

link := stringutils.OrDefault(istioVuln.Link, "https://istio.io/latest/news/security/")
_, fixedBy, err := istioutil.IsAffected(v, istioVuln)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we leave a comment saying we know this version is affected, which is why we can ignore that return value?

link := stringutils.OrDefault(istioVuln.Link, "https://istio.io/latest/news/security/")
_, fixedBy, err := istioutil.IsAffected(v, istioVuln)
if err != nil {
log.Errorf("unable to get fixedBy for %s: %istioVuln", istioVuln.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you meant %v at the end?

@daynewlee daynewlee merged commit 4f2407b into master Nov 14, 2022
@daynewlee daynewlee deleted the personal/yli3/addIstioService branch November 14, 2022 18:05
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.

3 participants