tcosolutions/betterscan

"checkmate git init" step is unresponsive

Closed this issue · 4 comments

Thanks for creating and sharing this tool. Appreciate your idea and efforts.

I'm facing issues while running the pre-built docker images on MacOS with M1 chip.
"checkmate git init" step is stuck for hours.
Is there a debug option to run the command to troubleshoot further?

Please find below further details about this blocker:
image

❯ uname -a Darwin EELPD01407 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64

`❯ docker run -ti scanmycode/scanmycode3-ce:worker-cli-arm64 checkmate
/root
/root
Loading plugin: git
Loading plugin: trufflehog3
Loading plugin: trojansource
Loading plugin: metrics
Loading plugin: bandit
Loading plugin: brakeman
Loading plugin: phpanalyzer
Loading plugin: gosec
Loading plugin: confused
Loading plugin: pmd
Loading plugin: semgrep
Loading plugin: semgrepdefi
Loading plugin: semgrepjs
Loading plugin: checkov
Usage: checkmate [command] [command] [...] [args]

Type "checkmate help" for help`

`❯ docker run -v /Users/karthik/Downloads/java-project-master:/Users/karthik/Downloads/java-project-master -ti scanmycode/scanmycode3-ce:worker-cli-arm64 bash
root@68484e859bd2:~# cd /Users/karthik/Downloads/java-project-master

root@68484e859bd2:/Users/karthik/Downloads/java-project-master#
root@68484e859bd2:/Users/karthik/Downloads/java-project-master# checkmate init
/root
/Users/karthik/Downloads/java-project-master
Loading plugin: git
Loading plugin: trufflehog3
Loading plugin: trojansource
Loading plugin: metrics
Loading plugin: bandit
Loading plugin: brakeman
Loading plugin: phpanalyzer
Loading plugin: gosec
Loading plugin: confused
Loading plugin: pmd
Loading plugin: semgrep
Loading plugin: semgrepdefi
Loading plugin: semgrepjs
Loading plugin: checkov
Initializing new project in the current directory.
root@68484e859bd2:/Users/karthik/Downloads/java-project-master# checkmate git init
/root
/Users/karthik/Downloads/java-project-master
/Users/karthik/Downloads/java-project-master
Loading plugin: git
Loading plugin: trufflehog3
Loading plugin: trojansource
Loading plugin: metrics
Loading plugin: bandit
Loading plugin: brakeman
Loading plugin: phpanalyzer
Loading plugin: gosec
Loading plugin: confused
Loading plugin: pmd
Loading plugin: semgrep
Loading plugin: semgrepdefi
Loading plugin: semgrepjs
Loading plugin: checkov`

Also tried on Linux machine and the result is same.
# uname -a Linux test-server 4.19.56-coreos-r1 #1 SMP Tue Jul 30 06:40:10 -00 2019 x86_64 Intel(R) Xeon(R) E-2278G CPU @ 3.40GHz GenuineIntel GNU/Linux

`# docker run -ti scanmycode/scanmycode3-ce:worker-cli bash
root@1421087bdf21:#
root@1421087bdf21:
# checkmate init
/root
/root
Loading plugin: git
Loading plugin: trufflehog3
Loading plugin: trojansource
Loading plugin: metrics
Loading plugin: bandit
Loading plugin: brakeman
Loading plugin: phpanalyzer
Loading plugin: gosec
Loading plugin: confused
Loading plugin: pmd
Loading plugin: semgrep
Loading plugin: semgrepdefi
Loading plugin: semgrepjs
Loading plugin: checkov
Initializing new project in the current directory.
root@1421087bdf21:~# checkmate git init
/root
/root
/root
Loading plugin: git
Loading plugin: trufflehog3
Loading plugin: trojansource
Loading plugin: metrics
Loading plugin: bandit
Loading plugin: brakeman
Loading plugin: phpanalyzer
Loading plugin: gosec
Loading plugin: confused
Loading plugin: pmd
Loading plugin: semgrep
Loading plugin: semgrepdefi
Loading plugin: semgrepjs
Loading plugin: checkov

client_loop: send disconnect: Broken pipe
❯`

