Skip to content

Fix SSHRemoteJobOperator mangling environment values with spaces or shell characters - #74810

Merged
potiuk merged 2 commits into
apache:mainfrom
astronomer:fix-ssh-remote-job-env-quoting
Oct 15, 2026
Merged

potiuk merged 2 commits into
apache:mainfrom
astronomer:fix-ssh-remote-job-env-quoting

Conversation

@kaxil

@kaxil kaxil commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

closes: #74601

SSHRemoteJobOperator mangles any environment value that contains a space or a shell metacharacter on POSIX hosts. build_posix_wrapper_command escaped each value for one level of single quotes and wrote export KEY='value', but those export lines are pasted inside the single-quoted job_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 with words: 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.quote for the job shell, then escapes the export block once more for the job_script literal, which is the treatment the command already gets a few lines below. Values with no special characters now render as export KEY=value (shlex leaves them unquoted), so the existing string assertion changed accordingly.

Values are now passed literally, so $VAR in 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 extend PATH in command instead. This also matches SSHOperator and the Windows wrapper, which never expanded values.

The new test runs the real wrapper under bash and 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\\share reached the job as C:datashare with 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.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

kaxil added 2 commits October 15, 2026 18:44
…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.
@potiuk
potiuk merged commit e1d881b into apache:main Oct 15, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OS command injection (RCE) in SSHRemoteJobOperator via environment values

2 participants