Skip to content
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

Error: ER_NOT_SUPPORTED_AUTH_MODE with auth_socket #1507

Open
abou7mied opened this issue Aug 26, 2016 · 29 comments
Open

Error: ER_NOT_SUPPORTED_AUTH_MODE with auth_socket #1507

abou7mied opened this issue Aug 26, 2016 · 29 comments
Assignees
Labels

Comments

@abou7mied
Copy link

abou7mied commented Aug 26, 2016

Yesterday I upgraded my ubuntu distribution an MySql Server was updated too.
But when I connect I get this error
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

My connection code:

var mysql = require('mysql');
var connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'test_db',
  // insecureAuth : true,
});

connection.query('SELECT * FROM users', function(err, rows, fields) {
  if (err) throw err;
});

I tried to set insecureAuth: true but no changes

@abou7mied abou7mied changed the title Error: ER_NOT_SUPPORTED_AUTH_MODE after upgrade to 5.17.13 Error: ER_NOT_SUPPORTED_AUTH_MODE after upgrade mysql-server to 5.17.13 Aug 26, 2016
@dougwilson
Copy link
Member

What auth modes do you have configured for your server?

@abou7mied
Copy link
Author

I'm working on local, and I didn't set any auth mode, maybe the default mode have been changed in the update of my-sql server?

Or what is the default of this mysql-driver then I set it in my config?
http://dev.mysql.com/doc/refman/5.7/en/mysql-command-options.html#option_mysql_default-auth

@abou7mied
Copy link
Author

Problem solved!

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

http://stackoverflow.com/a/36234358/1431224

Changing plugin to mysql_native_password solved the problem :)!

@dougwilson
Copy link
Member

I just installed 5.17.13 on Ubuntu and was able to connect just fine without changing anything. I'm not sure how to proceed. Would it be possible to provide a packet capture of the traffic between this module and your server? Do other Node.js modules like "mysql2" work?

@sidorares
Copy link
Member

could you console.log server hello packet? Add console.log(this) before this line -

@dougwilson
Copy link
Member

Haha, we all replied at the same time :) I'm not sure why mine worked out of the box, but glad to get this figured out.

@sidorares
Copy link
Member

@abou7mied what was the old value for plugin in mysql.user table? Yes, currently this driver only supports mysql_native_password and mysql_old_password auth methods ( mysql2 does not support mysql_old_password but allows to set AuthSwitch handler )

@abou7mied
Copy link
Author

abou7mied commented Aug 27, 2016

Actually I didn't try to figure out what was the old value, I just liked the part when I changed the plugin then it worked 😄

Thanks all guys for your concern

@DreadPirateShawn
Copy link

Just ran into the same issue.

The root user by default (if you didn't set any password during installation) appears to be:

mysql> select Host,User,plugin,authentication_string from user where User='root'\G
*************************** 1. row ***************************
                 Host: localhost
                 User: root
               plugin: auth_socket
authentication_string: 
1 row in set (0.00 sec)

In my case, I solved the problem by fixing my nodejs code to stop using root user to connect.

@LeZuse
Copy link

LeZuse commented Jan 10, 2017

#1507 (comment) worked for me. Don't forget to flush privileges; after.

@quytm2239
Copy link

quytm2239 commented Feb 11, 2017

#1507 (comment) worked for me, too. 👯‍♂️

and need flush privileges; after follow #1507 (comment)

@janat08
Copy link

janat08 commented Mar 5, 2017

@dougwilson Just in case this is totally happening, I think we should reopen the issue?

@dougwilson
Copy link
Member

From my understanding there is nothing to change in the module. If you have an idea of what to change, please feel free to submit a PR :)

@janat08
Copy link

janat08 commented Mar 5, 2017

Maybe some one will add something if there's and issue to show for it.

@janat08
Copy link

janat08 commented Mar 6, 2017

or add it to install instructions...

@joe-angell
Copy link

Does mysql or any other node lib support sha256_password plugin? I'm getting this same error trying to connect to a server using this plugin.

@sidorares
Copy link
Member

@joe-angell relatively easy to add with mysql2 and authSwitchHandler - see https://github.com/sidorares/node-mysql2/blob/master/documentation/Authentication-Switch.md

@mnakama
Copy link

mnakama commented Aug 9, 2017

I'm not sure that the issue is really resolved. How do we connect to mysql with auth_socket?

I'm specifically trying to get auth_socket working in place of password authentication, but I'm not sure if it's supported in this module.

@elemount
Copy link
Contributor

I'll raise a PR to support pluggable auth plugin in mysqljs which is compatible with mysql2. And then add a auth_socket method can be considered.

@sidorares
Copy link
Member

