[MDEV-13682] Role permissions don't work with CTEs Created: 2017-08-30 Updated: 2017-09-29 Resolved: 2017-09-29 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - CTE |
| Affects Version/s: | 10.2.6, 10.2.7, 10.2.8 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Elizabeth Good | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | CTEs, Roles | ||
| Environment: |
RHEL7. |
||
| Issue Links: |
|
||||||||
| Description |
|
When I grant a select on a table directly to the user, the user is able to use CTEs successfully. However, when I grant that same select to a role, and then grant the role to the user, the user CANNOT run CTEs successfully. This user (eg4) has been granted select on the Managers table through the mqm_read role:
But when the user tries to use a CTE, she gets a SELECT command denied error:
This seems to defeat the whole purpose of roles. |
| Comments |
| Comment by Elizabeth Good [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Wow, I just tried to create a role without having the underscore in the name. That new role appears to work with CTEs. Can you confirm? If having an underscore in the name of the role messes up the ability to create CTEs, then why is MariaDB allowing it (the creation of the underscored role)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elizabeth Good [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
You are correct. The CTE must have been cached. When I recreated everything from scratch, the new CTE did not work. Are there plans to have roles work with CTEs in a future release? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Roles in general work with CTE. There is a general problem with CTE and permissions (regardless roles), described in Please consider the following example.
But if we try to switch the default database to db1 (which we can do), it will stop working. This is the bug
It's unrelated to roles, same happens if you grant access directly to the user
Does it correlate with what you observe? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elizabeth Good [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I don't change the default database, so I'm not sure if this is a duplicate issue. I create a user without a default database. I create the role which has the select permissions and assign that as the default role for the user. But when user tries to do a CTE, he gets a SELECT command denied to user error. Drop and recreate user, then give user select on the table directly, CTEs run fine. And I've given the select permission on multiple databases, and haven't heard of any issue running the CTEs. I don't have any roles assigned to the users, since the roles don't appear to work as intended. (I've had to change up the CTEs, since it seems like the CTE results are cached.) It would be nice to be able to assign multiple roles to the user and have CTEs work, even if we switch databases. Perhaps that's the issue with Both my issue and issue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
> I don't change the default database > Drop and recreate user, then give user select on the table directly, CTEs run fine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elizabeth Good [ 2017-08-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Interesting, you are correct. This is what happens when I just grant select to a particular table: MariaDB [mysql]> show grants for oo49;
Couldn't figure out why this never problem never occurred before for us (thank goodness), and realized that this is NOT exactly how we grant permissions to our users. Since we want them to have selects on all the tables, this is how it is granted: MariaDB [mysql]> show grants for usr112;
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------ And this user has no problems doing a CTE: [root@watauga fuqua]# mysql -u usr112 -p lahman2016 Welcome to the MariaDB monitor. Commands end with ; or \g. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [lahman2016]> WITH new3 as (SELECT yearID, teamID, Rank from Teams LIMIT 20) SELECT * FROM new3;
-------
.... So, maybe the select on dbname.* implicitly grants select on the CTE tables? Which is probably what We are on MariaDB 10.2.8. Do you know when this issue will be fixed? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-09-29 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I cannot say for certain when |