-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
Images are ready for the commit at abc1e5c. To use the images, use the tag |
8193288
to
f07e6ce
Compare
f18bb0b
to
8b08c6e
Compare
a93bbcb
to
8038896
Compare
8038896
to
b48d8ad
Compare
Manual test with http request
|
There was a problem hiding this 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
api/v1/orchestratorscan/service.go
Outdated
|
||
// GetIstioVulnerabilities returns Istio vulnerabilities for requested Kubernetes version. | ||
func (s *serviceImpl) GetIstioVulnerabilities(_ context.Context, req *v1.GetIstioVulnerabilitiesRequest) (*v1.GetIstioVulnerabilitiesResponse, error) { | ||
var err error |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
} | ||
version, err := convert.TruncateVersion(version) | ||
if err != nil { | ||
log.Warnf("Unable to convert version of %s - %v. Skipping...", version, err) |
There was a problem hiding this comment.
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
"github.com/stackrox/rox/pkg/stringutils" | ||
v1 "github.com/stackrox/scanner/generated/scanner/api/v1" | ||
stackroxTypes "github.com/stackrox/scanner/pkg/types" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
api/v1/convert/istio.go
Outdated
) | ||
|
||
// IstioVulnerabilities converts istio cve schema to vulnerability. | ||
func IstioVulnerabilities(version string, istioVulns []types.Vuln) ([]*v1.Vulnerability, error) { |
There was a problem hiding this comment.
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
231ed03
to
95bcca4
Compare
f54d492
to
96b5f2a
Compare
4059e5b
to
9301d72
Compare
9301d72
to
807c953
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
api/v1/orchestratorscan/service.go
Outdated
ScannerVersion: s.version, | ||
} | ||
|
||
getIstioVuln := func(version string) ([]*v1.Vulnerability, error) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
pkg/istioUtil/util.go
Outdated
@@ -0,0 +1,26 @@ | |||
package istioUtil |
There was a problem hiding this comment.
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
pkg/istioUtil/util.go
Outdated
) | ||
|
||
// IstioIsAffected gets the fixed-by version for vStr in Istion vuln. | ||
func IstioIsAffected(vStr string, vuln types.Vuln) (bool, string, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
istio/cache/db.go
Outdated
|
||
var vulns []types.Vuln | ||
for _, vuln := range c.cache { | ||
isAffected, _, _ := istioUtil.IstioIsAffected(version, vuln) |
There was a problem hiding this comment.
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?
6c24339
to
8c49906
Compare
3b56631
to
27f2d4e
Compare
1d1e63f
to
abc1e5c
Compare
@daynewlee: The following test failed, say
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. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
Add functionalities of fetch Istio CVEs, converting Istio CVEs to responses and handling Istio CVE get requests.