-
Notifications
You must be signed in to change notification settings - Fork 174
ROX-28151: Tracker runner, triggered by Prometheus scrape request #15797
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0c5c7eb
minimal configuration
parametalol 6f567c7
aggregator
parametalol c60a266
CustomRegistry
parametalol c38f909
tracker
parametalol 11124ab
added a test, removed unused (here) method, nits
parametalol da10075
logging finding error
parametalol 0eaf539
cached runner
parametalol 56786a7
add global access scope checker
parametalol abc9ebd
unexport validateConfiguration
parametalol a359e9d
reshuffle tracker configuration a little
parametalol c8d3b6c
unused variable removed
parametalol c0eef19
nit
parametalol 96d587a
extract runner from singleton
parametalol d5bd75e
typo
parametalol 6481815
style
parametalol cff30be
nit: comment
parametalol 3d1684c
reset custom registry
parametalol 924e8b3
Apply suggestion from @parametalol
parametalol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package image_vulnerabilities | ||
|
|
||
| import ( | ||
| "strconv" | ||
|
|
||
| "github.com/stackrox/rox/central/metrics/custom/tracker" | ||
| "github.com/stackrox/rox/central/platform/matcher" | ||
| "github.com/stackrox/rox/generated/storage" | ||
| ) | ||
|
|
||
| var lazyLabels = []tracker.LazyLabel[*finding]{ | ||
| {Label: "Cluster", Getter: func(f *finding) string { return f.deployment.GetClusterName() }}, | ||
| {Label: "Namespace", Getter: func(f *finding) string { return f.deployment.GetNamespace() }}, | ||
| {Label: "Deployment", Getter: func(f *finding) string { return f.deployment.GetName() }}, | ||
| {Label: "IsPlatformWorkload", Getter: isPlatformWorkload}, | ||
|
|
||
| {Label: "ImageID", Getter: func(f *finding) string { return f.image.GetId() }}, | ||
| {Label: "ImageRegistry", Getter: func(f *finding) string { return f.name.GetRegistry() }}, | ||
| {Label: "ImageRemote", Getter: func(f *finding) string { return f.name.GetRemote() }}, | ||
| {Label: "ImageTag", Getter: func(f *finding) string { return f.name.GetTag() }}, | ||
| {Label: "Component", Getter: func(f *finding) string { return f.component.GetName() }}, | ||
| {Label: "ComponentVersion", Getter: func(f *finding) string { return f.component.GetVersion() }}, | ||
| {Label: "OperatingSystem", Getter: func(f *finding) string { return f.image.GetScan().GetOperatingSystem() }}, | ||
|
|
||
| {Label: "CVE", Getter: func(f *finding) string { return f.vuln.GetCve() }}, | ||
| {Label: "CVSS", Getter: func(f *finding) string { return strconv.FormatFloat(float64(f.vuln.GetCvss()), 'f', 1, 32) }}, | ||
| {Label: "Severity", Getter: func(f *finding) string { return f.vuln.GetSeverity().String() }}, | ||
| {Label: "SeverityV2", Getter: func(f *finding) string { return f.vuln.GetCvssV2().GetSeverity().String() }}, | ||
| {Label: "SeverityV3", Getter: func(f *finding) string { return f.vuln.GetCvssV3().GetSeverity().String() }}, | ||
| {Label: "IsFixable", Getter: func(f *finding) string { return strconv.FormatBool(f.vuln.GetFixedBy() != "") }}, | ||
| } | ||
|
|
||
| // finding holds all information for computing any label in this category. | ||
| // The aggregator calls the lazy label's Getter function with every finding to | ||
| // compute the values for the list of defined labels. | ||
| type finding struct { | ||
| err error | ||
| deployment *storage.Deployment | ||
| image *storage.Image | ||
| name *storage.ImageName | ||
| component *storage.EmbeddedImageScanComponent | ||
| vuln *storage.EmbeddedVulnerability | ||
| } | ||
|
|
||
| func (f *finding) GetError() error { return f.err } | ||
|
|
||
| func isPlatformWorkload(f *finding) string { | ||
| p, _ := matcher.Singleton().MatchDeployment(f.deployment) | ||
| return strconv.FormatBool(p) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package image_vulnerabilities | ||
|
|
||
| import ( | ||
| "context" | ||
| "iter" | ||
|
|
||
| deploymentDS "github.com/stackrox/rox/central/deployment/datastore" | ||
| "github.com/stackrox/rox/central/metrics" | ||
| "github.com/stackrox/rox/central/metrics/custom/tracker" | ||
| "github.com/stackrox/rox/generated/storage" | ||
| "github.com/stackrox/rox/pkg/sac" | ||
| "github.com/stackrox/rox/pkg/sac/resources" | ||
| "github.com/stackrox/rox/pkg/search" | ||
| ) | ||
|
|
||
| func New(registry metrics.CustomRegistry, ds deploymentDS.DataStore) *tracker.TrackerBase[*finding] { | ||
| return tracker.MakeTrackerBase( | ||
| "vulnerabilities", | ||
| "aggregated CVEs", | ||
| lazyLabels, | ||
| func(ctx context.Context, mcfg tracker.MetricsConfiguration) iter.Seq[*finding] { | ||
| return trackVulnerabilityMetrics(ctx, mcfg, ds) | ||
| }, | ||
| registry) | ||
| } | ||
|
|
||
| func trackVulnerabilityMetrics(ctx context.Context, _ tracker.MetricsConfiguration, ds deploymentDS.DataStore) iter.Seq[*finding] { | ||
| ctx = sac.WithGlobalAccessScopeChecker(ctx, sac.AllowFixedScopes( | ||
| sac.AccessModeScopeKeys(storage.Access_READ_ACCESS), | ||
| sac.ResourceScopeKeys(resources.Deployment, resources.Image))) | ||
|
|
||
| return func(yield func(*finding) bool) { | ||
| finding := &finding{} | ||
| _ = ds.WalkByQuery(ctx, search.EmptyQuery(), func(deployment *storage.Deployment) error { | ||
| finding.deployment = deployment | ||
| images, err := ds.GetImagesForDeployment(ctx, deployment) | ||
| if err != nil { | ||
| return nil // Nothing can be done with this error here. | ||
| } | ||
| for _, finding.image = range images { | ||
| if !forEachImageVuln(yield, finding) { | ||
| return tracker.ErrStopIterator | ||
| } | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // forEachImageVuln yields a finding for every vulnerability associated with | ||
| // each image name. | ||
| func forEachImageVuln(yield func(*finding) bool, f *finding) bool { | ||
| for _, f.component = range f.image.GetScan().GetComponents() { | ||
| for _, f.vuln = range f.component.GetVulns() { | ||
| for _, f.name = range f.image.GetNames() { | ||
| if !yield(f) { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.