salt-cloud and winrm failing with : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
Description of Issue/Question
Trying to create a Windows Minion in EC2 results in the following error:
[DEBUG ] Attempting WinRM connection to host 172.30.12.228 on port 5986
[ERROR ] There was a profile error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765)
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/cloud/cli.py", line 284, in run
self.config.get('names')
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1451, in run_profile
ret[name] = self.create(vm_)
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1281, in create
output = self.clouds[func](vm_)
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 2546, in create
vm_, data, ip_address, display_ssh_output
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 2241, in wait_for_instance
timeout=ssh_connect_timeout):
File "/usr/lib/python2.7/site-packages/salt/utils/cloud.py", line 838, in wait_for_winrm
r = s.run_cmd('sc query winrm')
File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 37, in run_cmd
shell_id = self.protocol.open_shell()
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 173, in send_message
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765)
Setup
base_teamcityserver:
provider: redacted-ec2
image: ami-fdf77aea
size: t2.micro
use_winrm: True
userdata_file: /etc/salt/windows-firewall.ps1
win_installer: /etc/salt/Salt-Minion-2016.3.1-AMD64-Setup.exe
win_installer_args: -G -H "http://172.30.0.143:3128"
win_username: Administrator
win_password: 'redacted'
win_interface: private_ips
smb_port: 445
script: bootstrap-salt
script_args: -G -H "http://172.30.0.143:3128"
subnetid: subnet-redacted
securitygroupid:
- sg-redacted
Steps to Reproduce Issue
salt-cloud -p base_teamcityserver teamcitytest1 -l debug
This will run until the aforementioned error is produced.
Versions Report
salt --versions-report
Salt Version:
Salt: 2016.3.0-n/a-764f56f
Dependency Versions:
cffi: Not Installed
cherrypy: 6.1.0
dateutil: 2.5.3
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.7
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.5 (default, Oct 11 2015, 17:47:16)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.7.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: redhat 7.2 Maipo
machine: x86_64
release: 3.10.0-327.22.2.el7.x86_64
system: Linux
version: Red Hat Enterprise Linux Server 7.2 Maipo
@yamamushi I don't think you're supposed to be using the script: bootstrap-salt and script_args: -G -H "http://172.30.0.143:3128" options with Windows VMs. The bootstrap-salt.sh script is meant for linux distros, and not windows installations.
I think the responses from @techhat and @twangboy in the other issue you referenced above will be helpful here. However, where did you get the win_installer_args option? That is not a supported option.
I'd like to see what @techhat or @twangboy think about this issue as well.
@rallytime those arguments are just things I've tried in #34785 .
As related to this particular issue, removing those arguments doesn't change the error I'm getting when trying to create the instances in EC2.
Updated profile with those arguments removed:
Profile
test_teamcityserver:
provider: redacted-ec2
image: ami-fdf77aea
size: t2.micro
use_winrm: True
userdata_file: /etc/salt/windows-firewall.ps1
win_installer: /etc/salt/Salt-Minion-2016.3.1-AMD64-Setup.exe
win_username: Administrator
win_password: 'redacted'
win_interface: private_ips
smb_port: 445
subnetid: subnet-redacted
securitygroupid:
- sg-redacted
Error log:
[DEBUG ] Attempting WinRM connection to host 172.30.11.33 on port 5986
[ERROR ] There was a profile error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765)
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/cloud/cli.py", line 284, in run
self.config.get('names')
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1451, in run_profile
ret[name] = self.create(vm_)
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1281, in create
output = self.clouds[func](vm_)
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 2546, in create
vm_, data, ip_address, display_ssh_output
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 2241, in wait_for_instance
timeout=ssh_connect_timeout):
File "/usr/lib/python2.7/site-packages/salt/utils/cloud.py", line 838, in wait_for_winrm
r = s.run_cmd('sc query winrm')
File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 37, in run_cmd
shell_id = self.protocol.open_shell()
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 173, in send_message
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765)
Versions Report
Salt Version:
Salt: 2016.3.0-n/a-764f56f
Dependency Versions:
cffi: Not Installed
cherrypy: 6.1.0
dateutil: 2.5.3
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.7
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.5 (default, Oct 11 2015, 17:47:16)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.7.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: redhat 7.2 Maipo
machine: x86_64
release: 3.10.0-327.22.2.el7.x86_64
system: Linux
version: Red Hat Enterprise Linux Server 7.2 Maipo
Thanks for posting this extra info @yamamushi. Unfortunately, I do not know very much about Windows and salt-cloud and how to set up something like this or how to implement passing parameters onto a script. I'll wait for @techhat and @twangboy to chime in.
@yamamushi may be missing the private_key setting which should point to your .pem file containing your certificate for amazon. This is how you authenticate.
@yamamushi you also need the keyname setting
@yamamushi It can be in either the profile or the provider file
@yamamushi You may also be missing the id and key settings in the provider file
@twangboy
Provider Config
redacted-ec2:
driver: ec2
id: 'redacted'
key: 'redacted'
private_key: /etc/salt/minion_key.pem
keyname: saltminion
securitygroupid: sg-redacted
minion:
master: 172.30.2.118
mine_functions:
private_ip:
- mine_function: network.interface_ip
- inet
mine_interval: 5
location: us-east-1
availability_zone: us-east-1a
ssh_interface: private_ips
rename_on_destroy: True
win_deploy_auth_retries: 10
win_deploy_auth_retry_delay: 120
It's worth noting that this config works on a machine with this salt version output:
Salt Version:
Salt: 2016.3.0
Dependency Versions:
Jinja2: 2.7.2
M2Crypto: 0.21.1
Mako: Not Installed
PyYAML: 3.11
PyZMQ: 14.7.0
Python: 2.7.5 (default, Oct 11 2015, 17:47:16)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
cffi: 0.8.6
cherrypy: 5.0.1
dateutil: 2.4.2
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
libgit2: 0.21.0
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.7
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pygit2: 0.21.4
python-gnupg: Not Installed
smmap: 0.8.1
timelib: Not Installed
System Versions:
dist: redhat 7.2 Maipo
machine: x86_64
release: 3.10.0-327.el7.x86_64
system: Red Hat Enterprise Linux Server 7.2 Maipo
@UtahDave Do you have any ideas here?
I recall seeing this with winexe when I didn't have impacket installed...
Maybe a firewall issue... are you passing the Powershell script for winrm? https://docs.saltstack.com/en/latest/topics/cloud/windows.html#firewall-settings
Here's a list of the pip packages installed (which shows impacket is installed):
pip list
aws (0.2.5)
awscli (1.10.47)
Babel (0.9.6)
backports.ssl-match-hostname (3.4.0.2)
boto (2.41.0)
botocore (1.4.37)
chardet (2.2.1)
CherryPy (6.1.0)
cloud-init (0.7.6)
colorama (0.3.7)
configobj (4.7.2)
decorator (3.4.0)
docutils (0.12)
ec2 (0.4.0)
ecdsa (0.13)
ethtool (0.8)
Fabric (1.11.1)
futures (3.0.5)
gyp (0.1)
impacket (0.9.15)
iniparse (0.4)
IPy (0.75)
Jinja2 (2.7.2)
jmespath (0.9.0)
jsonpatch (1.2)
jsonpointer (1.9)
kitchen (1.1.1)
lxml (3.2.1)
M2Crypto (0.21.1)
MarkupSafe (0.11)
msgpack-python (0.4.7)
paramiko (1.17.1)
pciutils (1.7.3)
perf (0.1)
pip (8.1.2)
policycoreutils-default-encoding (0.1)
prettytable (0.7.2)
pyasn1 (0.1.9)
pycrypto (2.6.1)
pycurl (7.19.0)
pygobject (3.14.0)
pygpgme (0.3)
pyliblzma (0.5.3)
pyOpenSSL (0.13.1)
pyserial (2.6)
python-dateutil (2.5.3)
python-dmidecode (3.10.13)
python-ntlm3 (1.0.2)
pyudev (0.15)
pywinrm (0.2.0)
pyxattr (0.5.1)
PyYAML (3.11)
pyzmq (14.7.0)
requests (2.6.0)
requests-ntlm (0.3.0)
rhnlib (2.5.65)
rhsm (1.15.4)
rsa (3.4.2)
s3transfer (0.0.1)
salt (2016.3.0-n-a-764f56f)
seobject (0.1)
sepolicy (1.1)
setuptools (0.9.8)
six (1.9.0)
tornado (4.2.1)
urlgrabber (3.10)
urllib3 (1.10.2)
wheel (0.29.0)
xmltodict (0.10.2)
yum-metadata-parser (1.1.4)
And here is the powershell script that is being run (which is the same script being run on the salt master that works):
<powershell>
New-NetFirewallRule -Name "SMB445" -DisplayName "SMB445" -Protocol TCP -LocalPort 445
New-NetFirewallRule -Name "WINRM5986" -DisplayName "WINRM5986" -Protocol TCP -LocalPort 5986
New-NetFirewallRule -Name "TEAMCITYUI" -DisplayName "TEAMCITYUI" -Protocol TCP -LocalPort 8111
New-NetFirewallRule -Name "TEAMCITYBUILD" -DisplayName "Allow TeamCity" -Direction Inbound -Protocol TCP -LocalPort 9090 -Program "c:\program files\java\jre7\bin\java.exe" -Action Allow
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
$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)`"`}
Restart-Service winrm
</powershell>
@twangboy @UtahDave , I found this StackOverflow post about this particular issue, but I'm honestly not very sure where to apply the suggested fix:
http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error
I'm also not sure if this is an issue originating in WinRM or if it's something that needs to be fixed on the Salt side (I'm leaning towards WinRM).
This same issue was also brought up about a month ago on the mailing list:
https://groups.google.com/forum/m/#!msg/salt-users/w-pr9II4YBM/_faS5vxsIAAJ
Any pointers would be appreciated. At the moment I'm not tied to absolutely needing to check the certificates as a security requirement, since we're deploying these instances in a private VPC, so if I had way to ignore the certificate checks that would be enough to get me around this particular problem.
I'm going to try snapshotting the working salt master that we have, and spinning it up in the VPC environment to see if the problem is isolated to the VPC environment as well.
@techhat Do you see anything here? ^^^^
@twangboy @UtahDave , might there be any new updates on working around this problem?
the root cause of your problem is that the powershell script that configure WINRM uses a self signed certificate for HTTPS communications. The default behavior in the Protocol class in winrm is to make strict validation of SSL certificate before opening a WINRM session. Because you are using a self signed certificate, this validation fails. Unfortunately, Salt does not override this default behaviour. As a temporary (ugly) workaround, I changed the default value for the property "server_cert_validation" from "validate" to "ignore" for the protocol class in pywinrm. I hope a fix will be found into cloud.py in salt
@Slayer09 Could you post that fix here? :-)
Finally, I did a rollback of my change in the Protocol class in pywinrm and changed the wait_for_winrm function in /usr/lib/python2.7/site-packages/salt/utils/cloud.py. At line 834, I add parameter server_cert_validation='ignore' to the call to winrm.Session. see below the modified function:
820 def wait_for_winrm(host, port, username, password, timeout=900):
821 '''
822 Wait until WinRM connection can be established.
823 '''
824 start = time.time()
825 log.debug(
826 'Attempting WinRM connection to host {0} on port {1}'.format(
827 host, port
828 )
829 )
830 trycount = 0
831 while True:
832 trycount += 1
833 try:
834 s = winrm.Session(host, auth=(username, password), transport='ssl', server_cert_validation='ignore')
835 if hasattr(s.protocol, 'set_timeout'):
836 s.protocol.set_timeout(15)
837 log.trace('WinRM endpoint url: {0}'.format(s.url))
838 r = s.run_cmd('sc query winrm')
839 if r.status_code == 0:
840 log.debug('WinRM session connected...')
841 return s
842 log.debug('Return code was {0}'.format(r.status_code))
843 time.sleep(1)
844 except WinRMTransportError as exc:
845 log.debug('Caught exception in wait_for_winrm: {0}'.format(exc))
846 if time.time() - start > timeout:
847 log.error('WinRM connection timed out: {0}'.format(timeout))
848 return None
849 log.debug(
850 'Retrying WinRM connection to host {0} on port {1} '
851 '(try {2})'.format(
852 host, port, trycount
853 )
854 )
855 time.sleep(1)