Skip to main content
TCloud
Silver ⭐️⭐️⭐️
Jul 8, 2019 3:43 AM UTC
Solved

SSLError: certificate verify failed

How do I enable further debugging on cloudera-scm-agents?

 

I'm working on deploying the cluster using self signed certificates but I'm running into the below issue and can't get past it:

 

[07/Jul/2019 23:35:05 +0000] 23766 MainThread agent ERROR Heartbeating to cm-r01nn01.mws.mds.xyz:7182 failed.
Traceback (most recent call last):
File "/opt/cloudera/cm-agent/lib/python2.7/site-packages/cmf/agent.py", line 1387, in _send_heartbeat
self.cfg.max_cert_depth)
File "/opt/cloudera/cm-agent/lib/python2.7/site-packages/cmf/https.py", line 139, in __init__
self.conn.connect()
File "/opt/cloudera/cm-agent/lib/python2.7/site-packages/M2Crypto/httpslib.py", line 69, in connect
sock.connect((self.host, self.port))
File "/opt/cloudera/cm-agent/lib/python2.7/site-packages/M2Crypto/SSL/Connection.py", line 309, in connect
ret = self.connect_ssl()
File "/opt/cloudera/cm-agent/lib/python2.7/site-packages/M2Crypto/SSL/Connection.py", line 295, in connect_ssl
return m2.ssl_connect(self.ssl, self._timeout)
SSLError: certificate verify failed

What I have in my certificates folder is the following:

 

[root@cm-r01en01 pki]# pwd
/opt/cloudera/security/pki
[root@cm-r01en01 pki]# ls -atlri
total 16
69943167 -rw-r--r--. 1 root root 2385 Apr 1 23:06 cm-r01en01.mws.mds.xyz.keystore.jks
69943152 -rw-r--r--. 1 root root 1453 Apr 1 23:07 cm-r01en01.mws.mds.xyz.pem
3870062 drwxr-xr-x. 5 root root 37 Apr 1 23:09 ..
69943169 lrwxrwxrwx. 1 root root 62 Apr 1 23:11 server.jks -> /opt/cloudera/security/pki/cm-r01en01.mws.mds.xyz.keystore.jks
69943259 -rw-r--r--. 1 root root 1453 Jul 6 20:01 cm-r01nn01.mws.mds.xyz.pem
69943154 lrwxrwxrwx. 1 root root 53 Jul 6 20:02 rootca.pem -> /opt/cloudera/security/pki/cm-r01nn01.mws.mds.xyz.pem
67689060 lrwxrwxrwx. 1 root root 53 Jul 6 20:36 agent.pem -> /opt/cloudera/security/pki/cm-r01en01.mws.mds.xyz.pem
69943151 drwxr-xr-x. 2 root root 4096 Jul 6 20:36 .
[root@cm-r01en01 pki]#

I'm not 100% sure if I have everything right though.  My cloudera-scm-agent config for that one host:

 

[root@cm-r01en01 pki]# cat /etc/cloudera-scm-agent/config.ini|grep -v "#" | sed -e "/^$/d"
[General]
server_host=cm-r01nn01.mws.mds.xyz
server_port=7182
max_collection_wait_seconds=10.0
metrics_url_timeout_seconds=30.0
task_metrics_timeout_seconds=5.0
monitored_nodev_filesystem_types=nfs,nfs4,tmpfs
local_filesystem_whitelist=ext2,ext3,ext4,xfs
impala_profile_bundle_max_bytes=1073741824
stacks_log_bundle_max_bytes=1073741824
stacks_log_max_uncompressed_file_size_bytes=5242880
orphan_process_dir_staleness_threshold=5184000
orphan_process_dir_refresh_interval=3600
scm_debug=DEBUG
dns_resolution_collection_interval_seconds=60
dns_resolution_collection_timeout_seconds=30
[Security]
use_tls=1
max_cert_depth=9
verify_cert_file=/opt/cloudera/security/pki/agent.pem
verify_cert_dir=/opt/cloudera/security/pki/
[Hadoop]
[Cloudera]
[JDBC]
[Cgroup_Paths]
[root@cm-r01en01 pki]#

cm-r01nn01 is the Name Node.

cm -r01en01 will be the gateway  / entry point to the cluster.  It will also run a few services.  

 

This is CM 6.2 .  I'm looking to go through the certificate process in preparation for a more formal deployment later on w/ official certificates.  Using self signed certs for now for this POC.

 

In particular, what certificate has it tried to load and is looking for?  How do I enable further debug logs to see all the calls it's making and files it's loading?

 

Cheers,
TK

bgooley
bgooleyAnswer
Gold ⭐️
Aug 2, 2019 12:12 AM UTC

@TCloud,

The exception is in the agent and indicates to us that the agent is not able to verify the certificate that was returned by Cloudera Manager during the TLS handshake.

In order to know why, we should look at what host the agent tried to contact (server_host in config.ini) and what certificates were listed in the SAN of the server certificate.

You can use the following command to see what certificate is returned:

openssl s_client -connect $(grep "server_host" /etc/cloudera-scm-agent/config.ini | sed s/server_host=//):7182 </dev/null | openssl x509 -text -noout

Then, check to make sure agent's truststore has the proper certificate that trusts the CM cert.  To test, you can use:

openssl s_client -connect $(grep -v '^#' /etc/cloudera-scm-agent/config.ini | grep "server_host=" | sed s/server_host=//):7182 -CAfile $(grep -v '^#' /etc/cloudera-scm-agent/config.ini | grep "verify_cert_file=" |sed s/verify_cert_file=//) -verify_hostname $(grep -v '^#' /etc/cloudera-scm-agent/config.ini | grep "server_host=" | sed s/server_host=//)</dev/null

 

The above is probably not that elegant, but you should be able to run it as it is.  It will grab your hostname and trust store file from the host's config.ini and then connect to your CM host to do a TLS handshake.  "-verify_hostname" will tell openssl to also do hostname validation to mimic what the agent does.

 

The result code of the above command should give us a better idea of why the handshake is failing.

 

23 replies

bgooley
Gold ⭐️
Gold ⭐️
Jul 8, 2019 4:25 PM UTC

Hi @TCloud ,

 

Thank you for including all this information.

I see that you have both verify_cert_dir and verify_cert_file configured, but one or the other should be chosen.  It appears you are configured for verify_cert_dir based on your directory listing.

 

I would recommend:

 

- commenting out verify_cert_dir by insertinga "#" character at the beginning of the line

- restarting the agent by executing "service cloudera-scm-server restart"

 

If that doesn't work, we can take a closer look at the certificates returned by Cloudera Manager and the certificates in your agent.pem file.

 

 

Translate
TCloud
TCloudAuthor
Silver ⭐️⭐️⭐️
Jul 9, 2019 4:26 AM UTC

First, appreciate you looking into this.

 

Just left verify_cert_file in place in /etc/cloudera-scm-agent/config.ini and same issue occurs.

 

Quite certain I got the certs incorrectly configured.  The reason why I'm thinking that is because I pointed agent.pem to various .pem files I have in the above-said folder.  Same result.

 

I also have an HAproxy / Keepalived configuration pointing to a common VIP  between the NN's called cm-c01.mws.mds.xyz .  That works fine for the CM UI, however, I'm trying the agent connection to the primary server directly at first to get that working before trying via the VIP.  So for the purpose of this exercise, I'm not using this VIP.  

 

Here's my cert process:

 

1) Generate a cert.

 

 

keytool -genkeypair -alias $(hostname -f) -keyalg RSA -keysize 2048 -dname "cn=$(hostname -f),OU=MDS,O=MDS,L=Los Angeles,ST=California,C=US" -keypass $(hostname -f) -keystore $(hostname -f).keystore.jks -storepass $(hostname -f) -validity 3650 -ext EKU=serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,OCSPSigning -ext san=dns:$(hostname -f)

 

2) Export cert from keystore.

 

 

keytool -export -alias $(hostname -f) -keystore $(hostname -f).keystore.jks -rfc -file $(hostname -f)-selfsigned.cer

 

3) Import the cert into the java truststores.

 

 

# Import root ca to the JDK Truststore
keytool -import -alias $(hostname -f) -file /opt/cloudera/security/jks/$(hostname -f)-selfsigned.cer -keystore /etc/pki/ca-trust/extracted/java/jssecacerts -storepass changeit



# Import root ca to the JDK Truststore
keytool -import -alias $(hostname -f) -file /opt/cloudera/security/jks/$(hostname -f)-selfsigned.cer -keystore /usr/java/jdk1.8.0_181-cloudera/jre/lib/security/jssecacerts -storepass changeit

 

 

4) Copy the files around and verify.

 

 

cp -ip /opt/cloudera/security/x509/$(hostname -f).pem /opt/cloudera/security/pki/$(hostname -f).pem;

cp -ip /opt/cloudera/security/x509/$(hostname -f).pem /opt/cloudera/security/pki/;
cp -ip /opt/cloudera/security/jks/$(hostname -f).keystore.jks /opt/cloudera/security/pki;

ln -s /opt/cloudera/security/pki/$(hostname -f).keystore.jks /opt/cloudera/security/pki/server.jks
ln -s /opt/cloudera/security/pki/$(hostname -f).pem /opt/cloudera/security/pki/agent.pem

 

 

