Skip to content

Commit

Permalink
(puppetlabsGH-813) Standardize allowed options for PowerShell over SSH
Browse files Browse the repository at this point in the history
We now disallow tty/run-as when using PowerShell and allow extensions.
We don't fail if extension is set when not using PowerShell, though it
will be ignored.
  • Loading branch information
nicklewis committed Apr 13, 2020
1 parent 7ff43e5 commit 7ad113d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/bolt/config/transport/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class SSH < Base
desc: "Host name." },
"host-key-check" => { type: TrueClass,
desc: "Whether to perform host key validation when connecting." },
"extensions" => { type: Array,
desc: "List of file extensions that are accepted for scripts or tasks on Windows. "\
"Scripts with these file extensions rely on the target's file type "\
"association to run. For example, if Python is installed on the system, "\
"a `.py` script runs with `python.exe`. The extensions `.ps1`, `.rb`, and "\
"`.pp` are always allowed and run via hard-coded executables." },
"interpreters" => { type: Hash,
desc: "A map of an extension name to the absolute path of an executable, "\
"enabling you to override the shebang defined in a task executable. The "\
Expand Down Expand Up @@ -109,6 +115,15 @@ class SSH < Base
"run-as-command must be an Array of Strings, received #{run_as_cmd.class} #{run_as_cmd.inspect}"
end
end

if @config['login-shell'] == 'powershell'
%w[tty run-as].each do |key|
if @config[key]
raise Bolt::ValidationError,
"#{key} is not supported when using PowerShell"
end
end
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions spec/bolt/config/transport/ssh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,26 @@
expect(config['private-key']).to eq(File.expand_path('path/to/key', boltdir))
end
end

context "when using powershell" do
before :each do
data['login-shell'] = 'powershell'
end

it "fails if tty is true" do
data['tty'] = true
expect { transport.new(data) }.to raise_error(Bolt::ValidationError, /tty is not supported/)
end

it "fails if run-as is set" do
data['run-as'] = 'soandso'
expect { transport.new(data) }.to raise_error(Bolt::ValidationError, /run-as is not supported/)
end

it "doesn't fail if other run-as options are set" do
data['run-as-command'] = %w[foo bar baz]
expect { transport.new(data) }.not_to raise_error
end
end
end
end

0 comments on commit 7ad113d

Please sign in to comment.