diff --git a/lib/ood_core/job/adapters/systemd.rb b/lib/ood_core/job/adapters/systemd.rb index 99b3af1cf..4227dfba1 100644 --- a/lib/ood_core/job/adapters/systemd.rb +++ b/lib/ood_core/job/adapters/systemd.rb @@ -15,6 +15,7 @@ class Factory # @option config [Object] :ssh_hosts (nil) The list of permissable hosts, defaults to :submit_host # @option config [Object] :strict_host_checking (true) Set to false to disable strict host checking and updating the known_hosts file # @option config [Object] :submit_host The SSH target to connect to, may be the head of a round-robin + # @option config [Object] :ssh_keyfile The SSH Key file to use as identity. def self.build_systemd(config) c = config.to_h.symbolize_keys debug = c.fetch(:debug, false) @@ -22,6 +23,7 @@ def self.build_systemd(config) ssh_hosts = c.fetch(:ssh_hosts, [c[:submit_host]]) strict_host_checking = c.fetch(:strict_host_checking, true) submit_host = c[:submit_host] + ssh_keyfile = c.fetch(:ssh_keyfile, "") Adapters::LinuxSystemd.new( ssh_hosts: ssh_hosts, @@ -31,6 +33,7 @@ def self.build_systemd(config) ssh_hosts: ssh_hosts, strict_host_checking: strict_host_checking, submit_host: submit_host, + ssh_keyfile: ssh_keyfile, ) ) end diff --git a/lib/ood_core/job/adapters/systemd/launcher.rb b/lib/ood_core/job/adapters/systemd/launcher.rb index fb9d5e19a..71757a5bb 100644 --- a/lib/ood_core/job/adapters/systemd/launcher.rb +++ b/lib/ood_core/job/adapters/systemd/launcher.rb @@ -10,7 +10,7 @@ # @api private class OodCore::Job::Adapters::LinuxSystemd::Launcher attr_reader :debug, :site_timeout, :session_name_label, :ssh_hosts, - :strict_host_checking, :username + :strict_host_checking, :username, :ssh_keyfile # The root exception class that all LinuxSystemd adapter-specific exceptions inherit # from class Error < StandardError; end @@ -26,6 +26,7 @@ def initialize( ssh_hosts:, strict_host_checking: false, submit_host:, + ssh_keyfile: "", **_ ) @debug = !! debug @@ -35,6 +36,7 @@ def initialize( @strict_host_checking = strict_host_checking @submit_host = submit_host @username = Etc.getlogin + @ssh_keyfile = ssh_keyfile end # @param hostname [#to_s] The hostname to submit the work to @@ -97,27 +99,36 @@ def call(cmd, *args, env: {}, stdin: "") # if ! strict_host_checking # -o UserKnownHostsFile=/dev/null (do not update the user's known hosts file) # -o StrictHostKeyChecking=no (do no check the user's known hosts file) + # if ssh_keyfile + # -i ssh_keyfile (Use this keyfile location) # # @param destination_host [#to_s] the destination host you wish to ssh into # @param cmd [Array<#to_s>] the command to be executed on the destination host def ssh_cmd(destination_host, cmd) - if strict_host_checking - [ - 'ssh', '-t', - '-p', OodCore::Job::Adapters::Helper.ssh_port, - '-o', 'BatchMode=yes', - "#{username}@#{destination_host}" - ].concat(cmd) - else - [ - 'ssh', '-t', - '-p', OodCore::Job::Adapters::Helper.ssh_port, - '-o', 'BatchMode=yes', - '-o', 'UserKnownHostsFile=/dev/null', - '-o', 'StrictHostKeyChecking=no', - "#{username}@#{destination_host}" - ].concat(cmd) + + sshcmd=[ + 'ssh', '-t', + '-p', OodCore::Job::Adapters::Helper.ssh_port, + '-o', 'Batchmode=yes', + ] + + if !strict_host_checking + sshcmd.concat([ + '-o','StrictHostKeyChecking=no', + '-o','UserKnownHostsFile=/dev/null', + ]) end + + if (!ssh_keyfile.to_s.empty?) + sshcmd.concat([ + '-i',ssh_keyfile.to_s, + ]) + end + + sshcmd.concat([ + "#{username}@#{destination_host}" + ]).concat(cmd) + end def shell