-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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(misconf): Expose misconf engine debug logs with --debug
option
#5550
Conversation
Addresses: #5395 Signed-off-by: Simar <[email protected]>
--debug
option--debug
option
It's off-topic, but I just remember defsec didn't sync with the logging options in Trivy, like |
Yeah you're right - I noticed that too. I think we need to better integrate the logging options between trivy and trivy-iac modules. I will create an issue for it #5551 |
pkg/misconf/scanner.go
Outdated
@@ -67,6 +68,14 @@ func (o *ScannerOption) Sort() { | |||
sort.Strings(o.DataPaths) | |||
} | |||
|
|||
type DebugLogger struct { | |||
} |
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.
Same as above
pkg/cloud/aws/scanner/scanner.go
Outdated
@@ -44,11 +44,11 @@ func (s *AWSScanner) Scan(ctx context.Context, option flag.Options) (scan.Result | |||
} | |||
|
|||
if option.Debug { | |||
scannerOpts = append(scannerOpts, options.ScannerWithDebug(&defsecLogger{})) | |||
scannerOpts = append(scannerOpts, options.ScannerWithDebug(&DebugLogger{})) |
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.
How about passing a named logger as a field? Zap will take care of adding the path to the logger name itself
scannerOpts = append(scannerOpts, options.ScannerWithDebug(&DebugLogger{})) | |
scannerOpts = append(scannerOpts, options.ScannerWithDebug(&DebugLogger{log.Logger.Named("aws")})) |
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.
log.Logger.Named()
returns a sugaredlogger which doesn't satisfy the interface conditions.
Instead I refactored the DebugLogger into the log
package which would help us re-use it across other packages and added a name as a field as you mentioned.
In this PR, the components use the Trivy global logger, so they will have the same behaviour as Trivy. I passed the -q flag and Trivy's output was clear. |
Great! |
pkg/log/logger.go
Outdated
@@ -121,3 +122,12 @@ func String(key, val string) zap.Field { | |||
} | |||
return zap.String(key, val) | |||
} | |||
|
|||
type DebugLogger struct { |
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.
It looks more like PrefixedLogger
, doesn't it?
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.
Renamed: d9389f7
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.
Please be mindful that I'm planning to migrate zap to slog after bumping Go to 1.21 in Trivy. I'm not sure slog meets our requirements, though.
@nikpivkin Can you please review this PR? |
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.
LGTM
Description
Exposes useful informational debug logs from the misconf engine when the existing
--debug
option is passed.This can be useful for a variety of reasons, including knowing if a rule was ignored and why.
Related issues
Related PRs
Checklist