-
Notifications
You must be signed in to change notification settings - Fork 119
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
ssl_peer_fingerprint_verification for self-signed certs #151
Comments
Works out of box for aws-marketplace/CIS Microsoft Windows Server 2012 R2 Benchmark v1.1.0-26bb465c-ce26-4da9-afb8-040b2f8c9a7f-ami-7a88f312.2
However after I run wsus updates something changes:
(I'll try and rerun these using only the WinRM gem, but I don't yet have decent test harness for this) |
Yeah I think for the purposes of changes to winrm, bypassing knife-windows and working directly against the winrm gem would be best. Its possible your auth errors are domain related. knife winrm uses negotiate authentication and if your server is domain joined, only domain accounts can auth via negotiate. See https://github.com/chef/knife-windows#platform-winrm-authentication-support for details. If your node is NOT domain joined, then thats not the issue. This auth issue asside, specifying the fingerprint of the self signed RDP cert is an interesting approach. While I dont see it in your sample, I'm assuming you are installing the cert in the root cert store of the knife workstation? Otherwise I'd expect to see errors regarding the cert not being signed by a valid authority. While it is convenient to use the RDP cert since it is already created, I'd be inclined to:
I am NOT an expert in X509 certificate security, so while your suggested approach "seems" legit, I'm always nervous to try out something new in this area. Its definitely not the convention. For example, Azure creates a cert for its IAAS VMs and allows you to grab it via |
I wish there was the AWS equivalent of Get-AzureCertificate, the closest thing we have is looking at the console output and grabbing the fingerprint... hence my taking this approach:
We don't actually have a copy of the certificate until the instance is connectable. Then we verify the SSL Fingerprint in a couple places:
I do see the benefits to generating self-signed certs, however:
Overall I think it would be nice to have an option to do it either way. |
This also reminds me of how the Fog API works with VMWare/vSphere: https://github.com/fog/fog/blob/master/lib/fog/vsphere/compute.rb#L455 |
I'm digging the way they rescue then compare the fingerprint |
#150 cleaned up a bit |
Yeah. We could duplicate here where in the event that that the SSL negotiation succeeds, we just wouldn't even deal with the thumbprint. However, it would seem wrong not to check it if you explicitly are saying THIS is the cert I want to use. |
Yes, if you specify the exact cert you want THAT cert. You don't care if something in your cert chain says it's ok. |
Going to debug that wsus_update issue noted above.... the machine isn't joining a domain. Maybe it's something specific to the CIS 2012 Benchmark: https://benchmarks.cisecurity.org/downloads/show-single/?file=windows2012R2.200 |
I've not run into any issue with the fingerprinting so far with this patch. I'd like to get at checkpoint here with others and see if we are ready to merge. |
Here is what I see for merge requirements:
|
PR is green (rubocop done). |
I've looked at the current tests... these changes actually connect to a tcp socket and retrieve the certificate / fingerprint. Is this something we want to stub out in ssl_socket.connect just for testing? |
I tried to create an integration test but I'm not sure how we would create a winrm listener that we would know the fingerprint / certificate for. (on ec2 it's provided via the api) I thought about running a helper but I'm not sure how / where to save it and make sure it doesn't run again against a box it's already run on: def create_https_listener
winrm = winrm_connection
#reuse the rdp certificate for winrm:
winrm.run_powershell_script(<<POWERSHELL)
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
$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)`"`}
net stop winrm
sc config winrm start=auto
net start winrm
POWERSHELL
end |
I think it might be easiest just to update the base image for this and include a known ssl fiingerprint... |
sorry @hh but I've been a bit swamped the last few days.I'll do some testing on my end and we'll try to get this merged soon. Thanks! |
fixed via #170 |
I've coded up a working spike for this at #150 which is in use by chef/knife-windows#298 and chef-boneyard/chef-provisioning-aws#348
The text was updated successfully, but these errors were encountered: