Oracle recently announced a new authentication plugin: caching_sha2_password
. This was added in 8.0.4, the second release candidate for MySQL 8.0. The new plugin is also made the default (can be configured by changing default_authentication_plugin
.
Why?
Phasing out SHA1
As Oracle said in the blog post to annouce this change they want to move to a more secure hashing algorithm (SHA256). Which I think is a good reason to do this.
Adding salt
Adding a salt makes hashes for identical passwords, but different users different. Again a good reason to do this.
Performance
Their earlier attempt at this resulted in sha256_password
. But this resulted in slower authentication. Without using persistent connections this is a serious limitation. So again a good reason.
What's wrong?
If you don't use SSL/TLS it gives your password away.
To protect against sending the password in cleartext over an insecure connection it encrypts the password before sending it. It does this by using public key cryptography. It encrypts the password with the public key of the server. Then the server can decrypt it with its private key. So far so good.
But the problem is how MySQL gets the public from the server. There is --get-server-public-key
which requests the key from the server. But it does so over an insecure connection, so this isn't safe.
An attacker could do a Man-in-the-Middle attack and give you their public key... and then the attacker can decrypt your password and proxy the connection.
The second option is to use --server-public-key-path=file_name
. But then you somehow need to collect all public keys from all your servers and securely distribute them to your clients. And you might want to renew these keys every year... this seems like an operational nightmare to me.
Also depending on what connector you use these options may not be available.
If you use SSL/TLS things are not much better.
With default settings mysqld generates self-signed X509 certificates and enables SSL/TLS. And the default ssl-mode
is PREFERRED
. This is better than the previous defaults as it guards against passive attacks. However this is NOT protecting against active attacks (MitM attacks) as MySQL won't verify if the certificate is signed by a known CA. It by default also doesn't verify if the hostname matches the certificate.
So if someone hijacks your connection and knowns how to do a SSL handshake: then the caching_sha2_password
plugin will handover the password in clear text.
Can we use it in a secure way?
Use SSL/TLS and set ssl-mode
to VERIFY_IDENTITY
(or at least VERIFY_CA
). Note that this requires you to configure MySQL with certificates which are signed by your CA and matches the hostnames of your servers.
In case you only need localhost connections: configure MySQL to only listen on local-loopback and you're done.
Staying with mysql_native_password
seems also to be an acceptable option for now. Note that sha256_password
has many of the same issues and should also be avoided without strict SSL/TLS settings.
I initially reported this to Oracle in Bug #79944 on 13 January 2016 for the sha256_password
plugin in 5.7.10.
No comments:
Post a Comment