Hi @ok-karthik

Thanks for your issue. I think you are missing the CODE_DIR env setup step and cd'ing into it.

If you exec into Container, pass the env var (-e) or export it there.

Below is also using Arm64 image (should be faster)

Below assume your code is under /code. Feel free to adjust.

export CODE_DIR=/code
cd $CODE_DIR
docker run -e CODE_DIR -v /code:/code -ti  scanmycode/scanmycode3-ce:worker-cli-arm64 /bin/sh -c 'cd $CODE_DIR && checkmate init'
docker run -e CODE_DIR -v /code:/code -ti  scanmycode/scanmycode3-ce:worker-cli-arm64 /bin/sh -c 'cd $CODE_DIR && checkmate git init'
docker run -e CODE_DIR -v /code:/code -ti  scanmycode/scanmycode3-ce:worker-cli-arm64 /bin/sh -c 'cd $CODE_DIR && checkmate git analyze'
docker run -e CODE_DIR -v /code:/code  -ti  scanmycode/scanmycode3-ce:worker-cli-arm64 /bin/sh -c 'cd $CODE_DIR && checkmate issues'

Let me know if this helped.

P. S Only have Linux on my end

@marcinguy , thanks for your response. Thanks for highlighting about CODE_DIR.

I've tested by passing the env var, it seems to work like a charm.
I think the problem was with the code repo being used.. For my particular private code repo, init step seems stuck at "checkmate git init". But when I use it with a sample public code repo, it seems to work okay (both results below)

On Linux and Mac M1 with https://github.com/skeeto/sample-java-project.git - Works Okay
jenkins-agent-1 orugondakart01 # export CODE_DIR=/tmp/sample-java-project; docker run -e CODE_DIR -v ${CODE_DIR}:${CODE_DIR} -ti scanmycode/scanmycode3-ce:worker-cli /bin/sh -c 'cd $CODE_DIR && checkmate init' /root /tmp/sample-java-project Loading plugin: git Loading plugin: trufflehog3 Loading plugin: trojansource Loading plugin: metrics Loading plugin: bandit Loading plugin: brakeman Loading plugin: phpanalyzer Loading plugin: gosec Loading plugin: confused Loading plugin: pmd Loading plugin: semgrep Loading plugin: semgrepdefi Loading plugin: semgrepjs Loading plugin: checkov Initializing new project in the current directory. jenkins-agent-1 orugondakart01 # jenkins-agent-1 orugondakart01 # export CODE_DIR=/tmp/sample-java-project; docker run -e CODE_DIR -v ${CODE_DIR}:${CODE_DIR} -ti scanmycode/scanmycode3-ce:worker-cli /bin/sh -c 'cd $CODE_DIR && checkmate git init' /root /tmp/sample-java-project /tmp/sample-java-project Loading plugin: git Loading plugin: trufflehog3 Loading plugin: trojansource Loading plugin: metrics Loading plugin: bandit Loading plugin: brakeman Loading plugin: phpanalyzer Loading plugin: gosec Loading plugin: confused Loading plugin: pmd Loading plugin: semgrep Loading plugin: semgrepdefi Loading plugin: semgrepjs Loading plugin: checkov jenkins-agent-1 orugondakart01 # export CODE_DIR=/tmp/sample-java-project; docker run -e CODE_DIR -v ${CODE_DIR}:${CODE_DIR} -ti scanmycode/scanmycode3-ce:worker-cli /bin/sh -c 'cd $CODE_DIR && checkmate git analyze' /root /tmp/sample-java-project /tmp/sample-java-project Loading plugin: git Loading plugin: trufflehog3 Loading plugin: trojansource Loading plugin: metrics Loading plugin: bandit Loading plugin: brakeman Loading plugin: phpanalyzer Loading plugin: gosec Loading plugin: confused Loading plugin: pmd Loading plugin: semgrep Loading plugin: semgrepdefi Loading plugin: semgrepjs Loading plugin: checkov Analyzing the 1 most recent commits in branch master (offset: 0) Excluding 0 file revisions Analyzing 12 new file revisions (0 are already analyzed) Analyzing and saving: 0 - 10 (12 remaining) Analyzing file revision .gitignore [main] INFO profile include tests: None [main] INFO profile exclude tests: None [main] INFO cli include tests: None [main] INFO cli exclude tests: None Please supply the path to a Rails application (looking in /tmp/12dba0595a514341a1e28bef134809f5). Use --force` to run a scan anyway.
PHP Notice: Trying to access array offset on value of type int in phar:///root/phpscan/progpilot_dev20180720-215434.phar/vendor/progpilot/package/src/progpilot/Transformations/Php/Expr.php on line 36
PHP Notice: Trying to access array offset on value of type int in phar:///root/phpscan/progpilot_dev20180720-215434.phar/vendor/progpilot/package/src/progpilot/Transformations/Php/Expr.php on line 36
PHP Notice: Trying to access array offset on value of type int in phar:///root/phpscan/progpilot_dev20180720-215434.phar/vendor/progpilot/package/src/progpilot/Transformations/Php/Expr.php on line 36
[gosec] 2022/06/17 11:51:13 Including rules: default
[gosec] 2022/06/17 11:51:13 Excluding rules: default
[gosec] 2022/06/17 11:51:13 No packages found
Jun 17, 2022 11:51:14 AM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis
WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.41.0/pmd_userdocs_incremental_analysis.html

