fix(terraform): avoid race on GIT_TERMINAL_PROMPT in remote module resolver#10956
Open
abidedavana wants to merge 1 commit into
Open
fix(terraform): avoid race on GIT_TERMINAL_PROMPT in remote module resolver#10956abidedavana wants to merge 1 commit into
abidedavana wants to merge 1 commit into
Conversation
…solver Setting and restoring the process-global GIT_TERMINAL_PROMPT around each download races with concurrent downloads: a deferred restore can re-enable the git credential prompt while another clone is still running, and the original value read by a second goroutine may be lost. Set the variable once, on the first remote download, and do not restore it. Fixes aquasecurity#10833
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…solver
Setting and restoring the process-global GIT_TERMINAL_PROMPT around each download races with concurrent downloads: a deferred restore can re-enable the git credential prompt while another clone is still running, and the original value read by a second goroutine may be lost. Set the variable once, on the first remote download, and do not restore it.
Fixes #10833
Description
This fixes the race on
GIT_TERMINAL_PROMPTdescribed in #10833.remoteResolver.download()used to save the current value ofGIT_TERMINAL_PROMPT, set it to0, and restore the old value with adefer. The variable is process-global, so when downloads run concurrently (for exampletrivy image, where layers are scanned in parallel) two calls can step on each other:git cloneis still running, so git can hang waiting for credentials instead of failing fast0as the "original" value and restores that, so the user's real value is lost for the rest of the processgo-getter doesn't let you pass an env var for a single git call (discussed in the issue), so the fix sets
GIT_TERMINAL_PROMPT=0once withsync.OnceValue, on the first remote download, and doesn't restore it. Nothing touches the environment unless a remote module actually gets downloaded. This is the approach suggested in the issue discussion.It's the same kind of fix as #10843, which fixed a race on the global
getter.Gettersin the same function.Before: concurrent module downloads can re-enable git's interactive prompt mid-clone (scan hangs on repos that ask for credentials), and the original
GIT_TERMINAL_PROMPTvalue can be silently lost.After: the prompt is disabled once for the lifetime of the process, only when a remote download happens. There is no restore, so there's nothing left to race.
About tests: I didn't add a new one. Because of the
sync.Once, any check of the env var inside the test binary depends on test order (once another test triggers the download path, a later assertion fails), and testing the setter on its own would just testos.Setenv. The existing integration tests in the resolvers package already rundownload()end to end, and they pass:(on Linux, including
TestResolveModuleFromCacheandTestResolveModuleFromCacheWithDifferentSubdir). golangci-lint v2.12.2 with--build-tags=integrationis also clean on the package.Related issues
GIT_TERMINAL_PROMPTsave/restore race in remote module resolver #10833Checklist