Sitelet https://github.com/OSC/ood_core/pull/996
Skip to content

fix ssh_wrap to use Shellwords.escape - #996

Merged
johrstrom merged 2 commits into
masterfrom
fix-ssh-wrap-to-escape-remote-commands
Oct 5, 2026
Merged

johrstrom merged 2 commits into
masterfrom
fix-ssh-wrap-to-escape-remote-commands

Conversation

@Oglopf

@Oglopf Oglopf commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

ssh_wrap passed the command, its arguments, and env values through to ssh unescaped.
SSH does no escaping of its own — the remote shell re-parses the whole command string — so
any argument containing a shell metacharacter gets mangled.

The reporter's example: an LSF resource request like -R select[mem>4000] has its >
interpreted as a redirect on the remote host, so the job is never submitted correctly.
Arguments with spaces split, and env values were interpolated raw into
export KEY=VALUE;.

ssh_wrap now shell-escapes cmd_args and env values. The escaping happens after the
existing early return:

return cmd, cmd_args if submit_host.to_s.empty?

so sites not using submit_host are unaffected — they return before reaching it, and
Open3.capture3 passes arguments as separate argv entries with no shell involved.

Related issue

Closes #923

Testing

  • Tests included
  • No tests needed — reason: ___

Three existing assertions in spec/job/adapters/helper_spec.rb updated — they used a
Job Name fixture with a space and asserted the unescaped output. The two local-path
assertions are unchanged and confirm no behavior change without submit_host.

New test/job/adapters/helper_test.rb covers the reporter's select[mem>4000] case, a
semicolon, env values with spaces, and the no-submit_host path.

bundle exec rake test and bundle exec rake spec are green.

Checklist

  • Follows project code style and conventions
  • Documentation provided (if new feature, adapter or behavior change) — N/A
  • This is a large feature and was discussed in an issue first (if applicable) — N/A

Anything else?

Sites currently working around this will need to stop. @keysmashes noted manually
.shellescape-ing native arguments in submit.yml.erb to get LSF submission working
over SSH. After this, those get escaped twice. Worth a release note.

On double-escaping, per @johrstrom's caution on the issue: I checked the other escaping
in the adapters. torque.rb:136 escapes envvars, but that is in the hash-native branch
which submits through the pbs-ruby bindings, not through ssh_wrap — separate path, no
overlap. The Shellwords use in kubernetes/helper.rb is a split, not an escape.

Affects every adapter that submits over SSH: slurm, psij, pbspro, sge, htcondor, torque,
lsf.

@johrstrom johrstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested at OSC and it works for me for to both slurm (for sbatch and other things like sacctmgr) and linux host adapters.

@johrstrom
johrstrom merged commit af490e3 into master Oct 5, 2026
6 checks passed
@johrstrom
johrstrom deleted the fix-ssh-wrap-to-escape-remote-commands branch October 5, 2026 21:12
@Oglopf Oglopf mentioned this pull request Oct 5, 2026
1 task done
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.

ssh_wrap doesn't properly escape remote commands

2 participants