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

feat: parse OS version from result of trivy-scan #1444

Merged
merged 12 commits into from
Apr 27, 2022
Merged

feat: parse OS version from result of trivy-scan #1444

merged 12 commits into from
Apr 27, 2022

Conversation

Nikkely
Copy link
Contributor

@Nikkely Nikkely commented Apr 15, 2022

What did you implement:

Currently, trivy-to-vuls don't parse OS version .
I made trivy-to-vuls parse it.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Add test case

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Reference

dependabot bot and others added 4 commits April 14, 2022 23:49
Bumps [github.com/aquasecurity/trivy](https://github.com/aquasecurity/trivy) from 0.24.2 to 0.25.4.
- [Release notes](https://github.com/aquasecurity/trivy/releases)
- [Changelog](https://github.com/aquasecurity/trivy/blob/main/goreleaser.yml)
- [Commits](aquasecurity/trivy@v0.24.2...v0.25.4)

---
updated-dependencies:
- dependency-name: github.com/aquasecurity/trivy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…ub.com/aquasecurity/trivy-0.25.4

chore(deps): bump github.com/aquasecurity/trivy from 0.24.2 to 0.25.4
Copy link
Member

@kotakanbe kotakanbe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@MaineK00n MaineK00n left a comment

Choose a reason for hiding this comment

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

How about rewriting it this way?

func setScanResultMeta(scanResult *models.ScanResult, report *types.Report) error {
	if report.Metadata.OS != nil {
		scanResult.Family = report.Metadata.OS.Family
		scanResult.Release = report.Metadata.OS.Name
		scanResult.ServerName = fmt.Sprintf("%s %s", scanResult.Family, scanResult.Release)
	} else {
		scanResult.Family = constant.ServerTypePseudo
		scanResult.ServerName = "library scan by trivy"
	}
	scanResult.ScannedAt = time.Now()
	scanResult.ScannedBy = "trivy"
	scanResult.ScannedVia = "trivy"

	if len(report.Results) == 0 {
		return xerrors.Errorf("scanned images or libraries are not supported by Trivy. see https://aquasecurity.github.io/trivy/dev/vulnerability/detection/os/, https://aquasecurity.github.io/trivy/dev/vulnerability/detection/language/")
	}

	// check vuls expected os or library
	for _, r := range report.Results {
		if !pkg.IsVulsExpectedOS(r.Type) && !pkg.IsVulsExpectedLib(r.Type) {
			return xerrors.Errorf("vuls not supported images or libraries. r.Type: %s", r.Type)
		}
	}
	return nil
}

@Nikkely Nikkely self-assigned this Apr 18, 2022
detector/detector.go Show resolved Hide resolved
detector/detector.go Show resolved Hide resolved
detector/detector.go Outdated Show resolved Hide resolved
@Nikkely Nikkely requested a review from MaineK00n April 26, 2022 08:44
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
@Nikkely Nikkely requested a review from MaineK00n April 26, 2022 10:17
Copy link
Collaborator

@MaineK00n MaineK00n left a comment

Choose a reason for hiding this comment

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

LGTM

@MaineK00n MaineK00n merged commit fd18df1 into future-architect:master Apr 27, 2022
@Nikkely Nikkely mentioned this pull request May 6, 2022
9 tasks
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.

None yet

3 participants