-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column Level Privileges are capitalized when applied to DB instance #399
Comments
@kmarse hello, thanks for reporting this! |
@Andersson007 Thanks for getting back to me on this. I did some investigating into the different modules and I don't see anywhere currently that it would be uppercasing the priv variable. Is there a place of reference you could point me to so that I can test a solution? |
@Andersson007 I ran some tests and found the issue which I have resolved locally. The issue was found in user.py on line 644 which performs an upper() function on the entire privilege statement including column_names. output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:(|$))', pieces[1].upper()) This causes 'SELECT( I believe that removing upper() to make sure that we are not breaking grants by forcing column_names to be uppercased. We should then handle uppercasing the SELECT(privileges) separate from the column names which I believe could be done by splitting the privilege(SELECT) from the column names then uppercase it and concatenate them and alter the privs. Let me know if you want me to create a PR just removing the upper or if you want to look into making it more robust. |
@kmarse thanks for the feedback! Your investigation is correct.
I think it would be a very dangerous path and definitely a breaking one
Considering the importance of the module and this particular feature, yep, I'm personally in favor of robust and non-breaking solutions:) |
@Andersson007 I wanted to give you an update on this as I have not had time to look for a more robust way but to provide you what mysql/oracle have updated me on through support tickets. After talking to a support representative from MySQL/Oracle I have verified that column level grants although in their documentation, which states "For access-checking purposes, comparisons of User, Proxied_user, authentication_string, Db, and Table_name values are case-sensitive. Comparisons of Host, Proxied_host, Column_name, and Routine_name values are not case-sensitive." I was told by the rep that, " in order to evaluate the privilege as part of MySQL authorization system, MySQL compares the column columns_priv.column_name of the mysql system table." This means that because I have a column named "first_name" and I want to grant select on just that column if I try to grant that in the module with the following privilege: database.person: 'SELECT(first_name)' When it goes through the module it would show as the following grant: GRANT SELECT( This then if I tried to query that column with that user would give me a SELECT COMMAND DENIED error because when it reads from columns_priv.column_name the column_name is lowercased which doesn't match and then in turn is not valid. From the updates I have received from MySQL/Oracle I feel more justified that my solution above is correct. The module should not be uppercasing any columns because that is the responsibility of the DBA/DBE to make sure that their yml files include the correct case sensitive typed column names so that the grant statement can be validated by MySQL correctly. After reviewing your code some more I understand what you are uppercasing. How I understand it is that with your code you are trying to make sure the all reserved words are uppercased like SELECT, INSERT, UPDATE, DELETE. But because column level grants are defined inline with these words in the grant statement like 'SELECT(first_name)' you are wanting to make sure you are uppercasing the the SELECT and by default you are uppercasing the column names as well (which is causing errors in the mysql priv evaluation. In my mind there are two solutions here.
They did open up a bug to update the documentation I believe which I am still investigating to see if that is the case so that all users of MySQL are not thinking that column level privileges are case insensitive. Also I have removed the above code from my local code repository and have been running this module in 4 different environments for 5 months now with nothing breaking so I don't believe that this is a breaking change to your module. I can still submit a pull request but would like feedback from you. |
@kmarse thanks for the detailed feedback! i would highlight that this code had been introduced before i came:) The
I meant it can be @kmarse @bmalynovytch @laurent-indermuehle @rsicart thoughts? |
I rarely use the |
I completely understand why this is a breaking change and should go out in a major release. Unfortunately after looking into the code some more I don't see a possible fix for a patch because if someone is dependent on the uppercasing of the columns to handle the matching of their uppercased columns in their db schema then unless done through a flag/boolean variable that we default to use the old code of uppercasing everything and then if the user sets their default value to false then it would skip that uppercasing. Other than that fix I can't really think of another way without it going out in a major release. Thanks for you feedback and let me know if there is anything I can do to help. I am more than willing to try and get a solution to you all. |
@kmarse thanks for investigating the case! However, considering the importance of the related code, in this particular case, Would be great to hear opinions of you all on the plan: @kmarse @laurent-indermuehle @rsicart @bmalynovytch @betanummeric @Jorge-Rodriguez |
I think we should review the tests to be sure that we cover all possible cases. And then try to remove the "upper". I say that because I almost never use capital letters and MySQL/MariaDB understand me without issues. |
@laurent-indermuehle thanks for the feedback! Agreed. @kmarse if you're OK with #399 (comment) and If no opposition to the plan util Monday, i think we can proceed with the boolean with default as it is not. What can help you. Instruqt labs:
Though I hope the rest of the team (@rsicart @bmalynovytch @betanummeric @Jorge-Rodriguez) will share their feedback until Monday. If not, feel free to proceed. |
@Andersson007 I apologize for the extremely late response. I will start to proceed with a request on this to add a boolean value with the default behavior being that of current functionality and then the ability to change the boolean to disable the capitalization of column level privileges. Are you wanting this to be a known boolean that other users are able to change as well? Meaning updating documentation? |
@kmarse no worries
Sure, any new features should be documented + would be nice to have an example. The module's file contains both the sections |
@Andersson007 thanks. I have finished the code and am working on documentation and then trying to work through creating unit testing for this. |
@kmarse thanks! if there are any questions/unclear things, we'll be happy to clarify them |
@Andersson007 I wrote my test based on previous tests that you have written. But no matter what I input into the unit test I am not seeing output changes when I run the unit tests can you give me advice on this? Unit Test: Unit Test Command: Unit Test output: ................................ [100%]
I only posted one of the outputs as they all look the same. |
@kmarse if you submit a PR with the changes and tests, it'd be easier for me to review (if you haven't done that before, Quickstart guide can help) |
@kmarse you were close for the units tests. If ansible-tests returns nothing it means the tests pass. I just added one based on your feedback: 11430f0 When I un-capitalize one column name, it immediately yell:
This was my first experience with unit tests. Thank you for making me learning something new today :) All integrations tests are now passing. I'm not sure they are the best thought. I discovered that only mysql 5.7 is case sensitive. Either MySQL 8 and MariaDB doesn't care and grant access no matter the case. But, I think you're right @kmarse and setting column_case_senstive to True is the best thing to do. I already announced that this will be the default starting with 4.0.0 when we release it, here and here Thanks you for your contribution! Feel free to comment on the PR but don't wait too much, I'll merge it soon to get back to #572. |
@kmarse @laurent-indermuehle thanks for the contribution! |
Hi @kmarse, |
Please raise issues via the new interface
Currently I use the mysql-roles module to manage all app roles in our db instances. I have some column level privileges to a larger table that I don't want to grant access to the whole table to some roles. I have been receiving access denied errors now because when the mysql-roles module applied the grants it capitalized the column names.
In MySQL's documentation I have found that it states that column level privileges are not case sensitive but after speaking to an oracle support rep he has confirmed that they are.
I am confused on why the module when inputting the grants for column level privileges is uppercasing the column name and not leaving it the way I have it in my playbook example follows:
What I have in my playbook:
'database.table': 'SELECT(
app_type
,rec_id
)'What MySQL is returning after application:
GRANT SELECT (
APP_TYPE
,REC_ID
) ONdatabase
.table
TOrole
@%
The text was updated successfully, but these errors were encountered: