[MDEV-12666] CURRENT_ROLE() and DATABASE() does not work in a view Created: 2017-05-02 Updated: 2020-08-25 Resolved: 2017-06-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Authentication and Privilege System, Views |
| Affects Version/s: | 10.0, 10.1, 10.1.22, 10.2 |
| Fix Version/s: | 10.0.32 |
| Type: | Bug | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | roles, view | ||
| Sprint: | 10.3.1-1 |
| Description |
|
The CURRENT_ROLE() function does not seem to work in a view. Let's say that I create the following users and role:
And I create the following table:
Now let's say that I create the following view:
Since I specified "SQL SECURITY INVOKER", the call of CURRENT_ROLE() should return the current role of the user who is invoking the view. Now let's log in as the "has_role" user and select the "test_role" role:
And let's see what happens if I query the view as this user:
We got no results. But if we manually execute the query from the view, we do get results:
It seems that CURRENT_ROLE() does not work in a view. |
| Comments |
| Comment by Elena Stepanova [ 2017-05-02 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here is a somewhat simpler version.
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-05-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Alexander! Can you please review a patch for this issue? Thanks! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-05-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
This patch is targeting 10.0. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-05-23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
A similar problem is repeatable with DATABASE(). I start mysql client without specifying a database name, and run this script:
Notice, DATABASE() was replaced to NULL. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-05-23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sent review comments by email | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Alexander! Thank you for your first review. I've looked into this problem some more and I've come up with a correct solution I believe. I hope the commit comment is sufficient to explain everything. Can you please review it again? I've taken inspiration from Item_param::safe_charset_converter. http://lists.askmonty.org/pipermail/commits/2017-June/011229.html Thank you! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Alexander, Please use this commit for review. I've removed a few superfluous changes to keep the patch a bit smaller. http://lists.askmonty.org/pipermail/commits/2017-June/011238.html Vicentiu | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-06-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ok to push. |