-
Notifications
You must be signed in to change notification settings - Fork 1.9k
(fix) Git Repo Cloning Error #4223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ameter . removed SkipAdditionalRefs flag, cloning using --mirror will include all the refs. put the check if userinfo is nil to avoid any crash due to invalid memory access.
Hey there, awesome. Did we check to see if it works well with the CI/CD flags? https://github.com/trufflesecurity/trufflehog?tab=readme-ov-file#12-scan-in-ci |
I did some testing around these flags and scanning is working. Do you see anyother area need to be tested out ? |
Moreover, With the help of my colleague @mustansir14, He created a testing public repo on bitbucket with
|
pkg/sources/git/git.go
Outdated
if params.userInfo == nil { | ||
if pass, ok := params.userInfo.Password(); ok { | ||
/* | ||
Sources: | ||
- https://medium.com/%40szpytfire/authenticating-with-github-via-a-personal-access-token-7c639a979eb3 | ||
- https://trinhngocthuyen.com/posts/tech/50-shades-of-git-remotes-and-authentication/#using-httpextraheader-config | ||
*/ | ||
authHeader := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", params.userInfo.Username(), pass))) | ||
gitArgs = append(gitArgs, "-c", fmt.Sprintf("http.extraHeader=Authorization: Basic %s", authHeader)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this block have changes?
#1918 tries to do this same thing, but uses the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requesting changes pending the outcome of an internal conversation about configurability
forceSkipBinaries = cli.Flag("force-skip-binaries", "Force skipping binaries.").Bool() | ||
forceSkipArchives = cli.Flag("force-skip-archives", "Force skipping archives.").Bool() | ||
skipAdditionalRefs = cli.Flag("skip-additional-refs", "Skip additional references.").Bool() | ||
useGitMirror = cli.Flag("use-git-mirror", "Use git mirror for git scans.").Bool() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we make this on by default for OSS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how we'd do that while still having it off by default when imported, btw:
Lines 454 to 455 in d3eb6c4
// OSS Default APK handling on | |
feature.EnableAPKHandler.Store(true) |
First of all special thanks to @dylanTruffle for the research and guidance how to solve this issue.
Description:
TL:DR; This PR uses --mirror flag to clone git repo to avoid error due to similar names of refs (tags, branches, pull requests etc). Also, This PR removes
SkipAdditionalRefs
flag which become unnecessary, since by default, using--mirror
, will bring all the refs.Multiple instances of git cloning issues were reported, if tags, branches, pull requests or releases in that repo have conflicting names.
The actual problem is how git refs (includes branches, tags, releases etc) are being cloned using parameter
-c remote.origin.fetch=+refs/*:refs/remotes/origin/*
. Which says that,👉 "Fetch ALL refs, whatever they are (branches, tags, pull requests,etc)**
👉 and map them into the local namespace refs/remotes/origin/*."
When two refs have similar name, Cloning get halt and error appears. This can be avoided if refs are being cloned under different head based on the type. e.g:
This solution does works but not auto-scalable if a new type of
refs
is added in future. Someone have to modify the above list of parameters to support it.Another solution is the flag
--mirror
which clones all the available refs in respected directory instead of atorigin
. It is lightweight as compare to-c remote.origin.fetch=+refs/*:refs/remotes/origin/*
because it does not bring the latest code to cloning directory which is actually not needed. Which is a win-win. Also, This PR removeSkipAdditionalRefs
flag which become unnecessary, since by default, using--mirror
, will bring all the refs.here are the successful cloning examples using
--mirror
:Checklist:
make test-community
)?make lint
this requires golangci-lint)?