Repository navigation
Fix SSHRemoteJobOperator mangling environment values with spaces or shell characters - #74810
Merged
Merged
Conversation
…hell characters On POSIX hosts each environment value was escaped for one level of single quotes, but the export lines are spliced into the single-quoted job_script literal, so the value's opening quote closed that literal. A value with a space broke the wrapper, and $(...), backticks or ; in a value were run by the wrapper shell instead of reaching the job. Quote each value with shlex.quote, then escape the export block for the job_script literal the same way the command already is.
Values used to be expanded by the remote shell as a side effect of the quoting bug, so $VAR in a value no longer works. Say so in the docstring and the operator docs, escape the exports and command in one step, and cover backslashes and braced variables in the test.
2 tasks done
potiuk
approved these changes
Oct 15, 2026
28 of 93 tasks
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.
closes: #74601
SSHRemoteJobOperatormangles anyenvironmentvalue that contains a space or a shell metacharacter on POSIX hosts.build_posix_wrapper_commandescaped each value for one level of single quotes and wroteexport KEY='value', but those export lines are pasted inside the single-quotedjob_script='...'literal. The value's own opening quote therefore closes that literal, and the value lands unquoted in the wrapper shell. So{"INPUT_FILE": "two words"}fails the submit withwords: command not found, and$(...), backticks or;in a value are run by the wrapper shell on the remote host instead of reaching the job.The fix quotes each value with
shlex.quotefor the job shell, then escapes the export block once more for thejob_scriptliteral, which is the treatment the command already gets a few lines below. Values with no special characters now render asexport KEY=value(shlex leaves them unquoted), so the existing string assertion changed accordingly.Values are now passed literally, so
$VARin a value is no longer expanded. Before, a value without spaces such as{"PATH": "$PATH:/opt/tools/bin"}happened to work, because the unquoted value was expanded by the wrapper shell. That came from the same bug, and it is what lets$(...)run, so the fix can't keep it. The docstring and operator docs now say values are literal and show how to extendPATHincommandinstead. This also matchesSSHOperatorand the Windows wrapper, which never expanded values.The new test runs the real wrapper under
bashand checks that no marker file appears and that the job's log holds the value verbatim, for spaces,$(...), backticks,;, embedded single and double quotes,$VAR,${PATH}and~, backslashes, a newline and the empty string. With the source change reverted, 9 of the 10 cases fail (the empty string passes either way). Backslashes were the quiet one:C:\data\\sharereached the job asC:datasharewith exit code 0.The Windows wrapper is not affected by this: its child script is base64-encoded via
-EncodedCommand, so env values only pass through one quoting level. #73352 is rewriting that wrapper separately.{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.