Skip to content

fix: pass Checkov arguments over stdin instead of the command line - #65

Merged
lolgab merged 1 commit into
masterfrom
fix/checkov-args-file
Dec 4, 2026
Merged

lolgab merged 1 commit into
masterfrom
fix/checkov-args-file

Conversation

@lolgab

@lolgab lolgab commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

#64 avoided Argument list too long by falling back to checkov -d .. On the large repositories that hit it, that scan walks the whole repository: every task language, paths excluded in Codacy, and the secrets framework over every file. Those runs are likely to hit the 5-minute timeout or the 2000Mi limit. In production it shows up as 64891 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 runs Checkov(argv).run() in-process, the same call the checkov command 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:

Input master This branch
40,001 files (~2.4 MB of -f args), one listed and one unlisted privileged pod falls back to -d ., reports both pods reports the listed pod only (28 s)
docs/multiple-tests cases — same output as master
  • After release, bump codacy/codacy-checkov in codacy-tools/docker-list.txt

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.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@lolgab
lolgab marked this pull request as ready for review December 4, 2026 10:57

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/codacy_checkov.py
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

@lolgab
lolgab requested a review from DMarinhoCodacy December 4, 2026 11:14
@lolgab
lolgab enabled auto-merge December 4, 2026 11:14
@lolgab
lolgab merged commit f17b1fa into master Dec 4, 2026
4 checks passed
@lolgab
lolgab deleted the fix/checkov-args-file branch December 4, 2026 12:11
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.

2 participants