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
WL#7131:Add timestamp in mysql.user on the last time the
password was changed and implement password rotation
We need to track when the password was last changed
and implement password rotation.
Put a TIMESTAMP column inside mysql.user table and
update it when the password is updated.
Put another column in mysql.user, holding the number
of days after which the password must expire.
Introduce extension of query ALTER USER as:
ALTER USER foo PASSWORD EXPIRE EVERY <day> DAY;
ALTER USER foo PASSWORD EXPIRE NEVER;
ALTER USER foo PASSWORD EXPIRE DEFAULT;
Copy file name to clipboardExpand all lines: mysql-test/include/mtr_system_tables_data.sql
+4-4
Original file line number
Diff line number
Diff line change
@@ -35,10 +35,10 @@ DROP TABLE tmp_db;
35
35
-- Fill "user" table with default users allowing root access
36
36
-- from local machine if "user" table didn't exist before
37
37
CREATE TEMPORARY TABLE tmp_user LIKE user;
38
-
INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N');
39
-
REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N'FROM dual WHERE @current_hostname !='localhost';
40
-
REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N');
41
-
REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N');
38
+
INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N',CURRENT_TIMESTAMP,NULL);
39
+
REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N',CURRENT_TIMESTAMP, NULLFROM dual WHERE @current_hostname !='localhost';
40
+
REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N',CURRENT_TIMESTAMP,NULL);
41
+
REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,@@default_authentication_plugin,'','N',CURRENT_TIMESTAMP,NULL);
42
42
INSERT INTO tmp_user (host,user) SELECT @current_hostname,''FROM dual WHERE @current_hostname !='localhost';
43
43
INSERT INTO user SELECT*FROM tmp_user WHERE @had_user_table=0;
# WL#7131: Add timestamp in mysql.user on the last time the
2626
+
# password was changed and implement password rotation.
2627
+
#
2628
+
SET @saved_value = @@global.default_password_lifetime;
2629
+
SET GLOBAL default_password_lifetime = 2;
2630
+
SHOW VARIABLES LIKE 'default_password_lifetime';
2631
+
Variable_name Value
2632
+
default_password_lifetime 2
2633
+
CREATE USER 'wl7131' IDENTIFIED BY 'wl7131';
2634
+
# This should report 1.
2635
+
SELECT (SELECT now()-(SELECT password_last_changed from mysql.user where user='wl7131')) <= 2;
2636
+
(SELECT now()-(SELECT password_last_changed from mysql.user where user='wl7131')) <= 2
2637
+
1
2638
+
UPDATE mysql.user SET password_last_changed = (now() - INTERVAL 3 DAY) where user='wl7131';
2639
+
FLUSH PRIVILEGES;
2640
+
# Attempt to execute query should fail
2641
+
mysql: [Warning] Using a password on the command line interface can be insecure.
2642
+
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2643
+
# Doing something should fail
2644
+
SELECT 1;
2645
+
ERROR HY000: You must SET PASSWORD before executing this statement
2646
+
# Setting variables should work
2647
+
SET old_passwords=0;
2648
+
# Setting password should work
2649
+
SET PASSWORD = PASSWORD('new_wl7131');
2650
+
# Doing something should pass
2651
+
SELECT 1;
2652
+
1
2653
+
1
2654
+
# Reconnecting with same user should pass now
2655
+
SELECT 1;
2656
+
1
2657
+
1
2658
+
DROP USER 'wl7131';
2659
+
CREATE USER 'wl7131' IDENTIFIED BY 'wl7131';
2660
+
# Issue alter user and check the value of
2661
+
# password_lifetime column
2662
+
ALTER USER 'wl7131' PASSWORD EXPIRE NEVER;
2663
+
# This should report 0
2664
+
SELECT password_lifetime FROM mysql.user where user='wl7131';
2665
+
password_lifetime
2666
+
0
2667
+
UPDATE mysql.user SET password_last_changed = (now() - INTERVAL 5 DAY) where user='wl7131';
2668
+
FLUSH PRIVILEGES;
2669
+
# This should pass as password is never expired.
2670
+
mysql: [Warning] Using a password on the command line interface can be insecure.
2671
+
ALTER USER 'wl7131' PASSWORD EXPIRE DEFAULT;
2672
+
# This should report NULL
2673
+
SELECT password_lifetime FROM mysql.user where user='wl7131';
2674
+
password_lifetime
2675
+
NULL
2676
+
# This should not pass as default_password_lifetime
2677
+
# (which is 2 now) is being used.
2678
+
mysql: [Warning] Using a password on the command line interface can be insecure.
2679
+
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2680
+
SET GLOBAL default_password_lifetime = 0;
2681
+
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 4 DAY;
2682
+
# Should report 4
2683
+
SELECT password_lifetime FROM mysql.user where user='wl7131';
2684
+
password_lifetime
2685
+
4
2686
+
# This should not pass.
2687
+
mysql: [Warning] Using a password on the command line interface can be insecure.
2688
+
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2689
+
SET GLOBAL default_password_lifetime = @saved_value;
2690
+
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 6 DAY;
2691
+
# Should report 6
2692
+
select password_lifetime from mysql.user where user='wl7131';
2693
+
password_lifetime
2694
+
6
2695
+
# This should pass.
2696
+
mysql: [Warning] Using a password on the command line interface can be insecure.
2697
+
DROP USER 'wl7131';
2698
+
CREATE USER 'wl7131';
2699
+
# This should not report NULL
2700
+
'DTVALUE' IS NOT NULL
2701
+
1
2702
+
GRANT USAGE ON *.* TO 'wl7131' REQUIRE SSL;
2703
+
# This should report 0 as it must have the same value as above
2704
+
TIMESTAMPDIFF(SECOND,'DTVALUE','DTVALUE') <> 0
2705
+
0
2706
+
# Should report errors
2707
+
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL -2 DAY;
2708
+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2 DAY' at line 1
2709
+
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 0 DAY;
2710
+
ERROR HY000: Incorrect DAY value: '0'
2711
+
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 65536 DAY;
2712
+
ERROR HY000: Incorrect DAY value: '65536'
2713
+
# Setting an empty password. It should update the timestamp column.
2714
+
SET PASSWORD FOR 'wl7131' = PASSWORD('');
2715
+
# This should report 1.
2716
+
SELECT (SELECT now()-(SELECT password_last_changed from mysql.user where user='wl7131')) <= 2;
2717
+
(SELECT now()-(SELECT password_last_changed from mysql.user where user='wl7131')) <= 2
2718
+
1
2719
+
DROP USER 'wl7131';
2720
+
GRANT USAGE ON *.* TO 'wl7131'@'localhost' IDENTIFIED BY 'wl7131';
2721
+
# Must report 1
2722
+
SELECT (SELECT password_last_changed FROM mysql.user where user='wl7131') IS NOT NULL;
2723
+
(SELECT password_last_changed FROM mysql.user where user='wl7131') IS NOT NULL
0 commit comments