Repository navigation
Conversation
init with an sshFile used to run 'GIT_SSH_COMMAND=... terraform init ...' through bash -c, with the key path, binary path and backend config file name interpolated unquoted: spaces broke it and any of them could inject commands. It now runs terraform directly through the normal init path and passes GIT_SSH_COMMAND as an environment variable, with the key path POSIX single-quoted because git hands that value to sh. The sshFile still wins over a GIT_SSH_COMMAND in the caller's environment variables, as the bash prefix did. Behaviour changes: - SSH init no longer needs bash and runs the same command line as init. - redirectErrorStream now applies to SSH init (it was ignored before), so with it set, SSH init's stderr reaches the output listener as plain init's already did. - The full command line is no longer logged at WARN; an INFO line without the command or env values replaces it, the key path is logged at DEBUG. - StrictHostKeyChecking=no is unchanged.
|
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.



Problem
When
sshFilewas set,initran throughbash -c:The key path, the binary path and the backend config file name were interpolated unquoted. That breaks on spaces, and it is command injection if any of them is influenced by job input. This path also needed bash, ignored
redirectErrorStream, duplicated the init flag logic, and logged the whole command line at WARN.Change
GIT_SSH_COMMANDis set as an environment variable. Git runs it throughsh -c, so the key path inside it is POSIX single-quoted, with each'written as'\''.sshFilestill wins over aGIT_SSH_COMMANDinterraformEnvironmentVariables, as the old inline prefix did. Callers such as Terrakube pass user-controlled variables in that map, and a stray value, even"", would silently drop the key. Other commands still get the caller's value.-o StrictHostKeyChecking=nois unchanged on purpose. Changing the host key policy needs a separate decision.Behaviour changes
redirectErrorStreamnow applies to SSH init. With it on, stderr goes to the output listener, as plain init already did. Terrakube setsredirectErrorStream(true)everywhere.$, backticks or;now arrive literally.Tests
New tests in
TerraformClientApiTest, using a fake terraform binary:sh;',$HOME, backticks and;survives git-style splitting ofGIT_SSH_COMMAND;;arrives as one argument;sshFilebeats a caller'sGIT_SSH_COMMAND(both non-empty and"");redirectErrorStreamis honoured.A reviewer also ran real git with a fake
sshand saw the key path arrive intact. Dockerverify(temurin 17,--init): 45/45 in terraform-client.