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

πŸ› Fix progress for unscored assets #424

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 14 additions & 12 deletions cli/reporter/print_compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,22 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep
r.out.Write([]byte(NewLineCharacter))
}

r.out.Write([]byte("Controls:" + NewLineCharacter))
for id, score := range report.Scores {
_, ok := resolved.CollectorJob.ReportingQueries[id]
if !ok {
continue
}
if len(report.Scores) > 0 {
r.out.Write([]byte("Controls:" + NewLineCharacter))
for id, score := range report.Scores {
_, ok := resolved.CollectorJob.ReportingQueries[id]
if !ok {
continue
}

query, ok := queries[id]
if !ok {
r.out.Write([]byte("Couldn't find any queries for incoming value for " + id))
continue
}
query, ok := queries[id]
if !ok {
r.out.Write([]byte("Couldn't find any queries for incoming value for " + id))
continue
}

r.printControl(score, query, asset, resolved, report, results)
r.printControl(score, query, asset, resolved, report, results)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,11 @@ func (s *localAssetScanner) run() (*AssetReport, error) {
return ar, err
}
s.ProgressReporter.Score(report.Score.Rating().Letter())
s.ProgressReporter.Completed()
if report.Score.Rating().Letter() == "U" {
Copy link
Member

Choose a reason for hiding this comment

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

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 think, this is different. It is not an error, the asset matched a policy, but didn't get scored.

I used this policy to provoke this:

  - asset_filter:
      query: platform.name == "k8s-deployment"
    scoring_queries:
    data_queries:

@preslavgerchev In which situation did you see the problem with the progress bar?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tested this with the Kubernetes Best Practices by Mondoo policy, however it had most of its controls disabled or ignored, leading to the situation you described above (matching filter, no queries).

i can provide the exact policy (with ignored queries) if needed

Copy link
Member

Choose a reason for hiding this comment

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

I am not 100% sure I understand what we are solving here then. In case policies applied it was scored. Feels like the issue is with the policy itself.

Copy link
Member

Choose a reason for hiding this comment

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

Preslav showed me the issue. I agree that we need to fix the overall progress, but reading the score itself feels wrong. The progress bar should not care about the rating at all. We can move forward with this approach as mitigation but we need a better solution for that handling going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up is #439

s.ProgressReporter.NotApplicable()
} else {
s.ProgressReporter.Completed()
}

log.Debug().Str("asset", s.job.Asset.Mrn).Msg("scan complete")
ar.Report = report
Expand Down