[MXS-2642] PAMAuth does not eliminate duplicate PAM services during authentication Created: 2019-08-19 Updated: 2020-08-25 Resolved: 2019-09-04 |
|
| Status: | Closed |
| Project: | MariaDB MaxScale |
| Component/s: | Authenticator |
| Affects Version/s: | 2.3.11 |
| Fix Version/s: | 2.3.12, 2.4.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Esa Korhonen |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Sprint: | MXS-SPRINT-89 | ||||||||
| Description |
|
The PAMAuth authenticator is only supposed to try authenticating each user with a particular PAM service at most twice--once before reloading the users, and once after reloading the users. The second attempt only happens if the PAM service has changed since the first attempt. See here: However, it looks like it is actually possible for the PAMAuth authenticator to try a specific PAM service more times than that, because PAMAuth does not eliminate duplicate PAM services during authentication. For example, let's say that we do the following:
Now we have two distinct user accounts named "alice", and they both use the "mariadb" PAM service. The PAMAuth authenticator loads user accounts using the following query:
See here: The results for this specific scenario would be the following:
Let's say that the "alice" user tries to log in from a host with an IP address that is something like 192.168.1.10. In this case, the get_pam_user_services() function will tell PAMAuth to try the "mariadb" service twice--once for the 'alice'@'%' user account, and once for the 'alice'@'192.168.1.%' user account. See here: It's not really helpful to try authenticating with the same service multiple times. This can be especially problematic if the user's environment locks a user's account after so many failed authentication attempts. In environments like that, if MaxScale tries the same bad password multiple times for each login attempt, then that will cause the user account to be locked much sooner. I think MaxScale should fix this by eliminating duplicate PAM services, so that it only tries each unique service once. I see two potential ways to fix this that are both pretty easy: 1.) The SQLite query that fetches the PAM services in the get_pam_user_services() function does not currently eliminate duplicates. One way to fix this would be by adding the "DISINCT" keyword to the SQLite query, so that SQLite will remove duplicate PAM services from the results. e.g.:
2.) The get_pam_user_services() function currently uses a std::vector<std::string> to store the PAM services returned by the SQLite query. C++'s std::vector allows duplicate objects. Another way to fix this would be to switch from std::vector<std::string> to something like std::unordered_set<std::string>, which does not allow duplicates. http://www.cplusplus.com/reference/unordered_set/unordered_set/ |
| Comments |
| Comment by Geoff Montee (Inactive) [ 2019-08-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I've confirmed that MaxScale will try the same PAM service multiple times. I reproduced this by creating the following user accounts:
And I used the following configuration file:
And then I attempted to log into MaxScale using a bad password:
The MaxScale error log clearly shows that authentication was tried twice, when it only should have been tried once in this case:
And the syslog (i.e. /var/log/secure) also shows the two attempts using the same service name:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2019-08-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I repeated the previous test with a third user account added to the mix:
As expected, MaxScale tries to authenticate the user using the "mariadb" PAM service three times. The MaxScale error log:
The syslog:
I think MaxScale should eliminate duplicate PAM services, so that it only tries each unique service once. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Esa Korhonen [ 2019-08-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is fixed in 2.4.1, where role support was also added. This is not really even a bug, as it is explained in Pam authentication documentation: |