You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description :
-----------
We rewrite a SQL statement for following reasons:
a) Obfuscate the password as following
b) Skip some clauses from ACL DDLs before adding the statement to binlog.
c) Needs to re-synthesize some of the SQL statements.
There are following three mediums where we add the rewritten SQL statement.
a) Usual log files that includes General, slow query and audit log.
b) binlog files
c) Standard output to print the result of queries like SHOW CREATE USER.
Problems
========
1) A SQL statement which contains a plain text password is rewritten in two
different type in the different logs.
2) Current rewrite design is difficult to maintain and extend.
For instance - Refer Bug#24911117 (Sakila) (Sakila) fix in RB#19217.
3) If some of the clauses are not specified in the SQL statement then their
default value is added to the statement rewritten for the general log but
not for the audit, slow query and binlogs. It happens because once the query
is rewritten for the binlog the same is used for subsequent logs
(Refer Bug#27967905 (Sakila)).
This worklog proposes an alternate design to fix the current problems,
and make it easier to extend the rewrite functionality if so desired in future.
Design
======
1) Added following class hierarchy.
There is an abstract base class Rewriter. All the concrete classes have to
implement the method rewrite().
+-----------+
|I_Rewriter |
+-----------+
^
|
|
+-----------------+---------------+------------+-----+------------so on
| | | | |
| | | | |
Rewriter_user Rewriter_set Rewriter_slave_start | Rewriter_create_server
^ ^ |
| | Rewriter_change_master
| Rewriter_set_password
|
+-------------+---------------+
| | |
| | |
| | Rewriter_show_create_user
| |
| Rewriter_alter_user
|
Rewriter_create user
2) Added a Rewriter_util class to wrap the common utility methods used
across the classes.
3) Some of the ACL DDLs rewrite additional parameters so as much like earlier,
there are two interface functions to rewrite the query. The clients must
not create the rewriter objects directly, instead they should call following
functions as desired.
void mysql_rewrite_query()
void mysql_rewrite_acl_query()
Review:
-------
RB#19703
WITH MAX_QUERIES_PER_HOUR 2 MAX_USER_CONNECTIONS 2
1573
-
CREATE USER 'user13'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS '<secret>' ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
1573
+
CREATE USER 'user13'@'localhost' IDENTIFIED BY <secret> ACCOUNT UNLOCK
1574
1574
CREATE USER user14@localhost IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF'
1575
1575
ACCOUNT LOCK
1576
-
CREATE USER 'user15'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' PASSWORD EXPIRE NEVER ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
1576
+
CREATE USER 'user15'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY <secret> PASSWORD EXPIRE NEVER ACCOUNT UNLOCK
1577
1577
CREATE USER user16@localhost IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF'
1578
1578
ACCOUNT LOCK PASSWORD EXPIRE NEVER
1579
1579
CREATE USER user10@localhost IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF'
1580
1580
SELECT argument FROM mysql.general_log WHERE argument LIKE 'ALTER USER %' AND
1581
1581
command_type NOT LIKE 'Prepare';
1582
1582
argument
1583
-
ALTER USER 'u10'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' REQUIRE SSL PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
1583
+
ALTER USER 'u10'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY <secret> REQUIRE SSL
1584
1584
ALTER USER user11@localhost IDENTIFIED WITH 'sha256_password'
Copy file name to clipboardExpand all lines: mysql-test/r/rewrite_general_log.result
+51-15
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
1
TRUNCATE TABLE mysql.general_log;
2
+
CALL mtr.add_suppression('Following users were specified in CREATE USER IF NOT EXISTS but they already exist');
3
+
CALL mtr.add_suppression('Following users were specified in ALTER USER IF EXISTS but they do not exist');
2
4
--------------- general log ---------------------------------------
3
5
SET @old_log_output= @@global.log_output;
4
6
SET @old_general_log= @@global.general_log;
@@ -34,9 +36,28 @@ CREATE USER test_user2 IDENTIFIED WITH mysql_native_password BY 'azundris2';
34
36
CHANGE MASTER TO MASTER_PASSWORD='azundris3';
35
37
CREATE USER 'test_user4'@'localhost' IDENTIFIED WITH mysql_native_password;
36
38
ALTER USER 'test_user4'@'localhost' IDENTIFIED BY 'azundris4';
39
+
CREATE USER test_user5 IDENTIFIED WITH mysql_native_password AS
40
+
'*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF', test_user6 IDENTIFIED BY 'test';
41
+
ALTER USER IF EXISTS test_user5 IDENTIFIED BY 'test',
42
+
test_user6 IDENTIFIED WITH mysql_native_password AS
43
+
'*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF', test_user7 IDENTIFIED BY 'test';
44
+
Warnings:
45
+
Note 3162 Authorization ID 'test_user7'@'%' does not exist.
46
+
CREATE USER IF NOT EXISTS test_user6 IDENTIFIED BY 'test',
47
+
test_user7 IDENTIFIED BY 'test';
48
+
Warnings:
49
+
Note 3163 Authorization ID 'test_user6'@'%' already exists.
50
+
ALTER USER test_user7 IDENTIFIED WITH mysql_native_password AS
51
+
'*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF';
52
+
CREATE USER test_user8 IDENTIFIED BY '';
53
+
ALTER USER test_user8 IDENTIFIED BY '';
54
+
CREATE USER test_user9 IDENTIFIED WITH 'caching_sha2_password' BY '';
55
+
ALTER USER test_user9 IDENTIFIED WITH 'caching_sha2_password' BY '';
37
56
SET GLOBAL general_log= 'OFF';
38
57
DROP USER 'test_user4'@'localhost';
39
58
DROP USER 'test_user3'@'localhost';
59
+
DROP USER test_user9, test_user8;
60
+
DROP USER test_user7, test_user6, test_user5;
40
61
DROP USER test_user2;
41
62
DROP USER test_user1;
42
63
CREATE TABLE test_log (argument TEXT);
@@ -49,22 +70,37 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE CONCAT('%azun','dris%
49
70
argument
50
71
Show that we logged stuff at all:
51
72
------ from file ------
52
-
SELECT TRIM(LEADING '\t' FROM MID(argument,LOCATE('Query',argument)+5)) FROM test_log WHERE argument LIKE '%AS %' AND
53
-
argument NOT LIKE '%Prepare%';
73
+
SELECT TRIM(LEADING '\t' FROM MID(argument,LOCATE('Query',argument)+5)) FROM
74
+
test_log WHERE (argument LIKE '%BY %' OR argument LIKE '%AS %')
75
+
AND argument NOT LIKE '%Prepare%';
54
76
TRIM(LEADING '\t' FROM MID(argument,LOCATE('Query',argument)+5))
55
-
CREATE USER 'test_user1'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
56
-
CREATE USER 'test_user3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' REQUIRE SSL PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
57
-
ALTER USER 'test_user3'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS '<secret>' REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4 PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
58
-
CREATE USER 'test_user2'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
59
-
ALTER USER 'test_user4'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
77
+
CREATE USER 'test_user1'@'%' IDENTIFIED WITH 'mysql_native_password' BY <secret>
78
+
CREATE USER 'test_user3'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY <secret> REQUIRE SSL
79
+
ALTER USER 'test_user3'@'localhost' IDENTIFIED BY <secret> REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4
80
+
CREATE USER 'test_user2'@'%' IDENTIFIED WITH 'mysql_native_password' BY <secret>
81
+
ALTER USER 'test_user4'@'localhost' IDENTIFIED BY <secret>
82
+
CREATE USER 'test_user5'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF','test_user6'@'%' IDENTIFIED BY <secret>
83
+
ALTER USER IF EXISTS 'test_user5'@'%' IDENTIFIED BY <secret>,'test_user6'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF','test_user7'@'%' IDENTIFIED BY <secret>
84
+
CREATE USER IF NOT EXISTS 'test_user6'@'%' IDENTIFIED BY <secret>,'test_user7'@'%' IDENTIFIED BY <secret>
85
+
CREATE USER 'test_user8'@'%' IDENTIFIED BY <secret>
86
+
ALTER USER 'test_user8'@'%' IDENTIFIED BY <secret>
87
+
CREATE USER 'test_user9'@'%' IDENTIFIED WITH 'caching_sha2_password' BY <secret>
88
+
ALTER USER 'test_user9'@'%' IDENTIFIED WITH 'caching_sha2_password' BY <secret>
60
89
------ from table ------
61
-
SELECT argument FROM mysql.general_log WHERE argument LIKE '%AS %' AND command_type NOT LIKE 'Prepare';
90
+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%BY %' AND command_type NOT LIKE 'Prepare';
62
91
argument
63
-
CREATE USER 'test_user1'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
64
-
CREATE USER 'test_user3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' REQUIRE SSL PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
65
-
ALTER USER 'test_user3'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS '<secret>' REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4 PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
66
-
CREATE USER 'test_user2'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
67
-
ALTER USER 'test_user4'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS '<secret>' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
92
+
CREATE USER 'test_user1'@'%' IDENTIFIED WITH 'mysql_native_password' BY <secret>
93
+
CREATE USER 'test_user3'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY <secret> REQUIRE SSL
94
+
ALTER USER 'test_user3'@'localhost' IDENTIFIED BY <secret> REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4
95
+
CREATE USER 'test_user2'@'%' IDENTIFIED WITH 'mysql_native_password' BY <secret>
96
+
ALTER USER 'test_user4'@'localhost' IDENTIFIED BY <secret>
97
+
CREATE USER 'test_user5'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF','test_user6'@'%' IDENTIFIED BY <secret>
98
+
ALTER USER IF EXISTS 'test_user5'@'%' IDENTIFIED BY <secret>,'test_user6'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*67092806AE91BFB6BE72DE6C7BE2B7CCA8CFA9DF','test_user7'@'%' IDENTIFIED BY <secret>
99
+
CREATE USER IF NOT EXISTS 'test_user6'@'%' IDENTIFIED BY <secret>,'test_user7'@'%' IDENTIFIED BY <secret>
100
+
CREATE USER 'test_user8'@'%' IDENTIFIED BY <secret>
101
+
ALTER USER 'test_user8'@'%' IDENTIFIED BY <secret>
102
+
CREATE USER 'test_user9'@'%' IDENTIFIED WITH 'caching_sha2_password' BY <secret>
103
+
ALTER USER 'test_user9'@'%' IDENTIFIED WITH 'caching_sha2_password' BY <secret>
68
104
------ done ------
69
105
------ rewrite ------
70
106
SELECT argument FROM mysql.general_log WHERE argument LIKE CONCAT('set ','character set %');
@@ -84,8 +120,8 @@ GRANT EXECUTE ON FUNCTION test.func_rewrite_1 TO test_user1
84
120
GRANT SELECT,USAGE ON test.* TO test_user3@localhost
85
121
GRANT USAGE ON test.* TO test_user3@localhost WITH GRANT OPTION
86
122
------ done ------ see log_tables.test for more proof! :)
87
-
SELECT COUNT(*)>=1 FROM mysql.general_log WHERE argument LIKE 'CREATE USER%' AND argument LIKE CONCAT('%AS %');
88
-
COUNT(*)>=1
123
+
SELECT COUNT(*)=1 FROM mysql.general_log WHERE argument LIKE 'CREATE USER%' AND argument LIKE CONCAT('%AS %');
124
+
COUNT(*)=1
89
125
1
90
126
Bug#13958454 -- show we print SET @a:=5, but SELECT (@a:=5)
0 commit comments