Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement changes to enable basic authentication for winrm by using --basic-auth CLI option. #6

Open
wants to merge 1 commit into
base: kd/ec2-winrm-ssl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ec2-user-data/winrm-http.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
<%= "winrm set winrm/config/service '@{AllowUnencrypted=\"true\"}'
winrm set winrm/config/service/auth '@{Basic=\"true\"}'" if defined?(basic_auth) && basic_auth %>

echo "winrm e winrm/config/listener" >> $env:temp\knife-ec2-user-data.log
winrm e winrm/config/listener >> $env:temp\knife-ec2-user-data.log
Expand Down
8 changes: 7 additions & 1 deletion lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ class Ec2ServerCreate < Knife
:boolean => true,
:default => false

option :basic_auth,
:long => "--basic-auth",
:description => "Enable Basic authentication for winrm on VM. Default is false",
:boolean => true,
:default => false

def tcp_test_winrm(ip_addr, port)
tcp_socket = TCPSocket.new(ip_addr, port)
yield
Expand Down Expand Up @@ -710,7 +716,7 @@ def load_windows_user_data
})
else
winrm_cfg_ps = ERBHelpers::ERBCompiler.run(
File.read(File.join(user_data_scripts_dir, "winrm-http.erb")), {})
File.read(File.join(user_data_scripts_dir, "winrm-http.erb")), {:basic_auth => locate_config_value(:basic_auth)})
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@
server_def[:user_data].should include("$fwpolicy.Rules.Add($fwrule)")
end

it "enable basic authentication for winrm on --basic-auth CLI option set" do
@knife_ec2_create.config[:basic_auth] = true
server_def = @knife_ec2_create.create_server_def
server_def[:user_data].should include("winrm set winrm/config/service '@{AllowUnencrypted=\"true\"}'")
server_def[:user_data].should include("winrm set winrm/config/service/auth '@{Basic=\"true\"}'")
end

context "winrm-transport set to ssl" do
before(:each) do
@knife_ec2_create.config[:winrm_transport] = "ssl"
Expand Down