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

ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol "caching_sha2_password" #7293

Open
lreyessandoval opened this issue Aug 10, 2023 · 3 comments

Comments

@lreyessandoval
Copy link

Node version: 16.16.0
Sails version (sails): 1.5.2
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 2.0.0
Organics hook version (sails-hook-organics):
Grunt hook version (sails-hook-grunt): 4.0.0
Uploads hook version (sails-hook-uploads):
DB adapter & version (e.g. [email protected]): 3.0.1
Skipper adapter & version (e.g. [email protected]): 0.8.7

Mysql versión: 8.0.34 community


when making a connection from an api rest project (backend) to a mysql database in version 8.0.34, it fails to establish a connection. The following error appears:

AdapterError: Unexpected error from database adapter: `count` failed ("badConnection").  A connection either could not be obtained or there was an error using the connection.
Additional data:
{
error: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
--------------------
at Protocol._enqueue (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/Connection.js:116:18)
at Pool.getConnection (/www/wwwapp/testapi.ditdental.com/node_modules/mysql/lib/Pool.js:48:16)
at Object.getConnection (/www/wwwapp/testapi.ditdental.com/node_modules/machinepack-mysql/lib/get-connection.js:78:25)
at wrapper (/www/wwwapp/testapi.ditdental.com/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at Deferred.parley.retry [as _handleExec] (/www/wwwapp/testapi.ditdental.com/node_modules/machine/lib/private/help-build-machine.js:1076:19)
at Deferred.exec (/www/wwwapp/testapi.ditdental.com/node_modules/parley/lib/private/Deferred.js:286:10)
at Deferred.switch (/www/wwwapp/testapi.ditdental.com/node_modules/machine/lib/private/help-build-machine.js:1469:16)
at spawnConnection (/www/wwwapp/testapi.ditdental.com/node_modules/sails-mysql/helpers/private/connection/spawn-connection.js:29:10)
at Object.spawnOrLeaseConnection (/www/wwwapp/testapi.ditdental.com/node_modules/sails-mysql/helpers/private/connection/spawn-or-lease-connection.js:23:3)
at Object.count (/www/wwwapp/testapi.ditdental.com/node_modules/sails-mysql/helpers/count.js:119:24)
at wrapper (/www/wwwapp/testapi.ditdental.com/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at Deferred.parley.retry [as _handleExec] (/www/wwwapp/testapi.ditdental.com/node_modules/machine/lib/private/help-build-machine.js:1076:19)
at Deferred.exec (/www/wwwapp/testapi.ditdental.com/node_modules/parley/lib/private/Deferred.js:286:10)
at Deferred.switch (/www/wwwapp/testapi.ditdental.com/node_modules/machine/lib/private/help-build-machine.js:1469:16)
at Object.count (/www/wwwapp/testapi.ditdental.com/node_modules/sails-mysql/lib/adapter.js:331:16)
at Deferred._.extend._WLModel [as _handleExec] (/www/wwwapp/testapi.ditdental.com/node_modules/waterline/lib/waterline/methods/count.js:221:15)
at Deferred.exec (/www/wwwapp/testapi.ditdental.com/node_modules/parley/lib/private/Deferred.js:286:10)
at Deferred.tryCatcher (/www/wwwapp/testapi.ditdental.com/node_modules/bluebird/js/release/util.js:11:23)
at ret (eval at makeNodePromisifiedEval (/www/wwwapp/testapi.ditdental.com/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:14:23)
at Deferred.toPromise (/www/wwwapp/testapi.ditdental.com/node_modules/parley/lib/private/Deferred.js:572:19)
at Deferred.then (/www/wwwapp/testapi.ditdental.com/node_modules/parley/lib/private/Deferred.js:431:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
},
meta: {
host: 'localhost',
port: 3306,
schema: true,
adapter: 'sails-mysql',
url: 'mysql://usr_ditdenta_test:****@localhost:3306/ditdenta_test',
identity: 'default'
}
}
at Object.find [as productgroup/find] (/www/wwwapp/testapi.ditdental.com/api/controllers/ProductGroupController.js:32:45)
at /www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/router/bind.js:236:53
at routeTargetFnWrapper (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/router/bind.js:395:9)
at Layer.handle [as handle_request] (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/layer.js:95:5)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/layer.js:95:5)
at /www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:335:12)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:275:10)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:127:14)
at alwaysAllow (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/hooks/policies/index.js:178:16)
at routeTargetFnWrapper (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/router/bind.js:395:9)
at Layer.handle [as handle_request] (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/layer.js:95:5)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/layer.js:95:5)
at /www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:335:12)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/index.js:275:10)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:127:14)
at Hook.expressMiddleware (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/hooks/i18n/index.js:205:14)
at Hook.wrapper [as expressMiddleware] (/www/wwwapp/testapi.ditdental.com/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at addLocalizationMethod (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/hooks/i18n/index.js:147:35)
at routeTargetFnWrapper (/www/wwwapp/testapi.ditdental.com/node_modules/sails/lib/router/bind.js:395:9)
at Layer.handle [as handle_request] (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/layer.js:95:5)
at next (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/www/wwwapp/testapi.ditdental.com/node_modules/express/lib/router/route.js:112:3)

The user database is configured with "authentication" "caching_sha2_password"

@sailsbot
Copy link

@lreyessandoval Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. (Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)
  • tell us why this issue is important to you and your team. What are you trying to accomplish? (Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. (Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. (Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. (Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@neonexus
Copy link

neonexus commented Sep 10, 2023

@lreyessandoval The problem is because MySQL is using "caching_sha2_password" instead of the "mysql_native_password" plugin.

Try this (may have to flush privileges too):

ALTER USER 'user' identified with mysql_native_password BY 'changeMeRightMeow';

@franc23
Copy link

franc23 commented Dec 19, 2023

While the solution proposed will get it to work, it's not the ideal solution. Please see https://stackoverflow.com/a/56509065 for reasoning as to why.
Sailsjs mysql adapter needs to support the caching_sha2_password change.

Below 3 changes resolves the issue in sailsjs-mysql:
Change below two lines to require mysql2 instead of mysql

  1. https://github.com/sailshq/machinepack-mysql/blob/da6d6fcfcbf3393f149f00fbdd38164ef030976a/index.js#L12
  2. https://github.com/sailshq/machinepack-mysql/blob/da6d6fcfcbf3393f149f00fbdd38164ef030976a/lib/create-manager.js#L5C22-L5C27

Change package.json to require mysql2 with the latest version
3. https://github.com/sailshq/machinepack-mysql/blob/da6d6fcfcbf3393f149f00fbdd38164ef030976a/package.json#L26
For ex: "mysql2": "3.6.5",

Updating these 3 resolved it. Can submit a PR if this is the right way to go about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants