terrascan icon indicating copy to clipboard operation
terrascan copied to clipboard

Terrascan init fails on Windows since ~Oct 19 (?)

Open dotpaul opened this issue 1 year ago • 1 comments

  • terrascan version: 1.18.0, also repros on 1.18.3
  • Operating System: Windows

Description

Expected: running "terrascan init" should succeed on Windows

But it fails with: 2023-10-23T14:04:30.742-0700 error cli/init.go:42 failed to initialize terrascan. error : failed to fetch references from git repo. error: 'some refs were not updated'

As far as I can tell, this is happening because https://github.com/tenable/terrascan has branches that differ only by case, "CICD-test" and "cicd-test". I was able to use code similar to Terrascan's initialization to clone a repo and fetch references, on a forked Terrascan repo, with one of those branches deleted

What I Did

terrascan.exe init -l debug
2023-10-23T13:49:09.584-0700    debug   cli/register.go:66      TERRASCAN_CONFIG:
2023-10-23T13:49:09.594-0700    debug   config/config-reader.go:55      no config file specified
2023-10-23T13:49:09.598-0700    debug   utils/policy.go:43      absolute rego_subdir path, `C:\SecureApp\pkg\policies\opa\rego`, does not fall under base repo path's `C:\Users\paulming\.terrascan` directory structure
2023-10-23T13:49:09.599-0700    debug   utils/policy.go:44      appending rego_subdir path: `pkg\policies\opa\rego` to the policy base path: `C:\Users\paulming\.terrascan`. checking ...
2023-10-23T13:49:09.600-0700    debug   config/global.go:126    global config loaded
2023-10-23T13:49:09.601-0700    debug   initialize/run.go:52    initializing terrascan
2023-10-23T13:49:09.602-0700    debug   initialize/run.go:68    downloading policies
2023-10-23T13:49:09.603-0700    debug   initialize/run.go:69    base directory path : C:\Users\paulming\.terrascan
2023-10-23T13:49:10.075-0700    debug   initialize/run.go:225   policy directory path : https://github.com/tenable/terrascan.git
2023-10-23T13:49:10.075-0700    debug   initialize/run.go:226   policy repo url : https://github.com/tenable/terrascan.git
2023-10-23T13:49:10.075-0700    debug   initialize/run.go:227   policy repo git branch : master
2023-10-23T13:49:10.076-0700    debug   initialize/run.go:228   cloning terrascan repo at C:\Users\paulming\.terrascan
2023-10-23T13:50:43.052-0700    error   cli/init.go:42  failed to initialize terrascan. error : failed to fetch references from git repo. error: 'some refs were not updated'

dotpaul avatar Oct 23 '23 21:10 dotpaul

This has been happening for me as well on both Windows and MacOS for the last week or so. It seems to still clone the repo into ~/.terrascan, allowing subsequent runs of terrascan scan to pass, but even an initial terrascan init will still fail on the first pass. My repro:

  1. rm -rf ~/.terrascan
  2. terrascan init --> get the same error as above.

TylerJang27 avatar Oct 23 '23 22:10 TylerJang27