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

refactor(secret): add warning about large files #7085

Conversation

DmitriyLewen
Copy link
Contributor

Description

Show warnings about large files so users can skip them.
See #7078 for more details.

example:

2024-07-03T12:46:19+06:00       WARN    [secret] The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.     file_path="fslibs-entry-point.sh" size (MB)=946

Related discussions

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Jul 3, 2024
@@ -165,6 +166,9 @@ func (a *SecretAnalyzer) Required(filePath string, fi os.FileInfo) bool {
return false
}

if size := fi.Size(); size > 209_715_200 { // 200MB
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'm not sure about the size
@knqyf263 wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel even 10 MB is large for plain text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I probably overdid it when I chose 200 MB 😄
updated in c3d5e4c

Choose a reason for hiding this comment

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

Can we have this configurable i.e if value is passed through flag than we can consider it and skip the scanning?
If not provided then we can show the warning and proceed with the scanning.

--file-size-threshold 10mb

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'm not sure new flag is good idea, because we will only be using it for secret scanner.
But we can think about adding this option to secret config file

Copy link

@rajaSahil rajaSahil Jul 3, 2024

Choose a reason for hiding this comment

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

Sure, anything would be fine, since this would be helpful a lot.
We can easily add a config and scan whole registry and based on the threshold, trivy will skip the scanning.
Otherwise we will have to manually add code logic to look for the warnings.

Choose a reason for hiding this comment

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

But for standalone trivy scanning, IMO flag would make sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The size varies depending on scanner (vulnerability, misconfiguration and secret) and analyzer (npm and go binary). Adding the flag needs to be carefully designed. We'll merge this PR with the current implementation as this warning is at least useful.

Choose a reason for hiding this comment

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

Should I go ahead and add a feature enhancement Issue?

Copy link
Collaborator

Choose a reason for hiding this comment

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

 Yes, you can open a discussion.

@knqyf263 knqyf263 added this pull request to the merge queue Jul 3, 2024
Merged via the queue into aquasecurity:main with commit cb89fbb Jul 3, 2024
12 checks passed
@DmitriyLewen DmitriyLewen deleted the refactor-secret/add-warning-about--big-files branch July 4, 2024 04:08
@knqyf263
Copy link
Collaborator

knqyf263 commented Jul 9, 2024

2024-07-09T10:02:24+04:00 WARN [secret] The size of the scanned file is too large. It is recommended to use --skip-files for this file to avoid high memory consumption. file_path="usr/local/bin/trivy" size (MB)=117

@DmitriyLewen I realized it even shows a warning for binary files. We should show it after checking the file type as a binary file is skipped regardless of the file size.
https://github.com/DmitriyLewen/trivy/blob/c3d5e4c60158fe0d8a152af467c90530cc3e5c2e/pkg/fanal/analyzer/secret/secret.go#L98-L101

@DmitriyLewen
Copy link
Contributor Author

Nice catch!
I will create PR.

@DmitriyLewen
Copy link
Contributor Author

#7123

skahn007gl pushed a commit to skahn007gl/trivy that referenced this pull request Jul 23, 2024
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.

3 participants