Repository navigation
fix: pass Checkov arguments over stdin instead of the command line - #65
Conversation
The E2BIG fallback from #64 scanned the whole directory, which walks every file in the repository (excluded paths, other languages, secrets on all of them) and is likely to time out on the large repositories that hit it. Start a small launcher that reads the arguments as JSON on stdin and calls Checkov in-process, so the requested file list never reaches execve and Checkov scans exactly the files the worker sent, however many there are.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
👀 Worth a closer look
The launcher may fail when Checkov is available on PATH but not installed in the wrapper’s Python environment, changing behavior from the previous executable-based invocation. This should be reviewed for deployment environments that separate those installations.
Test suggestions
- Run with a file list exceeding the operating system argument-size limit and verify only the listed files are scanned.
- Verify the launcher decodes stdin arguments and passes them to Checkov without dropping or reordering options.
- Verify timeout handling still terminates the child Checkov process.
- Verify normal scans produce the same output as the previous command-line invocation.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Run with a file list exceeding the operating system argument-size limit and verify only the listed files are scanned.
2. Verify the launcher decodes stdin arguments and passes them to Checkov without dropping or reordering options.
3. Verify timeout handling still terminates the child Checkov process.
4. Verify normal scans produce the same output as the previous command-line invocation.
TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| checkovProcess = Popen(command + ['-d', '.'], stdout=PIPE, cwd=srcDir, env=processEnv) | ||
|
|
||
| stdout = checkovProcess.communicate()[0] | ||
| checkovProcess = Popen([sys.executable, CHECKOV_LAUNCHER], stdin=PIPE, stdout=PIPE, cwd=srcDir, env=processEnv) |
There was a problem hiding this comment.
🟡 MEDIUM RISK
When Checkov is installed in a different Python environment from the wrapper, scans now fail with an import error instead of using the checkov executable on PATH. Consider running the launcher with the interpreter associated with that executable, or explicitly installing Checkov in the wrapper's interpreter.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
#64 avoided
Argument list too longby falling back tocheckov -d .. On the large repositories that hit it, that scan walks the whole repository: every task language, paths excluded in Codacy, and thesecretsframework over every file. Those runs are likely to hit the 5-minute timeout or the 2000Mi limit. In production it shows up as64891 files do not fit in the command line, scanning the whole directory.The wrapper now starts
checkov_launcher.py, which reads Checkov's arguments as JSON on stdin and runsCheckov(argv).run()in-process, the same call thecheckovcommand makes. The file list never goes on the command line, so Checkov scans exactly the files the worker sent, whatever their number. The-d .fallback is removed. Checkov still runs in a child process, so the timeout kill is unchanged.Checked locally against checkov 3.3.19:
master-fargs), one listed and one unlisted privileged pod-d ., reports both podsdocs/multiple-testscasesmastercodacy/codacy-checkovincodacy-tools/docker-list.txt