@mnakama I did a bit of research on how auth_socket works and dump notes here:

  1. depends on SO_PEERCRED ( see http://welz.org.za/notes/on-peer-cred.html )
  2. afaik only for clients connected via domain socket
  3. server is able to check user who created this domain socket connection and uses system user name as mysql user name

node bindings for SO_PEERCRED:
https://github.com/XeCycle/get-peercred
https://github.com/nathan7/peercred

looks like this is not part of libuv so requires binary module

The above is probably for server side of plugin.
I have not found yet detailed description of client side of auth_socket plugin. Looks that just connecting to unix socket and responding to auth switch might be enough (but password has to be supplied somehow - not sure if it's standard mysql_native_password way of sending it)

@elemount
Copy link
Contributor

@sidorares @mnakama , I've read the MySQL server code. This may be a server level auth plugin which do not need client to do something(Not sure yet). But the ER_NOT_SUPPORTED_AUTH_MODE will be always thrown when client driver do not support CLIENT_PLUGIN_AUTH , I assume that after my pull request #1776 is merged, it will be fixed automatically.

@dougwilson
Copy link
Member

Ah, that makes sense @elemount . Yea, your PR implemented the CLIENT_PLUGIN_AUTH, so if that is what is the underlying cause, then that would fix it. Setting up a server with this plugin enabled would validate this.
I'm going to rename the issue and reopen to better track this instead of it being in a closed issue :)

@dougwilson dougwilson reopened this Aug 10, 2017
@dougwilson dougwilson changed the title Error: ER_NOT_SUPPORTED_AUTH_MODE after upgrade mysql-server to 5.17.13 Error: ER_NOT_SUPPORTED_AUTH_MODE with auth_socket Aug 10, 2017
@mnakama
Copy link

mnakama commented Aug 10, 2017

@dougwilson , I just checked out PR #1776 and tried it. auth_socket works perfectly with this. Merging the PR would fix this issue. Thanks @elemount =)

Steps I used to test auth_socket

On the server side:
Using a linux user named "client"

CREATE USER 'client'@'localhost' IDENTIFIED WITH auth_socket;
GRANT all ON *.* TO 'client'@'localhost';
FLUSH PRIVILEGES;

On the node.js client:

let sql = mysql.createPool({
    multipleStatements: true,
    charset: 'UTF8_GENERAL_CI',
    connectionLimit: 10,
    socketPath: '/run/mysqld/mysqld.sock',
    user: 'client', // this needs to match the node.js process user
    //password: (not used with auth_socket),
});

Then execute queries as usual.

@sidorares Correct, there is no need for SO_PEERCRED on the client side. No password needed, either. It's essentially the linux equivalent of the security guard who knows you by your face.

For those interested, this is the only official documentation I found:
https://dev.mysql.com/doc/refman/5.7/en/socket-pluggable-authentication.html

It seems they left out the client part of the documentation completely. It says "None, see discussion", but I don't see a discussion anywhere on the page.

EDIT: It looks like I need the "user" parameter after all. It needs to match the node.js process user. Otherwise, the client tries to use "" as a username and fails.

@Badestrand
Copy link

Badestrand commented Nov 20, 2017

Is there any chance this gets solved soon? As I understand this, I have to switch to another library to support logging in with the default root user? The linked pull request is in the making for 4 months already so will probably need another 6 months until merged in?

Edit: Sorry if I sound snarky, I am exhausted from bug hunting and in general I love working with mysqljs.

Edit 2: Does anyone know any node mysql library that supports this?

@mnakama
Copy link

mnakama commented Nov 20, 2017

@Badestrand Yeah, not sure what happened with the pull request. I used the pull request's commit in our main development branch, and it seems to work fine. I recommend trying it out yourself and possibly helping @elemount get the PR cleaned up. A possible alternative would be to find/use a python mysql library that is more mature.

If you want the code to be part of master branch, check out PR #1776. I think it just needs to be cleanly rebased onto master before it'll be accepted. I'd work on it myself, but I no longer have a need for it.

@dougwilson @elemount Please correct me if I'm wrong.

@tbjgod
Copy link

tbjgod commented Apr 25, 2018

I use this to fix it:
mysql > USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

@drewsmith
Copy link

This one worked for me:

docker exec -it YOUR_CONTAINER mysql -u root -p
Enter password:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '{your password}';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{your password}';
SELECT plugin FROM mysql.user WHERE User = 'root';

@robwhess
Copy link

robwhess commented May 1, 2018

I'm not sure what the status of this request is, but I thought I'd add my input. I'm getting the same error trying to connect to a MySQL 8.0 database. It looks like for MySQL 8.0, the default authentication plugin is caching_sha2_password:

https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

I've verified that my server (running from the mysql:latest Docker image) is indeed using caching_sha2_password for the root user and all newly-created users.

@dougwilson
Copy link
Member

This is a request for support for auth_socket (as specified in the issue title), not for caching_sha2_password. The issue is clear what this is for. I'm locking this because the path forward is open a pull request with an implementation not just comment me too over and over :)

@mysqljs mysqljs locked and limited conversation to collaborators May 1, 2018
@dougwilson dougwilson self-assigned this Apr 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests