[MDEV-14732] mysql.db privileges evaluated on order of grants rather than hierarchically Created: 2017-12-21 Updated: 2019-08-22 Resolved: 2019-06-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Authentication and Privilege System |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.4.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Juan | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | upstream | ||
| Environment: |
CentOS 6, CentOS 7, OSX 10.11 |
||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
As described by customer: As super user :
Interestingly, that works (order of grants) :
The problem here is that the server is evaluating rows in mysql.db in order of addition rather than in logical order with the more specific database name superseding the more general or vice-versa. |
| Comments |
| Comment by Sergei Golubchik [ 2017-12-21 ] | ||
|
Grants are sorted from most specific (no wildcards) to less specific (wildcards only). The order considers only the prefix up to the first wildcard. Note that the underscore '_' is a wildcard, so both grants have the same "specificity weight" and the order is undefined, practically it happens to be the order in which GRANT statements were issued, but it' not guaranteed. If you remove the wildcard in the middle:
The more specific (no wildcards) name will be always sorted first, independently from the GRANT statement order. | ||
| Comment by Sergei Golubchik [ 2017-12-21 ] | ||
|
Ideally, the sorting algorithm should recognize that wildcard_grants% is less specific than wildcard_grants, despite them both having a wildcard in the middle. | ||
| Comment by Elena Stepanova [ 2018-07-02 ] | ||
|
I think ideally the system should merge all applicable privileges, that's what an average user probably expects. I don't know if the standard agrees, though. | ||
| Comment by Manuel Arostegui [ 2019-06-17 ] | ||
|
Can this be backported to 10.1 and 10.3 as well? | ||
| Comment by Sergei Golubchik [ 2019-06-17 ] | ||
|
Technically — yes, easily, it's a very local change. But it does change behavior is some corner cases. For example, the old code could consider hostname pattern www.% to be "more specific" than %.mariadb.org. This is clearly wrong, there are a lot more hosts that match the first pattern than the second, so the second is a lot more specific. And the new code handles it as such. Still it means that after this bugfix a user will have different privileges if these both grants were present in mysql.user table. Same for databases. That is why this bugfix was only pushed in 10.4, pre-GA. |