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

✨ poll for asset score updates #1174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,24 +512,46 @@ func (s *LocalScanner) RunAssetJob(job *AssetJob) {
return
}

job.Reporter.AddReport(job.Asset, results)

upstream := s.upstreamServices(job.Ctx, job.UpstreamConfig)
// The vuln report is relevant only when we have an aggregate reporter
if vulnReporter, isAggregateReporter := job.Reporter.(VulnReporter); upstream != nil && isAggregateReporter {
// get new gql client
mondooClient, err := gql.NewClient(job.UpstreamConfig, s._upstreamClient.HttpClient)
if err != nil {
return
if upstream != nil {
// If we show the score, we need to fetch it from upstream and update it
if _, isAggregateReporter := job.Reporter.(*AggregateReporter); !job.UpstreamConfig.Incognito && isAggregateReporter {
assetScore := results.Report.Scores[job.Asset.Mrn]

// Retry fetching the score a few times, in case it's not updated yet
for i := 0; i < 15; i++ {
score, err := upstream.PolicyResolver.GetScore(job.Ctx, &policy.EntityScoreReq{EntityMrn: job.Asset.Mrn, ScoreMrn: job.Asset.Mrn})
if err != nil {
log.Error().Err(err).Msg("could not get asset score")
}
if score.Score.ValueModifiedTime > assetScore.ValueModifiedTime {
results.Report.Scores[job.Asset.Mrn] = score.Score
results.Report.Score = score.Score
log.Debug().Uint32("old score", assetScore.Value).Uint32("new score", score.Score.Value).Msg("score updated")
break
}
log.Debug().Msg("score not updated yet, waiting 2 seconds")
time.Sleep(2 * time.Second)
}
}

gqlVulnReport, err := mondooClient.GetVulnCompactReport(job.Asset.Mrn)
if err != nil {
log.Error().Err(err).Msg("could not get vulnerability report")
return
// The vuln report is relevant only when we have an aggregate reporter
if vulnReporter, isVulnReporter := job.Reporter.(VulnReporter); isVulnReporter {
// get new gql client
mondooClient, err := gql.NewClient(job.UpstreamConfig, s._upstreamClient.HttpClient)
if err != nil {
return
}

gqlVulnReport, err := mondooClient.GetVulnCompactReport(job.Asset.Mrn)
if err != nil {
log.Error().Err(err).Msg("could not get vulnerability report")
return
}
vulnReporter.AddVulnReport(job.Asset, gqlVulnReport)
}
vulnReporter.AddVulnReport(job.Asset, gqlVulnReport)
}
job.Reporter.AddReport(job.Asset, results)

// When the progress bar is disabled there's no feedback when an asset is done scanning. Adding this message
// such that it is visible from the logs.
Expand Down
Loading