openssl x509 -in /opt/cloudera/security/pki/$(hostname -f).pem -noout -text

 

5) Repeat the above on the other hosts.  

 

6) HTTPS / 7183 works fine from CM, just not the agent to server communication, now that I have it enabled.  

 

The parts I'm not clear about stems from my intermediate knowledge of certs:

 

A)  Do I copy the generated cert off the CM / NN server to the other servers in the cluster?

B)  Should I be exporting the private key from the SSL keystore by I) converting to pcs12 II) exporting the cert and key from that?  One of the dozens of options I tried included this step but that didn't work out either when I was trying the connectivity of the cloudera-scm-agent on the NN instead of any other participating host:  

 

keytool -importkeystore \
-srckeystore cm-r01nn01.mws.mds.xyz.keystore.jks \
-destkeystore cm-r01nn01.mws.mds.xyz.keystore.p12 \
-deststoretype PKCS12 \
-srcalias cm-c01.mws.mds.xyz \
-deststorepass cm-r01nn01.mws.mds.xyz \
-destkeypass cm-r01nn01.mws.mds.xyz


# openssl pkcs12 -in cm-r01nn01.mws.mds.xyz.keystore.p12 -nokeys -out cm-r01nn01.mws.mds.xyz.cert.pem
Enter Import Password:
MAC verified OK
#

# openssl pkcs12 -in cm-r01nn01.mws.mds.xyz.keystore.p12 -nodes -nocerts -out cm-r01nn01.mws.mds.xyz.key.pem
Enter Import Password:
MAC verified OK
#

Thinking I might have the commands right, just not the sequence or I'm missing a step or two.  Further notes and info:

 

[ UTILITY NODE ]

 

[root@cm-r01en01 pki]# keytool -list -keystore /etc/pki/ca-trust/extracted/java/jssecacerts|grep cm
Enter keystore password: changeit
acraizfnmt-rcm, Mar 26, 2019, trustedCertEntry,
cm-r01nn02.mws.mds.xyz, Apr 14, 2019, trustedCertEntry,
cm-r01en01.mws.mds.xyz, Apr 1, 2019, trustedCertEntry,
cm-r01nn01.mws.mds.xyz, Apr 14, 2019, trustedCertEntry,
[root@cm-r01en01 pki]#

[ Name Node / CM Server]

 

[root@cm-r01nn01 pki]# keytool -list -keystore /etc/pki/ca-trust/extracted/java/jssecacerts|grep cm
Enter keystore password: changeit
acraizfnmt-rcm, Mar 26, 2019, trustedCertEntry,
cm-r01nn02.mws.mds.xyz, Apr 14, 2019, trustedCertEntry,
cm-c01.mws.mds.xyz, Jul 6, 2019, trustedCertEntry,
cm-r01nn01.mws.mds.xyz, Mar 31, 2019, trustedCertEntry,
[root@cm-r01nn01 pki]#

 

The only other message that I got when moving certs around under the agent.pem symlink, was:

 

SSLError: sslv3 alert bad certificate

 

I'm not clear if that error is a step forward or backwards.  Also, discovered by accident that I may not need to restart the cloudera-scm-agent under every scenario.  Just changing where the symlink agent.pem points too appear to generate different messages, even when the agent is running.  


Thx,
TK

 

Translate
bgooley
Gold ⭐️
Gold ⭐️
Jul 9, 2019 4:49 PM UTC

@TCloud,

 

If you are using self-signed certificates, then it sounds as if you may have things right.

For the heartbeat issue, though, we can use openssl to see if we have things configured correctly and also see what public certificate is returned by Cloudera Manager for the heartbeat

 

Run:

 

# openssl s_client -connect cm-r01nn01.mws.mds.xyz:7182 -showcerts -CAfile /opt/cloudera/security/pki/cm-r01en01.mws.mds.xyz.pem

 

I believe you will still get an error now that you have explained some of the backstory.

 

When the agent is making a connection to CM to perform the heartbeat, it needs to do a TLS handshake per your configuration.  Part of this handshake is the client (the agent) deciding if it trusts the certificate returned from CM.

 

In your config.ini, you are connecting to the CM host: cm-r01nn01.mws.mds.xyz

However, your pem file name indicates that you are pointing verify_cert_file to the agent's host's certificate, not the certificate of the Cloudera Manager host.

 

In essence, the agent needs to trust the certificate returned by CM in the handshake.

So, the verify_cert_file file will need to contain the certificate for cm-r01nn01.mws.mds.xyz

 

If that doesn't make sense, provide the output from the openssl command above and then also the output from:

 

# openssl x509 -in /opt/cloudera/security/pki/cm-r01en01.mws.mds.xyz.pem -text -noout

 

From that we can provide further advice.

Translate