METRICS: Using configs from the Registry (like --config=p/ci) reports pseudonymous rule metrics to semgrep.dev.
To disable Registry rule metrics, use "--metrics=off".
Using configs only from local files (like --config=xyz.yml) does not enable metrics.

More information: https://semgrep.dev/docs/metrics

Scanning 1 file.

Ran 1 rule on 1 file: 0 findings.

Scanning 1 file with 21 solidity rules.

Some files were skipped or only partially analyzed.
Partially scanned: 1 files only partially analyzed due to a parsing or internal Semgrep error

Ran 21 rules on 1 file: 0 findings.

Scanning across multiple languages:
js | 111 rules × 1 file
ts | 111 rules × 1 file

100%|██████████████████████████████████████████████████████████████████████████████████████████████████|2/2 tasks

Ran 111 rules on 1 file: 0 findings.`

On Linux and Mac M1 with private code repo - unresponsive at "checkmate git init" step
❯ export CODE_DIR="/Users/karthik.orugonda/Downloads/java-project-master"; docker run -e CODE_DIR -v ${CODE_DIR}:${CODE_DIR} -ti scanmycode/scanmycode3-ce:worker-cli-arm64 /bin/sh -c 'cd $CODE_DIR && checkmate git init' /root /Users/karthik.orugonda/Downloads/java-project-master /Users/karthik.orugonda/Downloads/java-project-master Loading plugin: git Loading plugin: trufflehog3 Loading plugin: trojansource Loading plugin: metrics Loading plugin: bandit Loading plugin: brakeman Loading plugin: phpanalyzer Loading plugin: gosec Loading plugin: confused Loading plugin: pmd Loading plugin: semgrep Loading plugin: semgrepdefi Loading plugin: semgrepjs Loading plugin: checkov

@ok-karthik I will add a check to make sure code is a git repo clone and CODE_DIR env var is set, so it can warn about it. Thanks for your hint.

I think your java-project-master is not a git repo, but just a directory with source files.

Do you have .git folder inside?

If not please run git init && git add . && git commit in it to make it a Git repo.

Let me know if it helps.

Closing due to inactivity