chef-provisioning-aws 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/Rakefile +1 -0
- data/lib/chef/provisioning/aws_driver/driver.rb +154 -21
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_instance.rb +1 -1
- metadata +3 -4
- data/spec/acceptance/aws_ebs_volume/nodes/ettores-mbp.lan.json +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5474ba34beb9fa261bd2c3abbe9561772bd36877
|
4
|
+
data.tar.gz: 602d8d0ce78d094d41e0982e97ddd42654528777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e410f83858985cc03647c57e074aafd8ad8ec7d9db663c0ed02c477823a33b70f06a7152b815c47298a35fbb8ef319565686fa7cade07db53100d4aea164322f
|
7
|
+
data.tar.gz: d42f36a75e6644ffc964e6cfc794e8cab50ca7622553e9310669d2630a5e5478a674581adcaadbf3f0e3003e5487efaa7b1a2a559ae03d2c73ef1438a34e3da0
|
data/README.md
CHANGED
@@ -149,6 +149,8 @@ with_machine_options({
|
|
149
149
|
use_private_ip_for_ssh: false, # DEPRECATED, use `transport_address_location`
|
150
150
|
transport_address_location: :public_ip, # `:public_ip` (default), `:private_ip` or `:dns`. Defines how SSH or WinRM should find an address to communicate with the instance.
|
151
151
|
is_windows: true, # false by default
|
152
|
+
winrm_username: "Administrator",
|
153
|
+
winrm_password: "password", # Override if you have specified your own password and are not fetching the password from AWS
|
152
154
|
})
|
153
155
|
```
|
154
156
|
|
@@ -181,7 +183,14 @@ load_balancer "my_elb" do
|
|
181
183
|
port: 443,
|
182
184
|
ssl_certificate_id: "arn:aws:iam::360965486607:server-certificate/cloudfront/foreflight-2015-07-09"
|
183
185
|
}
|
184
|
-
]
|
186
|
+
],
|
187
|
+
health_check: {
|
188
|
+
healthy_threshold: 2,
|
189
|
+
unhealthy_threshold: 4,
|
190
|
+
interval: 12,
|
191
|
+
timeout: 5,
|
192
|
+
target: 'HTTPS:443/_status'
|
193
|
+
}
|
185
194
|
})
|
186
195
|
```
|
187
196
|
|
data/Rakefile
CHANGED
@@ -53,6 +53,7 @@ RSpec::Core::RakeTask.new(:machine_image) do |spec|
|
|
53
53
|
spec.rspec_opts = "-b -t super_slow -e 'machine_image can create an image in the VPC'"
|
54
54
|
end
|
55
55
|
|
56
|
+
require "chef/provisioning/aws_driver/version"
|
56
57
|
require "github_changelog_generator/task"
|
57
58
|
|
58
59
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
@@ -598,6 +598,44 @@ winrm set winrm/config/service/auth '@{Basic="true"}'
|
|
598
598
|
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
|
599
599
|
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
|
600
600
|
|
601
|
+
net stop winrm
|
602
|
+
sc config winrm start=auto
|
603
|
+
net start winrm
|
604
|
+
</powershell>
|
605
|
+
EOD
|
606
|
+
end
|
607
|
+
|
608
|
+
def https_user_data
|
609
|
+
<<EOD
|
610
|
+
<powershell>
|
611
|
+
winrm quickconfig -q
|
612
|
+
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
|
613
|
+
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
|
614
|
+
|
615
|
+
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
|
616
|
+
|
617
|
+
$SourceStoreScope = 'LocalMachine'
|
618
|
+
$SourceStorename = 'Remote Desktop'
|
619
|
+
|
620
|
+
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
|
621
|
+
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
|
622
|
+
|
623
|
+
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
|
624
|
+
$_.subject -like '*'
|
625
|
+
}
|
626
|
+
|
627
|
+
$DestStoreScope = 'LocalMachine'
|
628
|
+
$DestStoreName = 'My'
|
629
|
+
|
630
|
+
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
|
631
|
+
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
|
632
|
+
$DestStore.Add($cert)
|
633
|
+
|
634
|
+
$SourceStore.Close()
|
635
|
+
$DestStore.Close()
|
636
|
+
|
637
|
+
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{Hostname=`"($certId)`"`;CertificateThumbprint=`"($cert.Thumbprint)`"`}
|
638
|
+
|
601
639
|
net stop winrm
|
602
640
|
sc config winrm start=auto
|
603
641
|
net start winrm
|
@@ -648,11 +686,14 @@ EOD
|
|
648
686
|
# sending out encrypted password, restarting instance, etc.
|
649
687
|
if machine_spec.reference['is_windows']
|
650
688
|
wait_until_machine(action_handler, machine_spec, "receive 'Windows is ready' message from the AWS console", instance) { |instance|
|
651
|
-
|
652
|
-
|
689
|
+
instance.console_output.output
|
690
|
+
# seems to be a bug as we need to run this twice
|
691
|
+
# to consistently ensure the output is fully pulled
|
692
|
+
encoded_output = instance.console_output.output
|
693
|
+
if encoded_output.nil? || encoded_output.empty?
|
653
694
|
false
|
654
695
|
else
|
655
|
-
output = Base64.decode64(
|
696
|
+
output = Base64.decode64(encoded_output)
|
656
697
|
output =~ /Message: Windows is Ready to use/
|
657
698
|
end
|
658
699
|
}
|
@@ -845,10 +886,18 @@ EOD
|
|
845
886
|
end
|
846
887
|
|
847
888
|
if machine_options[:is_windows]
|
848
|
-
Chef::Log.debug "Setting Default
|
849
|
-
|
889
|
+
Chef::Log.debug "Setting Default windows userdata based on WinRM transport"
|
890
|
+
if bootstrap_options[:user_data].nil?
|
891
|
+
case machine_options[:winrm_transport]
|
892
|
+
when 'https'
|
893
|
+
data = https_user_data
|
894
|
+
else
|
895
|
+
data = user_data
|
896
|
+
end
|
897
|
+
bootstrap_options[:user_data] = Base64.encode64(data)
|
898
|
+
end
|
850
899
|
else
|
851
|
-
Chef::Log.debug "Non-windows, not setting userdata"
|
900
|
+
Chef::Log.debug "Non-windows, not setting Default userdata"
|
852
901
|
end
|
853
902
|
|
854
903
|
bootstrap_options = AWSResource.lookup_options(bootstrap_options, managed_entry_store: machine_spec.managed_entry_store, driver: self)
|
@@ -984,31 +1033,115 @@ EOD
|
|
984
1033
|
|
985
1034
|
def create_winrm_transport(machine_spec, machine_options, instance)
|
986
1035
|
remote_host = determine_remote_host(machine_spec, instance)
|
1036
|
+
username = machine_options[:winrm_username] || 'Administrator'
|
1037
|
+
# default to http for now, should upgrade to https when knife support self-signed
|
1038
|
+
transport_type = machine_options[:winrm_transport] || 'http'
|
1039
|
+
type = case transport_type
|
1040
|
+
when 'http'
|
1041
|
+
:plaintext
|
1042
|
+
when 'https'
|
1043
|
+
:ssl
|
1044
|
+
end
|
1045
|
+
if machine_spec.reference[:winrm_port]
|
1046
|
+
port = machine_spec.reference[:winrm_port]
|
1047
|
+
else #default port
|
1048
|
+
port = case transport_type
|
1049
|
+
when 'http'
|
1050
|
+
'5985'
|
1051
|
+
when 'https'
|
1052
|
+
'5986'
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
endpoint = "#{transport_type}://#{remote_host}:#{port}/wsman"
|
987
1056
|
|
988
|
-
port = machine_spec.reference['winrm_port'] || 5985
|
989
|
-
endpoint = "http://#{remote_host}:#{port}/wsman"
|
990
|
-
type = :plaintext
|
991
1057
|
pem_bytes = get_private_key(instance.key_name)
|
992
1058
|
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
1059
|
+
if machine_options[:winrm_password]
|
1060
|
+
password = machine_options[:winrm_password]
|
1061
|
+
else # pull from ec2 and store in reference
|
1062
|
+
if machine_spec.reference['winrm_encrypted_password']
|
1063
|
+
decoded = Base64.decode64(machine_spec.reference['winrm_encrypted_password'])
|
1064
|
+
else
|
1065
|
+
encrypted_admin_password = instance.password_data.password_data
|
1066
|
+
if encrypted_admin_password.nil? || encrypted_admin_password.empty?
|
1067
|
+
raise "You did not specify winrm_password in the machine options and no encrytpted password could be fetched from the instance"
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
machine_spec.reference['winrm_encrypted_password']||=encrypted_admin_password
|
1071
|
+
# ^^ saves encrypted password to the machine_spec
|
1072
|
+
decoded = Base64.decode64(encrypted_admin_password)
|
999
1073
|
end
|
1000
|
-
|
1001
|
-
private_key = OpenSSL::PKey::RSA.new(
|
1074
|
+
# decrypt so we can utilize
|
1075
|
+
private_key = OpenSSL::PKey::RSA.new(get_private_key(instance.key_name))
|
1002
1076
|
password = private_key.private_decrypt decoded
|
1003
1077
|
end
|
1004
1078
|
|
1079
|
+
disable_sspi = machine_options[:winrm_disable_sspi] || false # default to Negotiate
|
1080
|
+
basic_auth_only = machine_options[:winrm_basic_auth_only] || false # disallow Basic auth by default
|
1081
|
+
no_ssl_peer_verification = machine_options[:winrm_no_ssl_peer_verification] || false #disallow MITM potential by default
|
1082
|
+
|
1005
1083
|
winrm_options = {
|
1006
|
-
:
|
1007
|
-
:
|
1008
|
-
:disable_sspi
|
1009
|
-
:basic_auth_only
|
1084
|
+
user: username,
|
1085
|
+
pass: password,
|
1086
|
+
disable_sspi: disable_sspi,
|
1087
|
+
basic_auth_only: basic_auth_only,
|
1088
|
+
no_ssl_peer_verification: no_ssl_peer_verification,
|
1010
1089
|
}
|
1011
1090
|
|
1091
|
+
if no_ssl_peer_verification or type != :ssl
|
1092
|
+
# => we won't verify certs at all
|
1093
|
+
Chef::Log.info "No SSL or no peer verification"
|
1094
|
+
elsif machine_spec.reference['winrm_ssl_thumbprint']
|
1095
|
+
# we have stored the cert
|
1096
|
+
Chef::Log.info "Using stored fingerprint"
|
1097
|
+
else
|
1098
|
+
# we need to retrieve the cert and verify it by connecting just to
|
1099
|
+
# retrieve the ssl certificate and compare it to what we see in the
|
1100
|
+
# console logs
|
1101
|
+
instance.console_output.data.output
|
1102
|
+
# again this seem to need to be run twice, to ensure
|
1103
|
+
encoded_output = instance.console_output.data.output
|
1104
|
+
console_lines = Base64.decode64(encoded_output).lines
|
1105
|
+
fp_context = OpenSSL::SSL::SSLContext.new
|
1106
|
+
tcp_connection = TCPSocket.new(instance.private_ip_address, port)
|
1107
|
+
ssl_connection = OpenSSL::SSL::SSLSocket.new(tcp_connection, fp_context)
|
1108
|
+
|
1109
|
+
begin
|
1110
|
+
ssl_connection.connect
|
1111
|
+
rescue OpenSSL::SSL::SSLError => e
|
1112
|
+
raise e unless e.message =~ /bad signature/
|
1113
|
+
ensure
|
1114
|
+
tcp_connection.close
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
winrm_cert = ssl_connection.peer_cert_chain.first
|
1118
|
+
|
1119
|
+
rdp_thumbprint = console_lines.grep(
|
1120
|
+
/RDPCERTIFICATE-THUMBPRINT/)[-1].split(': ').last.chomp
|
1121
|
+
rdp_subject = console_lines.grep(
|
1122
|
+
/RDPCERTIFICATE-SUBJECTNAME/)[-1].split(': ').last.chomp
|
1123
|
+
winrm_subject = winrm_cert.subject.to_s.split('=').last.upcase
|
1124
|
+
winrm_thumbprint=OpenSSL::Digest::SHA1.new(winrm_cert.to_der).to_s.upcase
|
1125
|
+
|
1126
|
+
if rdp_subject != winrm_subject or rdp_thumbprint != winrm_thumbprint
|
1127
|
+
Chef::Log.fatal "Winrm ssl port certificate differs from rdp console logs"
|
1128
|
+
end
|
1129
|
+
# now cache these for later use in the reference
|
1130
|
+
if machine_spec.reference['winrm_ssl_subject'] != winrm_subject
|
1131
|
+
machine_spec.reference['winrm_ssl_subject'] = winrm_subject
|
1132
|
+
end
|
1133
|
+
if machine_spec.reference['winrm_ssl_thumbprint'] != winrm_thumbprint
|
1134
|
+
machine_spec.reference['winrm_ssl_thumbprint'] = winrm_thumbprint
|
1135
|
+
end
|
1136
|
+
if machine_spec.reference['winrm_ssl_cert'] != winrm_cert.to_pem
|
1137
|
+
machine_spec.reference['winrm_ssl_cert'] = winrm_cert.to_pem
|
1138
|
+
end
|
1139
|
+
end
|
1140
|
+
|
1141
|
+
if machine_spec.reference['winrm_ssl_thumbprint']
|
1142
|
+
winrm_options[:ssl_peer_fingerprint] = machine_spec.reference['winrm_ssl_thumbprint']
|
1143
|
+
end
|
1144
|
+
|
1012
1145
|
Chef::Provisioning::Transport::WinRM.new("#{endpoint}", type, winrm_options, {})
|
1013
1146
|
end
|
1014
1147
|
|
@@ -13,7 +13,7 @@ class Chef::Resource::AwsInstance < Chef::Provisioning::AWSDriver::AWSResourceWi
|
|
13
13
|
attribute :name, kind_of: String, name_attribute: true
|
14
14
|
|
15
15
|
attribute :instance_id, kind_of: String, aws_id_attribute: true, default: lazy {
|
16
|
-
name =~ /^i-[a-f0-9]{8}$/ ? name : nil
|
16
|
+
name =~ /^i-(?:[a-f0-9]{8}|[a-f0-9]{17})$/ ? name : nil
|
17
17
|
}
|
18
18
|
|
19
19
|
def aws_object
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Ewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-provisioning
|
@@ -307,7 +307,6 @@ files:
|
|
307
307
|
- lib/chef/resource/aws_subnet.rb
|
308
308
|
- lib/chef/resource/aws_vpc.rb
|
309
309
|
- lib/chef/resource/aws_vpc_peering_connection.rb
|
310
|
-
- spec/acceptance/aws_ebs_volume/nodes/ettores-mbp.lan.json
|
311
310
|
- spec/aws_support.rb
|
312
311
|
- spec/aws_support/aws_resource_run_wrapper.rb
|
313
312
|
- spec/aws_support/deep_matcher.rb
|
@@ -372,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
372
371
|
version: '0'
|
373
372
|
requirements: []
|
374
373
|
rubyforge_project:
|
375
|
-
rubygems_version: 2.
|
374
|
+
rubygems_version: 2.6.3
|
376
375
|
signing_key:
|
377
376
|
specification_version: 4
|
378
377
|
summary: Provisioner for creating aws containers in Chef Provisioning.
|