Skip to content

Conversation

sozercan
Copy link
Member

@sozercan sozercan commented Jun 12, 2025

What this PR does / why we need it:
This isn't something that affects the official builds from GHCR since container builds always copies trivy to /trivy.

If the project is rebuilt and the binary is not placed in root dir, this causes issues since eraser expects trivy to be in root. This PR enables fallback to PATH. If not found in PATH, it will provide an error.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #1149 #1150

Special notes for your reviewer:

Copy link

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 45.00000% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/scanners/trivy/trivy.go 38.88% 10 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 4.99% <45.00%> (-9.85%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/scanners/trivy/types.go 72.07% <100.00%> (+33.24%) ⬆️
pkg/scanners/trivy/trivy.go 5.03% <38.88%> (+5.03%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@ashnamehrotra ashnamehrotra left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

Copy link
Contributor

@pmengelbert pmengelbert left a comment

Choose a reason for hiding this comment

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

Few comments


// currentExecutingLookPath is a variable that points to exec.LookPath by default,
// but can be overridden for testing purposes.
var currentExecutingLookPath = exec.LookPath
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little weird to have this as a global variable here. Why not just use exec.LookPath in the findTrivyExecutable function?

Instead of overriding the lookup function for testing, why not create a t.TempDir(), create some executable files in it, and maniuplate PATH by using os.Setenv?


cliArgs := s.config.cliArgs(refs[i])
cmd := exec.Command(trivyCommandName, cliArgs...)
cmd := exec.Command(s.trivyPath, cliArgs...) // nolint:gosec // G204: Subprocess launched with variable
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make the initScanner function create a symlink at /trivy to the path where trivy was found? That way we don't have to disable a security lint.

Copy link
Member Author

@sozercan sozercan Jun 16, 2025

Choose a reason for hiding this comment

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

good point, this might be why we used /trivy path instead of relying on PATH. However, will this break read only root file system pod security?

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, we can change /trivy to trivy in the call to exec.Command and it will be located in the PATH automatically

Thanks to Mo for the fresh perspective :)

@sozercan sozercan force-pushed the trivy-path branch 3 times, most recently from d122771 to 52c653d Compare June 16, 2025 22:05
sozercan added 7 commits June 16, 2025 22:08
Signed-off-by: Sertac Ozercan <[email protected]>
Signed-off-by: Sertac Ozercan <[email protected]>
Signed-off-by: Sertac Ozercan <[email protected]>
Signed-off-by: Sertac Ozercan <[email protected]>
This reverts commit eebe5b9.

Signed-off-by: Sertac Ozercan <[email protected]>
Signed-off-by: Sertac Ozercan <[email protected]>
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.

[BUG] trivy-scanner pod doesn't error when trivy binary cannot be found
3 participants