-
Notifications
You must be signed in to change notification settings - Fork 371
feat(ubuntu): add eol date for 20.04-ESM #8981
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
Changes from 6 commits
07adf08
633427d
cb8c4e6
07f066f
711d991
753847e
dd44435
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,8 @@ var ( | |||||||||||||||||||||||||||||||
| "18.10": time.Date(2019, 7, 18, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "19.04": time.Date(2020, 1, 18, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "19.10": time.Date(2020, 7, 17, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "20.04": time.Date(2025, 4, 23, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "20.04": time.Date(2025, 5, 31, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "20.04-ESM": time.Date(2030, 4, 30, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "20.10": time.Date(2021, 7, 22, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "21.04": time.Date(2022, 1, 20, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
| "21.10": time.Date(2022, 7, 14, 23, 59, 59, 0, time.UTC), | ||||||||||||||||||||||||||||||||
|
|
@@ -67,15 +68,37 @@ var ( | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type options struct { | ||||||||||||||||||||||||||||||||
| eolDates map[string]time.Time | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type Option func(*options) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // WithEOLDates takes eol dates for testability | ||||||||||||||||||||||||||||||||
| func WithEOLDates(dates map[string]time.Time) Option { | ||||||||||||||||||||||||||||||||
| return func(opts *options) { | ||||||||||||||||||||||||||||||||
| opts.eolDates = dates | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Scanner implements the Ubuntu scanner | ||||||||||||||||||||||||||||||||
| type Scanner struct { | ||||||||||||||||||||||||||||||||
| *options | ||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Since there is only one field, defining a new struct may be too much. We may want to add the field directly rather than embedding.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks simpler, thanks! |
||||||||||||||||||||||||||||||||
| vs ubuntu.VulnSrc | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // NewScanner is the factory method for Scanner | ||||||||||||||||||||||||||||||||
| func NewScanner() *Scanner { | ||||||||||||||||||||||||||||||||
| func NewScanner(opts ...Option) *Scanner { | ||||||||||||||||||||||||||||||||
| o := &options{ | ||||||||||||||||||||||||||||||||
| eolDates: eolDates, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, opt := range opts { | ||||||||||||||||||||||||||||||||
| opt(o) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
| return &Scanner{ | ||||||||||||||||||||||||||||||||
| vs: ubuntu.NewVulnSrc(), | ||||||||||||||||||||||||||||||||
| options: o, | ||||||||||||||||||||||||||||||||
| vs: ubuntu.NewVulnSrc(), | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -133,12 +156,13 @@ func (s *Scanner) Detect(ctx context.Context, osVer string, _ *ftypes.Repository | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // IsSupportedVersion checks is OSFamily can be scanned using Ubuntu scanner | ||||||||||||||||||||||||||||||||
| func (s *Scanner) IsSupportedVersion(ctx context.Context, osFamily ftypes.OSType, osVer string) bool { | ||||||||||||||||||||||||||||||||
| return osver.Supported(ctx, eolDates, osFamily, osVer) | ||||||||||||||||||||||||||||||||
| osVer = s.versionFromEolDates(ctx, osVer) | ||||||||||||||||||||||||||||||||
| return osver.Supported(ctx, s.eolDates, osFamily, osVer) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // versionFromEolDates checks if actual (not ESM) version is not outdated | ||||||||||||||||||||||||||||||||
| func (s *Scanner) versionFromEolDates(ctx context.Context, osVer string) string { | ||||||||||||||||||||||||||||||||
| if _, ok := eolDates[osVer]; ok { | ||||||||||||||||||||||||||||||||
| if _, ok := s.eolDates[osVer]; ok { | ||||||||||||||||||||||||||||||||
| return osVer | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -148,7 +172,7 @@ func (s *Scanner) versionFromEolDates(ctx context.Context, osVer string) string | |||||||||||||||||||||||||||||||
| // then we need to get vulnerabilities for `18.04` | ||||||||||||||||||||||||||||||||
| // if `18.04` is outdated - we need to use `18.04-ESM` (we will return error until we add `18.04-ESM` to eolDates) | ||||||||||||||||||||||||||||||||
| ver := strings.TrimRight(osVer, "-ESM") | ||||||||||||||||||||||||||||||||
| if eol, ok := eolDates[ver]; ok && clock.Now(ctx).Before(eol) { | ||||||||||||||||||||||||||||||||
| if eol, ok := s.eolDates[ver]; ok && clock.Now(ctx).Before(eol) { | ||||||||||||||||||||||||||||||||
| return ver | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return osVer | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
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.