knife-ec2 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +21 -0
- data/.travis.yml +15 -2
- data/CHANGELOG.md +9 -0
- data/README.md +20 -0
- data/RELEASE_NOTES.md +16 -12
- data/knife-ec2.gemspec +2 -2
- data/lib/chef/knife/ec2_ami_list.rb +36 -16
- data/lib/chef/knife/ec2_base.rb +2 -3
- data/lib/chef/knife/ec2_flavor_list.rb +14 -5
- data/lib/chef/knife/ec2_server_create.rb +86 -11
- data/lib/knife-ec2/version.rb +6 -6
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/ec2_ami_list_spec.rb +92 -8
- data/spec/unit/ec2_flavor_list_spec.rb +14 -4
- data/spec/unit/ec2_server_create_spec.rb +327 -29
- metadata +7 -13
- data/CONTRIBUTIONS.md +0 -6
data/lib/knife-ec2/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
module Knife
|
2
|
-
module Ec2
|
3
|
-
VERSION = "0.
|
4
|
-
MAJOR, MINOR, TINY = VERSION.split('.')
|
5
|
-
end
|
6
|
-
end
|
1
|
+
module Knife
|
2
|
+
module Ec2
|
3
|
+
VERSION = "0.16.0"
|
4
|
+
MAJOR, MINOR, TINY = VERSION.split('.')
|
5
|
+
end
|
6
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,7 @@ require 'chef/knife/ec2_server_create'
|
|
5
5
|
require 'chef/knife/ec2_server_delete'
|
6
6
|
require 'chef/knife/ec2_server_list'
|
7
7
|
require 'chef/knife/ec2_ami_list'
|
8
|
+
require 'chef/knife/ec2_flavor_list'
|
8
9
|
|
9
10
|
# Clear config between each example
|
10
11
|
# to avoid dependencies between examples
|
@@ -32,7 +32,7 @@
|
|
32
32
|
"deleteOnTermination"=>"true",
|
33
33
|
"volumeType"=>"standard",
|
34
34
|
"encrypted"=>"false"}],
|
35
|
-
'description' => "
|
35
|
+
'description' => "window winrm",
|
36
36
|
'hypervisor' => "xen",
|
37
37
|
'imageId' => "ami-4ace6d23",
|
38
38
|
'imageLocation' => "microsoft/Windows_Server-2008-R2-SP1-English-64Bit-WebMatrix_Hosting-2012.06.12",
|
@@ -80,7 +80,7 @@
|
|
80
80
|
"deleteOnTermination"=>"true",
|
81
81
|
"volumeType"=>"standard",
|
82
82
|
"encrypted"=>"false"}],
|
83
|
-
'description' => "
|
83
|
+
'description' => "ubuntu 14.04",
|
84
84
|
'hypervisor' => "xen",
|
85
85
|
'imageId' => "ami-4ace6d29",
|
86
86
|
'imageOwnerAlias' => "aws-marketplace",
|
@@ -133,7 +133,7 @@
|
|
133
133
|
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
134
134
|
expect(knife_ec2_ami_list).to receive(:validate!)
|
135
135
|
images = ec2_connection.describe_images.body['imagesSet']
|
136
|
-
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
136
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
137
137
|
output_column_count = output_column.length
|
138
138
|
images.each do |image|
|
139
139
|
output_column << image["imageId"].to_s
|
@@ -141,6 +141,7 @@
|
|
141
141
|
output_column << image["architecture"].to_s
|
142
142
|
output_column << image["blockDeviceMapping"].first["volumeSize"].to_s
|
143
143
|
output_column << image["name"].split(/\W+/).first
|
144
|
+
output_column << image["description"]
|
144
145
|
end
|
145
146
|
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
146
147
|
knife_ec2_ami_list.run
|
@@ -192,7 +193,7 @@
|
|
192
193
|
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
193
194
|
images = ec2_connection.describe_images.body['imagesSet']
|
194
195
|
expect(knife_ec2_ami_list).to receive(:validate!)
|
195
|
-
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
196
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
196
197
|
output_column_count = output_column.length
|
197
198
|
images.each do |image|
|
198
199
|
output_column << image["imageId"].to_s
|
@@ -200,6 +201,7 @@
|
|
200
201
|
output_column << image["architecture"].to_s
|
201
202
|
output_column << image["blockDeviceMapping"].first["volumeSize"].to_s
|
202
203
|
output_column << image["name"].split(/\W+/).first
|
204
|
+
output_column << image["description"]
|
203
205
|
end
|
204
206
|
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
205
207
|
knife_ec2_ami_list.run
|
@@ -212,13 +214,14 @@
|
|
212
214
|
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
213
215
|
window_image = ec2_connection.describe_images.body['imagesSet'].first
|
214
216
|
expect(knife_ec2_ami_list).to receive(:validate!)
|
215
|
-
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
217
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
216
218
|
output_column_count = output_column.length
|
217
219
|
output_column << window_image["imageId"]
|
218
220
|
output_column << window_image["platform"]
|
219
221
|
output_column << window_image["architecture"]
|
220
222
|
output_column << window_image["blockDeviceMapping"].first["volumeSize"].to_s
|
221
223
|
output_column << window_image["name"].split(/\W+/).first
|
224
|
+
output_column << window_image["description"]
|
222
225
|
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
223
226
|
knife_ec2_ami_list.run
|
224
227
|
end
|
@@ -230,13 +233,14 @@
|
|
230
233
|
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
231
234
|
ubuntu_image = ec2_connection.describe_images.body['imagesSet'][1]
|
232
235
|
expect(knife_ec2_ami_list).to receive(:validate!)
|
233
|
-
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
236
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
234
237
|
output_column_count = output_column.length
|
235
238
|
output_column << ubuntu_image["imageId"]
|
236
239
|
output_column << ubuntu_image["name"].split(/\W+/).first
|
237
240
|
output_column << ubuntu_image["architecture"]
|
238
241
|
output_column << ubuntu_image["blockDeviceMapping"].first["volumeSize"].to_s
|
239
242
|
output_column << ubuntu_image["name"].split(/\W+/).first
|
243
|
+
output_column << ubuntu_image["description"]
|
240
244
|
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
241
245
|
knife_ec2_ami_list.run
|
242
246
|
end
|
@@ -248,13 +252,14 @@
|
|
248
252
|
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
249
253
|
expect(knife_ec2_ami_list).to receive(:validate!)
|
250
254
|
fedora_image = ec2_connection.describe_images.body['imagesSet'].last
|
251
|
-
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
255
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
252
256
|
output_column_count = output_column.length
|
253
257
|
output_column << fedora_image["imageId"]
|
254
258
|
output_column << fedora_image["name"].split(/\W+/).first
|
255
259
|
output_column << fedora_image["architecture"]
|
256
260
|
output_column << fedora_image["blockDeviceMapping"].first["volumeSize"].to_s
|
257
261
|
output_column << fedora_image["name"].split(/\W+/).first
|
262
|
+
output_column << fedora_image["description"]
|
258
263
|
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
259
264
|
knife_ec2_ami_list.run
|
260
265
|
end
|
@@ -265,7 +270,86 @@
|
|
265
270
|
knife_ec2_ami_list.config[:platform] = 'xyz'
|
266
271
|
knife_ec2_ami_list.config[:use_iam_profile] = true
|
267
272
|
knife_ec2_ami_list.config[:owner] = true
|
268
|
-
expect{ knife_ec2_ami_list.validate! }.to raise_error "Invalid platform: #{knife_ec2_ami_list.config[:platform]}. Allowed platforms are: ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco, amazon, nessus."
|
273
|
+
expect{ knife_ec2_ami_list.validate! }.to raise_error "Invalid platform: #{knife_ec2_ami_list.config[:platform]}. Allowed platforms are: windows, ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco, amazon, nessus."
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context 'when --search is passed' do
|
279
|
+
before do
|
280
|
+
allow(knife_ec2_ami_list.ui).to receive(:warn)
|
281
|
+
allow(knife_ec2_ami_list).to receive(:custom_warnings!)
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'When search key word is present in description' do
|
285
|
+
it 'shows only AMIs List that have 14.04 in description' do
|
286
|
+
knife_ec2_ami_list.config[:search] = '14.04'
|
287
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
288
|
+
image = ec2_connection.describe_images.body['imagesSet'][2]
|
289
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
290
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
291
|
+
output_column_count = output_column.length
|
292
|
+
output_column << image["imageId"]
|
293
|
+
output_column << image["name"].split(/\W+/).first
|
294
|
+
output_column << image["architecture"]
|
295
|
+
output_column << image["blockDeviceMapping"].first["volumeSize"].to_s
|
296
|
+
output_column << image["name"].split(/\W+/).first
|
297
|
+
output_column << image["description"]
|
298
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
299
|
+
knife_ec2_ami_list.run
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context 'When user pass platform and search keyword' do
|
304
|
+
it 'shows only AMIs List that have 14.04 in description and platform is ubuntu' do
|
305
|
+
knife_ec2_ami_list.config[:platform] = 'ubuntu'
|
306
|
+
knife_ec2_ami_list.config[:search] = 'Quan'
|
307
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
308
|
+
ubuntu_image = ec2_connection.describe_images.body['imagesSet'][1]
|
309
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
310
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
311
|
+
output_column_count = output_column.length
|
312
|
+
output_column << ubuntu_image["imageId"]
|
313
|
+
output_column << ubuntu_image["name"].split(/\W+/).first
|
314
|
+
output_column << ubuntu_image["architecture"]
|
315
|
+
output_column << ubuntu_image["blockDeviceMapping"].first["volumeSize"].to_s
|
316
|
+
output_column << ubuntu_image["name"].split(/\W+/).first
|
317
|
+
output_column << ubuntu_image["description"]
|
318
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
319
|
+
knife_ec2_ami_list.run
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'When user pass owner, platform and search keyword' do
|
324
|
+
it 'shows only AMIs List that owner microsoft platform windows and search keyword is winrm' do
|
325
|
+
knife_ec2_ami_list.config[:owner] = 'microsoft'
|
326
|
+
knife_ec2_ami_list.config[:platform] = 'windows'
|
327
|
+
knife_ec2_ami_list.config[:search] = 'winrm'
|
328
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
329
|
+
ubuntu_image = ec2_connection.describe_images.body['imagesSet'].first
|
330
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
331
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
332
|
+
output_column_count = output_column.length
|
333
|
+
output_column << ubuntu_image["imageId"]
|
334
|
+
output_column << ubuntu_image["platform"]
|
335
|
+
output_column << ubuntu_image["architecture"]
|
336
|
+
output_column << ubuntu_image["blockDeviceMapping"].first["volumeSize"].to_s
|
337
|
+
output_column << ubuntu_image["name"].split(/\W+/).first
|
338
|
+
output_column << ubuntu_image["description"]
|
339
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
340
|
+
knife_ec2_ami_list.run
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context 'When search key word is not present in description' do
|
345
|
+
it 'Fetch no AMI' do
|
346
|
+
knife_ec2_ami_list.config[:search] = 'Not present'
|
347
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
348
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
349
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name", "Description"]
|
350
|
+
output_column_count = output_column.length
|
351
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
352
|
+
knife_ec2_ami_list.run
|
269
353
|
end
|
270
354
|
end
|
271
355
|
end
|
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
require File.expand_path('../../spec_helper', __FILE__)
|
17
17
|
require 'fog/aws'
|
18
|
-
require 'chef/knife/ec2_flavor_list'
|
19
18
|
|
20
19
|
describe Chef::Knife::Ec2FlavorList do
|
21
20
|
|
@@ -24,7 +23,7 @@ describe Chef::Knife::Ec2FlavorList do
|
|
24
23
|
let(:ec2_connection) { double(Fog::Compute::AWS) }
|
25
24
|
before do
|
26
25
|
allow(knife_flavor_list).to receive(:connection).and_return(ec2_connection)
|
27
|
-
@flavor1 = double("flavor1", :name => "High-CPU Medium", :architecture => "32
|
26
|
+
@flavor1 = double("flavor1", :name => "High-CPU Medium", :architecture => "32", :id => "c1.medium", :bits => "32", :cores => "5", :ram => "1740.8", :disk => "350", :ebs_optimized_available => "false", :instance_store_volumes => "0")
|
28
27
|
|
29
28
|
allow(ec2_connection).to receive(:flavors).and_return([@flavor1])
|
30
29
|
|
@@ -39,18 +38,29 @@ describe Chef::Knife::Ec2FlavorList do
|
|
39
38
|
knife_flavor_list.run
|
40
39
|
end
|
41
40
|
|
41
|
+
context 'when region is not specified' do
|
42
|
+
it 'shows warning that default region will be will be used' do
|
43
|
+
knife_flavor_list.config.delete(:region)
|
44
|
+
Chef::Config[:knife].delete(:region)
|
45
|
+
ec2_flavors = double(:sort_by => [])
|
46
|
+
allow(ec2_connection).to receive(:flavors).and_return(ec2_flavors)
|
47
|
+
allow(knife_flavor_list).to receive(:validate!)
|
48
|
+
expect(knife_flavor_list.ui).to receive(:warn).with("No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:")
|
49
|
+
knife_flavor_list.run
|
50
|
+
end
|
51
|
+
end
|
42
52
|
|
43
53
|
context '--format option' do
|
44
54
|
context 'when format=summary' do
|
45
55
|
before do
|
46
|
-
|
56
|
+
@output_s=["ID", "Name", "Architecture", "RAM", "Disk", "Cores", "c1.medium", "High-CPU Medium", "32-bit", "1740.8", "350 GB", "5"]
|
47
57
|
knife_flavor_list.config[:format] = 'summary'
|
48
58
|
allow(knife_flavor_list.ui).to receive(:warn)
|
49
59
|
allow(knife_flavor_list).to receive(:validate!)
|
50
60
|
end
|
51
61
|
|
52
62
|
it 'shows the output in summary format' do
|
53
|
-
expect(knife_flavor_list.ui).to receive(:list).with(@output_s
|
63
|
+
expect(knife_flavor_list.ui).to receive(:list).with(@output_s, :uneven_columns_across, 6)
|
54
64
|
knife_flavor_list.run
|
55
65
|
end
|
56
66
|
end
|
@@ -46,7 +46,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
46
46
|
:public_ip_address => '75.101.253.10',
|
47
47
|
:private_dns_name => 'ip-10-251-75-20.ec2.internal',
|
48
48
|
:private_ip_address => '10.251.75.20',
|
49
|
-
:root_device_type => 'not_ebs'
|
49
|
+
:root_device_type => 'not_ebs',
|
50
|
+
:block_device_mapping => [{'volumeId' => "456"}] } }
|
50
51
|
|
51
52
|
let (:server) { double(:id => "i-123" ) }
|
52
53
|
|
@@ -80,6 +81,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
80
81
|
end
|
81
82
|
|
82
83
|
allow(ec2_connection).to receive(:tags).and_return double('create', :create => true)
|
84
|
+
allow(ec2_connection).to receive(:volume_tags).and_return double('create', :create => true)
|
83
85
|
allow(ec2_connection).to receive_message_chain(:images, :get).and_return double('ami', :root_device_type => 'not_ebs', :platform => 'linux')
|
84
86
|
allow(ec2_connection).to receive(:addresses).and_return [double('addesses', {
|
85
87
|
:domain => 'standard',
|
@@ -281,7 +283,6 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
281
283
|
# default value of config[:ssh_password] is nil
|
282
284
|
knife_ec2_create.config[:winrm_password] = "winrm_password"
|
283
285
|
knife_ec2_create.config[:ssh_password] = nil
|
284
|
-
|
285
286
|
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
286
287
|
knife_ec2_create.run
|
287
288
|
expect(knife_ec2_create.config[:ssh_password]).to eq("winrm_password")
|
@@ -455,6 +456,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
455
456
|
allow(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
456
457
|
allow(knife_ec2_create).to receive(:puts)
|
457
458
|
allow(knife_ec2_create).to receive(:print)
|
459
|
+
allow(knife_ec2_create.ui).to receive(:error)
|
460
|
+
allow(knife_ec2_create.ui).to receive(:msg)
|
458
461
|
end
|
459
462
|
|
460
463
|
it "sets the Name tag to the instance id by default" do
|
@@ -490,6 +493,25 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
490
493
|
|
491
494
|
end
|
492
495
|
|
496
|
+
describe "when setting volume tags" do
|
497
|
+
before do
|
498
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
499
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", :run => true)
|
500
|
+
allow(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
501
|
+
allow(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
502
|
+
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
503
|
+
allow(knife_ec2_create.ui).to receive(:error)
|
504
|
+
end
|
505
|
+
|
506
|
+
it "sets the volume tags as specified when given --volume-tags Key=Value" do
|
507
|
+
knife_ec2_create.config[:volume_tags] = ["VolumeTagKey=TestVolumeTagValue"]
|
508
|
+
expect(ec2_connection.tags).to receive(:create).with(:key => "VolumeTagKey",
|
509
|
+
:value => "TestVolumeTagValue",
|
510
|
+
:resource_id => new_ec2_server.block_device_mapping.first['volumeId'])
|
511
|
+
knife_ec2_create.run
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
493
515
|
# This shared examples group can be used to house specifications that
|
494
516
|
# are common to both the Linux and Windows bootstraping process. This
|
495
517
|
# would remove a lot of testing duplication that is currently present.
|
@@ -1588,13 +1610,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1588
1610
|
If (-Not $vm_name) {
|
1589
1611
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1590
1612
|
}
|
1591
|
-
|
1613
|
+
|
1614
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1615
|
+
$name.Encode("CN=$vm_name", 0)
|
1616
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1617
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1618
|
+
$key.KeySpec = 1
|
1619
|
+
$key.Length = 2048
|
1620
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1621
|
+
$key.MachineContext = 1
|
1622
|
+
$key.Create()
|
1623
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1624
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1625
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1626
|
+
$ekuoids.add($serverauthoid)
|
1627
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1628
|
+
$ekuext.InitializeEncode($ekuoids)
|
1629
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1630
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1631
|
+
$cert.Subject = $name
|
1632
|
+
$cert.Issuer = $cert.Subject
|
1633
|
+
$cert.NotBefore = get-date
|
1634
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1635
|
+
$cert.X509Extensions.Add($ekuext)
|
1636
|
+
$cert.Encode()
|
1637
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1638
|
+
$enrollment.InitializeFromRequest($cert)
|
1639
|
+
$certdata = $enrollment.CreateRequest(0)
|
1640
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1641
|
+
|
1592
1642
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1593
1643
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1594
1644
|
iex $create_listener_cmd
|
1595
|
-
|
1596
1645
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1597
|
-
|
1598
1646
|
EOH
|
1599
1647
|
end
|
1600
1648
|
|
@@ -1607,7 +1655,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1607
1655
|
before do
|
1608
1656
|
knife_ec2_create.config[:winrm_user] = ".\\ec2"
|
1609
1657
|
@ssl_config_data = <<-EOH
|
1610
|
-
net user /add ec2 ec2@123;
|
1658
|
+
net user /add ec2 ec2@123 ;
|
1611
1659
|
net localgroup Administrators /add ec2;
|
1612
1660
|
|
1613
1661
|
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
@@ -1620,13 +1668,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1620
1668
|
If (-Not $vm_name) {
|
1621
1669
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1622
1670
|
}
|
1623
|
-
|
1671
|
+
|
1672
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1673
|
+
$name.Encode("CN=$vm_name", 0)
|
1674
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1675
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1676
|
+
$key.KeySpec = 1
|
1677
|
+
$key.Length = 2048
|
1678
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1679
|
+
$key.MachineContext = 1
|
1680
|
+
$key.Create()
|
1681
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1682
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1683
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1684
|
+
$ekuoids.add($serverauthoid)
|
1685
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1686
|
+
$ekuext.InitializeEncode($ekuoids)
|
1687
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1688
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1689
|
+
$cert.Subject = $name
|
1690
|
+
$cert.Issuer = $cert.Subject
|
1691
|
+
$cert.NotBefore = get-date
|
1692
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1693
|
+
$cert.X509Extensions.Add($ekuext)
|
1694
|
+
$cert.Encode()
|
1695
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1696
|
+
$enrollment.InitializeFromRequest($cert)
|
1697
|
+
$certdata = $enrollment.CreateRequest(0)
|
1698
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1699
|
+
|
1624
1700
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1625
1701
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1626
1702
|
iex $create_listener_cmd
|
1627
|
-
|
1628
1703
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1629
|
-
|
1630
1704
|
EOH
|
1631
1705
|
|
1632
1706
|
end
|
@@ -1680,7 +1754,35 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1680
1754
|
If (-Not $vm_name) {
|
1681
1755
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1682
1756
|
}
|
1683
|
-
|
1757
|
+
|
1758
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1759
|
+
$name.Encode("CN=$vm_name", 0)
|
1760
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1761
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1762
|
+
$key.KeySpec = 1
|
1763
|
+
$key.Length = 2048
|
1764
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1765
|
+
$key.MachineContext = 1
|
1766
|
+
$key.Create()
|
1767
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1768
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1769
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1770
|
+
$ekuoids.add($serverauthoid)
|
1771
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1772
|
+
$ekuext.InitializeEncode($ekuoids)
|
1773
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1774
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1775
|
+
$cert.Subject = $name
|
1776
|
+
$cert.Issuer = $cert.Subject
|
1777
|
+
$cert.NotBefore = get-date
|
1778
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1779
|
+
$cert.X509Extensions.Add($ekuext)
|
1780
|
+
$cert.Encode()
|
1781
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1782
|
+
$enrollment.InitializeFromRequest($cert)
|
1783
|
+
$certdata = $enrollment.CreateRequest(0)
|
1784
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1785
|
+
|
1684
1786
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1685
1787
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1686
1788
|
iex $create_listener_cmd
|
@@ -1694,7 +1796,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1694
1796
|
end
|
1695
1797
|
|
1696
1798
|
it 'returns false' do
|
1697
|
-
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(
|
1799
|
+
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(false)
|
1698
1800
|
end
|
1699
1801
|
end
|
1700
1802
|
|
@@ -1747,13 +1849,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1747
1849
|
If (-Not $vm_name) {
|
1748
1850
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1749
1851
|
}
|
1750
|
-
|
1852
|
+
|
1853
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1854
|
+
$name.Encode("CN=$vm_name", 0)
|
1855
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1856
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1857
|
+
$key.KeySpec = 1
|
1858
|
+
$key.Length = 2048
|
1859
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1860
|
+
$key.MachineContext = 1
|
1861
|
+
$key.Create()
|
1862
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1863
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1864
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1865
|
+
$ekuoids.add($serverauthoid)
|
1866
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1867
|
+
$ekuext.InitializeEncode($ekuoids)
|
1868
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1869
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1870
|
+
$cert.Subject = $name
|
1871
|
+
$cert.Issuer = $cert.Subject
|
1872
|
+
$cert.NotBefore = get-date
|
1873
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1874
|
+
$cert.X509Extensions.Add($ekuext)
|
1875
|
+
$cert.Encode()
|
1876
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1877
|
+
$enrollment.InitializeFromRequest($cert)
|
1878
|
+
$certdata = $enrollment.CreateRequest(0)
|
1879
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1880
|
+
|
1751
1881
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1752
1882
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1753
1883
|
iex $create_listener_cmd
|
1754
|
-
|
1755
1884
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1756
|
-
|
1757
1885
|
</powershell>
|
1758
1886
|
EOH
|
1759
1887
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
@@ -1797,13 +1925,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1797
1925
|
If (-Not $vm_name) {
|
1798
1926
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1799
1927
|
}
|
1800
|
-
|
1928
|
+
|
1929
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1930
|
+
$name.Encode("CN=$vm_name", 0)
|
1931
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1932
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1933
|
+
$key.KeySpec = 1
|
1934
|
+
$key.Length = 2048
|
1935
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1936
|
+
$key.MachineContext = 1
|
1937
|
+
$key.Create()
|
1938
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1939
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1940
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1941
|
+
$ekuoids.add($serverauthoid)
|
1942
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1943
|
+
$ekuext.InitializeEncode($ekuoids)
|
1944
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1945
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1946
|
+
$cert.Subject = $name
|
1947
|
+
$cert.Issuer = $cert.Subject
|
1948
|
+
$cert.NotBefore = get-date
|
1949
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1950
|
+
$cert.X509Extensions.Add($ekuext)
|
1951
|
+
$cert.Encode()
|
1952
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1953
|
+
$enrollment.InitializeFromRequest($cert)
|
1954
|
+
$certdata = $enrollment.CreateRequest(0)
|
1955
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1956
|
+
|
1801
1957
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1802
1958
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1803
1959
|
iex $create_listener_cmd
|
1804
|
-
|
1805
1960
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1806
|
-
|
1807
1961
|
</powershell>
|
1808
1962
|
EOH
|
1809
1963
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
@@ -1840,13 +1994,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1840
1994
|
If (-Not $vm_name) {
|
1841
1995
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1842
1996
|
}
|
1843
|
-
|
1997
|
+
|
1998
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1999
|
+
$name.Encode("CN=$vm_name", 0)
|
2000
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2001
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2002
|
+
$key.KeySpec = 1
|
2003
|
+
$key.Length = 2048
|
2004
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2005
|
+
$key.MachineContext = 1
|
2006
|
+
$key.Create()
|
2007
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2008
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2009
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2010
|
+
$ekuoids.add($serverauthoid)
|
2011
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2012
|
+
$ekuext.InitializeEncode($ekuoids)
|
2013
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2014
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2015
|
+
$cert.Subject = $name
|
2016
|
+
$cert.Issuer = $cert.Subject
|
2017
|
+
$cert.NotBefore = get-date
|
2018
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2019
|
+
$cert.X509Extensions.Add($ekuext)
|
2020
|
+
$cert.Encode()
|
2021
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2022
|
+
$enrollment.InitializeFromRequest($cert)
|
2023
|
+
$certdata = $enrollment.CreateRequest(0)
|
2024
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2025
|
+
|
1844
2026
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1845
2027
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1846
2028
|
iex $create_listener_cmd
|
1847
|
-
|
1848
2029
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1849
|
-
|
1850
2030
|
</powershell>
|
1851
2031
|
EOH
|
1852
2032
|
end
|
@@ -1865,13 +2045,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1865
2045
|
If (-Not $vm_name) {
|
1866
2046
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1867
2047
|
}
|
1868
|
-
|
2048
|
+
|
2049
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2050
|
+
$name.Encode("CN=$vm_name", 0)
|
2051
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2052
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2053
|
+
$key.KeySpec = 1
|
2054
|
+
$key.Length = 2048
|
2055
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2056
|
+
$key.MachineContext = 1
|
2057
|
+
$key.Create()
|
2058
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2059
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2060
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2061
|
+
$ekuoids.add($serverauthoid)
|
2062
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2063
|
+
$ekuext.InitializeEncode($ekuoids)
|
2064
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2065
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2066
|
+
$cert.Subject = $name
|
2067
|
+
$cert.Issuer = $cert.Subject
|
2068
|
+
$cert.NotBefore = get-date
|
2069
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2070
|
+
$cert.X509Extensions.Add($ekuext)
|
2071
|
+
$cert.Encode()
|
2072
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2073
|
+
$enrollment.InitializeFromRequest($cert)
|
2074
|
+
$certdata = $enrollment.CreateRequest(0)
|
2075
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2076
|
+
|
1869
2077
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1870
2078
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1871
2079
|
iex $create_listener_cmd
|
1872
|
-
|
1873
2080
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1874
|
-
|
1875
2081
|
</powershell>
|
1876
2082
|
EOH
|
1877
2083
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
@@ -1952,13 +2158,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1952
2158
|
If (-Not $vm_name) {
|
1953
2159
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1954
2160
|
}
|
1955
|
-
|
2161
|
+
|
2162
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2163
|
+
$name.Encode("CN=$vm_name", 0)
|
2164
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2165
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2166
|
+
$key.KeySpec = 1
|
2167
|
+
$key.Length = 2048
|
2168
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2169
|
+
$key.MachineContext = 1
|
2170
|
+
$key.Create()
|
2171
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2172
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2173
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2174
|
+
$ekuoids.add($serverauthoid)
|
2175
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2176
|
+
$ekuext.InitializeEncode($ekuoids)
|
2177
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2178
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2179
|
+
$cert.Subject = $name
|
2180
|
+
$cert.Issuer = $cert.Subject
|
2181
|
+
$cert.NotBefore = get-date
|
2182
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2183
|
+
$cert.X509Extensions.Add($ekuext)
|
2184
|
+
$cert.Encode()
|
2185
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2186
|
+
$enrollment.InitializeFromRequest($cert)
|
2187
|
+
$certdata = $enrollment.CreateRequest(0)
|
2188
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2189
|
+
|
1956
2190
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1957
2191
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1958
2192
|
iex $create_listener_cmd
|
1959
|
-
|
1960
2193
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1961
|
-
|
1962
2194
|
</powershell>
|
1963
2195
|
<script>
|
1964
2196
|
|
@@ -1996,13 +2228,39 @@ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public
|
|
1996
2228
|
If (-Not $vm_name) {
|
1997
2229
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1998
2230
|
}
|
1999
|
-
|
2231
|
+
|
2232
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2233
|
+
$name.Encode("CN=$vm_name", 0)
|
2234
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2235
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2236
|
+
$key.KeySpec = 1
|
2237
|
+
$key.Length = 2048
|
2238
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2239
|
+
$key.MachineContext = 1
|
2240
|
+
$key.Create()
|
2241
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2242
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2243
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2244
|
+
$ekuoids.add($serverauthoid)
|
2245
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2246
|
+
$ekuext.InitializeEncode($ekuoids)
|
2247
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2248
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2249
|
+
$cert.Subject = $name
|
2250
|
+
$cert.Issuer = $cert.Subject
|
2251
|
+
$cert.NotBefore = get-date
|
2252
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2253
|
+
$cert.X509Extensions.Add($ekuext)
|
2254
|
+
$cert.Encode()
|
2255
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2256
|
+
$enrollment.InitializeFromRequest($cert)
|
2257
|
+
$certdata = $enrollment.CreateRequest(0)
|
2258
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2259
|
+
|
2000
2260
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2001
2261
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2002
2262
|
iex $create_listener_cmd
|
2003
|
-
|
2004
2263
|
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2005
|
-
|
2006
2264
|
</powershell>
|
2007
2265
|
EOH
|
2008
2266
|
end
|
@@ -2330,4 +2588,44 @@ netstat > c:\\netstat_data.txt
|
|
2330
2588
|
end
|
2331
2589
|
end
|
2332
2590
|
|
2591
|
+
describe 'Handle password greater than 14 characters' do
|
2592
|
+
before do
|
2593
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2594
|
+
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
2595
|
+
knife_ec2_create.config[:winrm_password] = "LongPassword@123"
|
2596
|
+
end
|
2597
|
+
|
2598
|
+
context 'when user enters Y after prompt' do
|
2599
|
+
before do
|
2600
|
+
allow(STDIN).to receive_message_chain(:gets, :chomp => "Y")
|
2601
|
+
end
|
2602
|
+
it 'user addition command is executed forcefully' do
|
2603
|
+
expect(knife_ec2_create.ui).to receive(:warn).with('The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):')
|
2604
|
+
knife_ec2_create.validate!
|
2605
|
+
expect(knife_ec2_create.instance_variable_get(:@allow_long_password)).to eq ("/yes")
|
2606
|
+
end
|
2607
|
+
end
|
2608
|
+
|
2609
|
+
context 'when user enters n after prompt' do
|
2610
|
+
before do
|
2611
|
+
allow(STDIN).to receive_message_chain(:gets, :chomp => "N")
|
2612
|
+
end
|
2613
|
+
it 'operation exits' do
|
2614
|
+
expect(knife_ec2_create.ui).to receive(:warn).with('The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):')
|
2615
|
+
expect{ knife_ec2_create.validate! }.to raise_error("Exiting as operation with password greater than 14 characters not accepted")
|
2616
|
+
end
|
2617
|
+
end
|
2618
|
+
|
2619
|
+
context 'when user enters xyz instead of (Y/N) after prompt' do
|
2620
|
+
before do
|
2621
|
+
allow(STDIN).to receive_message_chain(:gets, :chomp => "xyz")
|
2622
|
+
end
|
2623
|
+
it 'operation exits' do
|
2624
|
+
expect(knife_ec2_create.ui).to receive(:warn).with('The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):')
|
2625
|
+
expect{ knife_ec2_create.validate! }.to raise_error("The input provided is incorrect.")
|
2626
|
+
end
|
2627
|
+
end
|
2628
|
+
|
2629
|
+
end
|
2630
|
+
|
2333
2631
|
end
|