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

Adding Winrm https support #24

Open
wants to merge 4 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+29 −3
Diff settings

Always

Just for now

View
@@ -26,6 +26,7 @@ if(Test-PendingReboot){ Invoke-Reboot }
Write-BoxstarterMessage "Setting up winrm"
netsh advfirewall firewall add rule name="WinRM-HTTP" dir=in localport=5985 protocol=TCP action=allow
netsh advfirewall firewall add rule name="WinRM-HTTPS" dir=in localport=5986 protocol=TCP action=allow

This comment has been minimized.

@hh

hh Dec 6, 2015

Windows Firewall change adding 5986

@hh

hh Dec 6, 2015

Windows Firewall change adding 5986

$enableArgs=@{Force=$true}
try {
@@ -42,4 +43,27 @@ Enable-WSManCredSSP -Force -Role Server
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
Write-BoxstarterMessage "winrm setup complete"
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
Write-BoxstarterMessage "Reusing RDP self-signed certificate for WinRM HTTPS"
$SourceStoreScope = 'LocalMachine'
$SourceStorename = 'Remote Desktop'
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$_.subject -like '*'
}
$DestStoreScope = 'LocalMachine'
$DestStoreName = 'My'
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$SourceStore.Close()
$DestStore.Close()
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{Hostname=`"($certId)`"`;CertificateThumbprint=`"($cert.Thumbprint)`"`}

This comment has been minimized.

@mwrock

mwrock Dec 6, 2015

Owner

This is cool. You'd probably also have to enable 5986 on the firewall too for this to work right?

@mwrock

mwrock Dec 6, 2015

Owner

This is cool. You'd probably also have to enable 5986 on the firewall too for this to work right?

This comment has been minimized.

@hh

hh Dec 6, 2015

Yeah, added above at line 29

@hh

hh Dec 6, 2015

Yeah, added above at line 29

This comment has been minimized.

@mwrock

mwrock Dec 6, 2015

Owner

It would be better to put this added block BEFORE lines 43-45. The reason is that as soon as those lines succeed, packer is able to successfully connect and will start the shutdown process. There's a good chance it will still succeed since the shutdown process includes a sysprep and so there is still a small amount of time for the remaining code to complete, but its just safer to always have those three lines at the very end.

@mwrock

mwrock Dec 6, 2015

Owner

It would be better to put this added block BEFORE lines 43-45. The reason is that as soon as those lines succeed, packer is able to successfully connect and will start the shutdown process. There's a good chance it will still succeed since the shutdown process includes a sysprep and so there is still a small amount of time for the remaining code to complete, but its just safer to always have those three lines at the very end.

Write-BoxstarterMessage "winrm setup complete"
View
@@ -4,6 +4,7 @@
"type": "virtualbox-iso",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm,tcp,,55985,,5985" ],
[ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm_ssl,tcp,,55986,,5986" ],

This comment has been minimized.

@mwrock

mwrock Dec 6, 2015

Owner

Looks like a duplicate forwarding?

@mwrock

mwrock Dec 6, 2015

Owner

Looks like a duplicate forwarding?

This comment has been minimized.

@hh

hh Dec 6, 2015

It's a second forwarding for https, so we can test both with same image.

@hh

hh Dec 6, 2015

It's a second forwarding for https, so we can test both with same image.

This comment has been minimized.

@mwrock

mwrock Dec 6, 2015

Owner

ah right. I must be getting old.

@mwrock

mwrock Dec 6, 2015

Owner

ah right. I must be getting old.

[ "modifyvm", "{{.Name}}", "--memory", "2048" ],
[ "modifyvm", "{{.Name}}", "--vram", "36" ],
[ "modifyvm", "{{.Name}}", "--cpus", "2" ]
@@ -29,14 +30,15 @@
"scripts/PackerShutdown.bat",
"scripts/package.ps1",
"scripts/SetupComplete-2012.cmd",
"scripts/test-command.ps1"
"scripts/Test-Command.ps1"
]
},
{
"name": "virtualbox-iso-atlas",
"type": "virtualbox-iso",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm,tcp,,55985,,5985" ],
[ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm_ssl,tcp,,55986,,5986" ],
[ "modifyvm", "{{.Name}}", "--memory", "2048" ],
[ "modifyvm", "{{.Name}}", "--vram", "36" ],
[ "modifyvm", "{{.Name}}", "--cpus", "2" ]
@@ -60,7 +62,7 @@
"scripts/PackerShutdown.bat",
"scripts/package.ps1",
"scripts/SetupComplete-2012.cmd",
"scripts/test-command.ps1"
"scripts/Test-Command.ps1"
]
}
],