-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
executor: query user and role, hostname should be lowercase #28880
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
PTAL @morgo |
tk.MustExec("CREATE ROLE `engineering`@`US`;") | ||
tk.MustExec("create role `engineering`@`INDIA`;") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also verify the persisted value in mysql.user
?
It should match the following:
mysql [localhost:8024] {root} ((none)) > select user,host from mysql.user where user='engineering'\G
*************************** 1. row ***************************
user: engineering
host: %
*************************** 2. row ***************************
user: engineering
host: india
*************************** 3. row ***************************
user: engineering
host: us
3 rows in set (0.00 sec)
Otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case you mentioned should be ok, but after your reminder, I found such a case,I think we should fix it:
In MySQL
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| sqwe | % |
| test_user | % |
| tidb_security | % |
| tidb_system | % |
| u1 | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
9 rows in set (0.00 sec)
mysql> select host from mysql.user where host = 'LOCALHOST'\G
*************************** 1. row ***************************
host: localhost
*************************** 2. row ***************************
host: localhost
*************************** 3. row ***************************
host: localhost
*************************** 4. row ***************************
host: localhost
4 rows in set (0.00 sec)
In TiDB
mysql> select host from mysql.user;
+-------+
| host |
+-------+
| % |
| % |
| % |
| % |
| % |
| % |
| india |
| us |
+-------+
8 rows in set (0.00 sec)
mysql> select host from mysql.user where host = 'INDIA'\G
Empty set (0.00 sec)
mysql> select host from mysql.user where host = 'india'\G
*************************** 1. row ***************************
host: india
1 row in set (0.00 sec)
This difference is because MySQL uses a case insensitive collation, while
tidb uses binary.
…On Fri., Oct. 15, 2021, 8:30 p.m. #7, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In executor/simple_test.go
<#28880 (comment)>:
> + tk.MustExec("CREATE ROLE `engineering`@`US`;")
+ tk.MustExec("create role `engineering`@`INDIA`;")
The case you mentioned should be ok, but after your reminder, I found such
a case,I think we should fix it:
In MySQL
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| sqwe | % |
| test_user | % |
| tidb_security | % |
| tidb_system | % |
| u1 | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
9 rows in set (0.00 sec)
mysql> select host from mysql.user where host = 'LOCALHOST'\G
*************************** 1. row ***************************
host: localhost
*************************** 2. row ***************************
host: localhost
*************************** 3. row ***************************
host: localhost
*************************** 4. row ***************************
host: localhost
4 rows in set (0.00 sec)
In TiDB
mysql> select host from mysql.user;
+-------+
| host |
+-------+
| % |
| % |
| % |
| % |
| % |
| % |
| india |
| us |
+-------+
8 rows in set (0.00 sec)
mysql> select host from mysql.user where host = 'INDIA'\G
Empty set (0.00 sec)
mysql> select host from mysql.user where host = 'india'\G
*************************** 1. row ***************************
host: india
1 row in set (0.00 sec)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#28880 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAOE7T5P5XRNMLFT3VBAO3UHDPTTANCNFSM5GB464KA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
But if use mysql> select User, host from mysql.user where host = 'LOCALHOST';
+------------------+-----------+
| User | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> select User, host from mysql.user where user = 'ROOT';
Empty set (0.00 sec)
mysql> select User, host from mysql.user where user = 'root';
+------+-----------+
| User | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.20 |
+-----------+
1 row in set (0.00 sec) |
Here is the definition from MySQL 8.0: CREATE TABLE `user` (
`Host` char(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '', <-- insensitive
`User` char(32) COLLATE utf8_bin NOT NULL DEFAULT '', <-- sensitive Versus TiDB: `Host` char(255) NOT NULL, <-- binary (tidb disables collations by default)
`User` char(32) NOT NULL, <-- binary (tidb disables collations by default) |
OK, I understand, thank you! |
@morgo PTAL , thank you. By the way, I think if the user uses uppercase to store the hostname, but can only query through lowercase, it will make the user a little confused |
executor/simple.go
Outdated
@@ -982,7 +982,7 @@ func (e *SimpleExec) executeGrantRole(ctx context.Context, s *ast.GrantRoleStmt) | |||
} | |||
|
|||
for _, role := range s.Roles { | |||
exists, err := userExists(ctx, e.ctx, role.Username, role.Hostname) | |||
exists, err := userExists(ctx, e.ctx, role.Username, strings.ToLower(role.Hostname)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that there is a similar function userExistsInternal
. Should it be modified, too?
Besides, I prefer to put strings.ToLower
in userExists
so the callers don't have to care about the cases.
PTAL @morgo @djshow832 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for making the changes.
/merge |
@djshow832: In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: a4dae6d
|
@7yyo: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/run-check_dev_2 |
What problem does this PR solve?
Issue Number: close #28841
Problem Summary:
When creating a new user, the
hostname
will be converted to lowercase. So when querying, also use lowercase.What is changed and how it works?
What's Changed:
Use lowercase
hostname
for query.Check List
Tests
Side effects
Documentation
Release note