Skip to content
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

Anomaly of account replication from MySQL instance #2740

Closed
VWagen1989 opened this issue Nov 11, 2024 · 1 comment · Fixed by #2741
Closed

Anomaly of account replication from MySQL instance #2740

VWagen1989 opened this issue Nov 11, 2024 · 1 comment · Fixed by #2741

Comments

@VWagen1989
Copy link
Contributor

VWagen1989 commented Nov 11, 2024

Hi, I've encountered a replication issue about the account replicated from a MySQL primary instance. Here's how I produced this issue:

  • First, I built a replication stream from the primary MySQL instance(MySQL 8.0.33) to the replica(built based on go-mysql-server).
# Executed on Primary
mysql> CREATE USER 'lol'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'lol';
Query OK, 0 rows affected (0.01 sec)
  • Then I create an account on the primary MySQL instance.
# Executed on replica
mysql> select Host, User, plugin, authentication_string, identity from mysql.user where User = 'lol';
+------+------+-----------------------+-----------------------+-------------------------------------------+
| Host | User | plugin                | authentication_string | identity                                  |
+------+------+-----------------------+-----------------------+-------------------------------------------+
| %    | lol  | mysql_native_password |                       | *91D9861DFC07DD967611B8C96953474EF270AD5E |
+------+------+-----------------------+-----------------------+-------------------------------------------+
1 row in set (0.01 sec)
  • After that, I found the account was replicated successfully. But I failed connect the replica with the expected user and password, while the same operation on MySQL primary worked as expected.
# Connected to Primary, which succeeded
% mysql -h127.0.0.1 -P33306 -ulol -plol -e "select 1" 
mysql: [Warning] Using a password on the command line interface can be insecure.
+---+
| 1 |
+---+
| 1 |
+---+

# Connected to replica, which failed
% mysql -h127.0.0.1 -P23306 -ulol -plol -e "select 1"                                                                                                                                                                                        
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'lol'

# However, as I connected to replica without password, it succeeded
% mysql -h127.0.0.1 -P23306 -ulol -e "select 1"                                                                                                                                                                                              
+---+
| 1 |
+---+
| 1 |
+---+

As I dived into the implementation of the account replication. I found the root cause is:

  • The DDL statement of the 'CREATE USER' sent by primary MySQL instance is "CREATE USER ... IDENTIFIED ... AS '*91D9861DFC07DD967611B8C96953474EF270AD5E'". And then the query string was parsed by dolt-vitess to a "CreateUser" which with empty "Password" and non empty "Identity".
    MWympvaoLc
  • After that, go-mysql-server will persist the authentication data of this user with an empty "Password" string. So I could only connect to the replica without password.

After reading the documentation of "CREATE USER" MySQL. The keyword AS indicates that the following string is a hashed password string for the auth plugin. So I think go-mysql-server should store the hashed password string to the 'authentication_string', not just 'identity' in the table mysql.user.

@VWagen1989
Copy link
Contributor Author

I've also created a PR #2741. Please take a look :)

fulghum added a commit that referenced this issue Nov 11, 2024
fix: store the hashed password to 'authentication_string' (to #2740)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants