For command-line tools, if no user name is provided, then the default behavior is supposed to be that the client will use the name of the current Unix user.
From the MySQL documentation:
On Unix, most MySQL clients by default try to log in using the current Unix user name as the MySQL user name, but that is for convenience only.
Since the connector defaults to the return value of getlogin(), this is why the mysql client is using the wrong user name:
bash-4.2$ mysql --plugin-dir=/usr/lib64/mysql/plugin/ -h 127.0.0.1 -pbadpassword
ERROR 1045 (28000): Access denied for user 'ec2-user'@'localhost' (using password: NO)
Geoff Montee (Inactive)
added a comment - - edited I see that the read_user_name() function gets the user name by going through the following order:
Using the user name root if geteuid() returns 0 .
Using the user name returned by getlogin() , unless it is NULL .
Using the user name returned by getpwuid(geteuid()) , unless it is NULL .
Using the user name assigned to the USER environment variable, unless it is not set.
Using the user name assigned to the LOGNAME environment variable, unless it is not set.
Using the user name assigned to the LOGIN environment variable, unless it is not set.
See here:
https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.4/libmariadb/mariadb_lib.c#L499
I created a quick test program to check the return values of getlogin() and getpwuid(geteuid()) :
$ cat read_user_name.c
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
struct passwd *result;
char *login_user;
char *effective_user;
if ((login_user = getlogin()) != NULL)
{
printf("User name of login user is: %s\n", login_user);
}
else
printf("Could not get user name of login user\n");
if ((result = getpwuid(geteuid())) != NULL)
{
effective_user = result->pw_name;
printf("User name of effective user is: %s\n", effective_user);
}
else
printf("Could not get user name of effective user\n");
return 0;
}
This seems to indicate that getpwuid(geteuid()) returns the correct user name, but getlogin() does not. For example:
[ec2-user@ip-172-30-0-105 tmp]$ whoami
ec2-user
[ec2-user@ip-172-30-0-105 tmp]$ sudo -u mysql bash
bash-4.2$ whoami
mysql
bash-4.2$ id
uid=997(mysql) gid=994(mysql) groups=994(mysql),1005(shadow)
bash-4.2$ gcc read_user_name.c
bash-4.2$ ./a.out
User name of login user is: ec2-user
User name of effective user is: mysql
Since the connector defaults to the return value of getlogin() , this is why the mysql client is using the wrong user name:
bash-4.2$ mysql --plugin-dir=/usr/lib64/mysql/plugin/ -h 127.0.0.1 -pbadpassword
ERROR 1045 (28000): Access denied for user 'ec2-user'@'localhost' (using password: NO)
As far as I can tell, the problem is that getlogin() is used over getpwuid(geteuid()). See my previous comment for a test program that shows the difference.
Geoff Montee (Inactive)
added a comment - georg ,
This commit doesn't look like it would fix this issue:
https://github.com/MariaDB/mariadb-connector-c/commit/e8023f3bf05839aaf4d797747f265822ea4a0514
As far as I can tell, the problem is that getlogin() is used over getpwuid(geteuid()) . See my previous comment for a test program that shows the difference.
Hello, Red Hat here, we've just got hit (rather) hard by this issue.
—
We have put MariaDB 10.4.12 into Fedora 32 - which is now in BETA freeze.
Turns out, a lot of users and test are relying on this - documented - usage; which is broken now.
Unfortunattely we were searching for the bug in auth_socket plugin, which is now default in MariaDB 10.4.
—
There are other packages, which builds on top of (or utilizes) MariaDB. Those packages have build-time tests which rely on switching the user.
With this bug, they (suddenly) fail, thus the build of te package fail, and if it can't be built for a next Fedora release, such package has to be dropped from the distribution.
We would be grateful for fix or a workaround ASAP.
We have only two spots left for the fix in Fedora - either for F32 Final Freeze, or as a F32 zero-day update (which would cause various other issues, since the F32 images would be distributed without the fix)
The Final Freeze is at the beginning of April.
We are likely to start preparing downstream patch to apply before the Final Freeze, but we'd much prefer to be fixed upstream, since our knowledge about the DB code is limited and it may be much easier fir you to do it and not to make a mistake in it
—
Thanks Geoff for the fine detective job
Michal Schorm
added a comment - Hello, Red Hat here, we've just got hit (rather) hard by this issue.
—
We have put MariaDB 10.4.12 into Fedora 32 - which is now in BETA freeze.
Turns out, a lot of users and test are relying on this - documented - usage; which is broken now.
Unfortunattely we were searching for the bug in auth_socket plugin, which is now default in MariaDB 10.4.
—
There are other packages, which builds on top of (or utilizes) MariaDB. Those packages have build-time tests which rely on switching the user.
With this bug, they (suddenly) fail, thus the build of te package fail, and if it can't be built for a next Fedora release, such package has to be dropped from the distribution.
We would be grateful for fix or a workaround ASAP.
We have only two spots left for the fix in Fedora - either for F32 Final Freeze, or as a F32 zero-day update (which would cause various other issues, since the F32 images would be distributed without the fix)
The Final Freeze is at the beginning of April .
We are likely to start preparing downstream patch to apply before the Final Freeze, but we'd much prefer to be fixed upstream, since our knowledge about the DB code is limited and it may be much easier fir you to do it and not to make a mistake in it
—
Thanks Geoff for the fine detective job
georg's fix will be in MariaDB Connector/C 3.1.8, which should be released with MariaDB Server 10.4.13. I believe that release is currently planned for sometime around the end of April, but ralf.gebhardt@mariadb.com can correct me if I'm wrong. I hope that timeline works for you guys.
Thanks!
Geoff Montee (Inactive)
added a comment - Hi mschorm ,
georg 's fix will be in MariaDB Connector/C 3.1.8, which should be released with MariaDB Server 10.4.13. I believe that release is currently planned for sometime around the end of April, but ralf.gebhardt@mariadb.com can correct me if I'm wrong. I hope that timeline works for you guys.
Thanks!
I can´t wait for the fix, but that's fine.
I did proceed with taking the latest sources of CONC/C and rebuilding the 'mariadb-connector-c' and 'mariadb' Fedora packages.
This is our chance to get the fixed version available to the users with Fedora 32.
Once you release new versions, I'll update ASAP.
Thanks for the patch !
Michal Schorm
added a comment - I can´t wait for the fix, but that's fine.
I did proceed with taking the latest sources of CONC/C and rebuilding the 'mariadb-connector-c' and 'mariadb' Fedora packages.
This is our chance to get the fixed version available to the users with Fedora 32.
Once you release new versions, I'll update ASAP.
Thanks for the patch !
People
Georg Richter
Geoff Montee (Inactive)
Votes:
2Vote for this issue
Watchers:
5Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1175.1000000238419,"ttfb":193.89999997615814,"pageVisibility":"visible","entityId":79488,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"b95b36ee-29e4-4066-a23b-d012c5437b19","navigationType":0,"readyForUser":1274.7999999523163,"redirectCount":0,"resourceLoadedEnd":1092.5,"resourceLoadedStart":203.29999995231628,"resourceTiming":[{"duration":436.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":203.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":203.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":639.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":436.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":203.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":203.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":640.1000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":564.3000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":203.89999997615814,"connectEnd":203.89999997615814,"connectStart":203.89999997615814,"domainLookupEnd":203.89999997615814,"domainLookupStart":203.89999997615814,"fetchStart":203.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":642.2000000476837,"responseEnd":768.2000000476837,"responseStart":662.7000000476837,"secureConnectionStart":203.89999997615814},{"duration":691.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":204.39999997615814,"connectEnd":204.39999997615814,"connectStart":204.39999997615814,"domainLookupEnd":204.39999997615814,"domainLookupStart":204.39999997615814,"fetchStart":204.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":641.5,"responseEnd":896.2000000476837,"responseStart":657.7000000476837,"secureConnectionStart":204.39999997615814},{"duration":451.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":204.70000004768372,"connectEnd":204.70000004768372,"connectStart":204.70000004768372,"domainLookupEnd":204.70000004768372,"domainLookupStart":204.70000004768372,"fetchStart":204.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":642.5,"responseEnd":656,"responseStart":654.8999999761581,"secureConnectionStart":204.70000004768372},{"duration":453.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":204.79999995231628,"connectEnd":204.79999995231628,"connectStart":204.79999995231628,"domainLookupEnd":204.79999995231628,"domainLookupStart":204.79999995231628,"fetchStart":204.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":642.6000000238419,"responseEnd":658.6000000238419,"responseStart":656.2999999523163,"secureConnectionStart":204.79999995231628},{"duration":453.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":205,"connectEnd":205,"connectStart":205,"domainLookupEnd":205,"domainLookupStart":205,"fetchStart":205,"redirectEnd":0,"redirectStart":0,"requestStart":642.7000000476837,"responseEnd":658.7000000476837,"responseStart":656.8999999761581,"secureConnectionStart":205},{"duration":438.6999999284744,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":205.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":205.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":643.8999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":457.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":205.29999995231628,"connectEnd":205.29999995231628,"connectStart":205.29999995231628,"domainLookupEnd":205.29999995231628,"domainLookupStart":205.29999995231628,"fetchStart":205.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":644.1000000238419,"responseEnd":662.5,"responseStart":661.5,"secureConnectionStart":205.29999995231628},{"duration":438.60000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":205.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":205.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":644.1000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":469.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":205.70000004768372,"connectEnd":205.70000004768372,"connectStart":205.70000004768372,"domainLookupEnd":205.70000004768372,"domainLookupStart":205.70000004768372,"fetchStart":205.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":645.7000000476837,"responseEnd":675.2000000476837,"responseStart":665,"secureConnectionStart":205.70000004768372},{"duration":728.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":217.39999997615814,"connectEnd":217.39999997615814,"connectStart":217.39999997615814,"domainLookupEnd":217.39999997615814,"domainLookupStart":217.39999997615814,"fetchStart":217.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":837.8999999761581,"responseEnd":945.6000000238419,"responseStart":943.7999999523163,"secureConnectionStart":217.39999997615814},{"duration":863.3999999761581,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":229.10000002384186,"connectEnd":229.10000002384186,"connectStart":229.10000002384186,"domainLookupEnd":229.10000002384186,"domainLookupStart":229.10000002384186,"fetchStart":229.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":1080,"responseEnd":1092.5,"responseStart":1091.3999999761581,"secureConnectionStart":229.10000002384186},{"duration":226.19999992847443,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":901.1000000238419,"connectEnd":901.1000000238419,"connectStart":901.1000000238419,"domainLookupEnd":901.1000000238419,"domainLookupStart":901.1000000238419,"fetchStart":901.1000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":1093.1000000238419,"responseEnd":1127.2999999523163,"responseStart":1126.6000000238419,"secureConnectionStart":901.1000000238419},{"duration":187.29999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1168.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1168.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1355.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":281.39999997615814,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1186.8999999761581,"connectEnd":1186.8999999761581,"connectStart":1186.8999999761581,"domainLookupEnd":1186.8999999761581,"domainLookupStart":1186.8999999761581,"fetchStart":1186.8999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":1435,"responseEnd":1468.2999999523163,"responseStart":1467.6000000238419,"secureConnectionStart":1186.8999999761581}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":4,"responseStart":194,"responseEnd":229,"domLoading":198,"domInteractive":1393,"domContentLoadedEventStart":1393,"domContentLoadedEventEnd":1467,"domComplete":1918,"loadEventStart":1918,"loadEventEnd":1919,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1359.1000000238419},{"name":"bigPipe.sidebar-id.end","time":1359.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":1360},{"name":"bigPipe.activity-panel-pipe-id.end","time":1363.2999999523163},{"name":"activityTabFullyLoaded","time":1485.2000000476837}],"measures":[],"correlationId":"e589e655a823b1","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":113,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I see that the read_user_name() function gets the user name by going through the following order:
See here:
https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.4/libmariadb/mariadb_lib.c#L499
I created a quick test program to check the return values of getlogin() and getpwuid(geteuid()):
$ cat read_user_name.c
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
struct passwd *result;
char *login_user;
char *effective_user;
if ((login_user = getlogin()) != NULL)
{
printf("User name of login user is: %s\n", login_user);
}
else
printf("Could not get user name of login user\n");
if ((result = getpwuid(geteuid())) != NULL)
{
effective_user = result->pw_name;
printf("User name of effective user is: %s\n", effective_user);
}
else
printf("Could not get user name of effective user\n");
return 0;
}
This seems to indicate that getpwuid(geteuid()) returns the correct user name, but getlogin() does not. For example:
[ec2-user@ip-172-30-0-105 tmp]$ whoami
ec2-user
[ec2-user@ip-172-30-0-105 tmp]$ sudo -u mysql bash
bash-4.2$ whoami
mysql
bash-4.2$ id
uid=997(mysql) gid=994(mysql) groups=994(mysql),1005(shadow)
bash-4.2$ gcc read_user_name.c
bash-4.2$ ./a.out
User name of login user is: ec2-user
User name of effective user is: mysql
Since the connector defaults to the return value of getlogin(), this is why the mysql client is using the wrong user name:
bash-4.2$ mysql --plugin-dir=/usr/lib64/mysql/plugin/ -h 127.0.0.1 -pbadpassword
ERROR 1045 (28000): Access denied for user 'ec2-user'@'localhost' (using password: NO)