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

*: Support Failed-Login Tracking and Temporary Account Locking #39322

Merged
merged 247 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
247 commits
Select commit Hold shift + click to select a range
501b772
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 22, 2022
c336cae
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 22, 2022
d70c2d2
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 22, 2022
a84b632
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 23, 2022
14c49db
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 23, 2022
8d410f5
Failed-Login Tracking and Temporary Account Locking
lastincisor Nov 23, 2022
3ff94ed
error fix
lastincisor Nov 23, 2022
9dc880f
error fix
lastincisor Nov 23, 2022
d79b208
error fix
lastincisor Nov 24, 2022
e7327c1
error fix
lastincisor Nov 24, 2022
3a30c3a
lockTime -1 error fix
lastincisor Nov 24, 2022
34201d3
alter user 'u1'@'localhost' FAILED_LOGIN_ATTEMPTS 32768;
lastincisor Nov 24, 2022
c3fd5d9
create user range fix
lastincisor Nov 25, 2022
7694be9
refactor executeCreateUser passwordOrLockOptionsInfoParser
lastincisor Nov 26, 2022
f9b7e87
refactor executeAlterUser passwordOrLockOptionsInfoParser
lastincisor Nov 26, 2022
6516405
refactor code
lastincisor Nov 26, 2022
6f81508
refactor code
lastincisor Nov 26, 2022
30c6896
refactor code
lastincisor Nov 26, 2022
b33ee55
refactor code
lastincisor Nov 26, 2022
fce7f88
refactor code
lastincisor Nov 26, 2022
bc857e7
refactor code
lastincisor Nov 26, 2022
40015ec
refactor code
lastincisor Nov 26, 2022
61127d0
refactor code
lastincisor Nov 26, 2022
c8b176a
refactor code
lastincisor Nov 26, 2022
7c9567d
refactor code
lastincisor Nov 26, 2022
978cc01
refactor code
lastincisor Nov 27, 2022
3d167d7
empty-lines: extra empty line at the end of a block (all_revive)
lastincisor Nov 27, 2022
dcdfd64
empty-lines: extra empty line at the end of a block (all_revive)
lastincisor Nov 27, 2022
a566df9
remove UnReservedKeyword
lastincisor Nov 28, 2022
2f596c2
test case
lastincisor Nov 28, 2022
9202619
test case
lastincisor Nov 28, 2022
e0f80a8
paeser formart
lastincisor Nov 28, 2022
e599d20
NotifyUpdatePrivilege err
lastincisor Nov 28, 2022
06d724c
NotifyUpdatePrivilege err
lastincisor Nov 28, 2022
8e0e1a6
bug fix
lastincisor Nov 28, 2022
2f75691
show add failedLoginAttempts passwordLockTimeDays
lastincisor Nov 28, 2022
db1f19a
SHOW test case
lastincisor Nov 28, 2022
35c74ff
code format
lastincisor Nov 28, 2022
e378bac
code format
lastincisor Nov 28, 2022
b880aa0
code format
lastincisor Nov 28, 2022
0ec6fa1
error code
lastincisor Nov 29, 2022
999ce53
error code
lastincisor Nov 29, 2022
404b07c
show bug fix
lastincisor Nov 29, 2022
995c874
merge master
lastincisor Nov 29, 2022
0c43ec7
string sql format
lastincisor Nov 29, 2022
729dc8a
code format
lastincisor Nov 29, 2022
5718453
code format
lastincisor Nov 29, 2022
2eebaae
code format
lastincisor Nov 29, 2022
d9c8ab2
Apply suggestions from code review
lastincisor Nov 29, 2022
ea42eb8
Apply suggestions from code review
lastincisor Nov 29, 2022
c871cdc
code format
lastincisor Nov 29, 2022
f1c86ff
modified: privilege/privileges/cache.go
bob34007 Nov 29, 2022
7b1df7e
modified: errno/errname.go
bob34007 Nov 29, 2022
5eb007e
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 29, 2022
d35219e
add comment
lastincisor Nov 29, 2022
a5d30aa
empty-lines: extra empty line at the start of a block (all_revive)
lastincisor Nov 29, 2022
897fd14
change alter user
keeplearning20221 Nov 29, 2022
d2c5c7d
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 29, 2022
50633e1
getFailedLoginCount bug fix
lastincisor Nov 29, 2022
6675cd1
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 29, 2022
a1a8f39
modified: simple.go
keeplearning20221 Nov 29, 2022
dafa247
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 29, 2022
e325c85
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Nov 29, 2022
f606e9a
modified: simple.go
keeplearning20221 Nov 29, 2022
ecc939b
code format
lastincisor Nov 30, 2022
1b7c067
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
d8b33bd
modified: executor/simple.go
keeplearning20221 Nov 30, 2022
463deb6
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 30, 2022
b398002
merge master
lastincisor Nov 30, 2022
09475b9
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
a15f48c
modified: cache.go
keeplearning20221 Nov 30, 2022
7ff0694
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 30, 2022
bb457fd
modified: ../../executor/simple.go
keeplearning20221 Nov 30, 2022
c1eb364
UserAttributesInfo comment
lastincisor Nov 30, 2022
b180526
AccessDenied rename passwordErr
lastincisor Nov 30, 2022
ea08a30
error code
lastincisor Nov 30, 2022
4312967
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
61649db
IsConnectionPasswordFailed
lastincisor Nov 30, 2022
fe7ac11
add ErrUserPasswordFailed err
lastincisor Nov 30, 2022
281adb3
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
2ce1fac
modified: privilege/privilege.go
bob34007 Nov 30, 2022
ef8ffb5
modified: privilege/privileges/privileges.go
bob34007 Nov 30, 2022
f7c4b33
err bug fix
lastincisor Nov 30, 2022
baa740c
ErrUserPasswordFailed add comment
lastincisor Nov 30, 2022
5b4faa1
modified: session/session.go
keeplearning20221 Nov 30, 2022
a580fcc
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 30, 2022
f3677c6
error code format
lastincisor Nov 30, 2022
96e3104
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
a96430f
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
44e48e6
modified: privilege/privileges/privileges.go
keeplearning20221 Nov 30, 2022
28fd5e7
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Nov 30, 2022
6e4dd7d
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
ac876ba
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
f7d8d50
Merge https://github.com/pingcap/tidb into failed-login-tracking
lastincisor Nov 30, 2022
e09589b
merge master
lastincisor Nov 30, 2022
1aefdee
Merge branch 'master' into failed-login-tracking
lastincisor Nov 30, 2022
e2fc639
Merge branch 'master' into failed-login-tracking
lastincisor Nov 30, 2022
d75d16a
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
6e33dd8
ErrUserPasswordFailed comment
lastincisor Dec 1, 2022
2efaefc
Update privilege/privileges/errors.go
lastincisor Dec 1, 2022
831d8a0
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
92efcd0
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
9301c22
merge master
lastincisor Dec 1, 2022
c3f5341
merge master
lastincisor Dec 1, 2022
d775ace
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
aecc57e
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
b56314e
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
87fcc25
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
bb0d0e3
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
c28eca3
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
cd56d08
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
050808c
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
008bae0
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
94d10f6
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
cb4b60e
merge master
lastincisor Dec 1, 2022
5e2ce98
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 1, 2022
d4815e4
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
b172185
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
7c50651
Merge branch 'master' into failed-login-tracking
lastincisor Dec 1, 2022
8257960
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
521162a
remove comment
lastincisor Dec 2, 2022
ed35d68
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 2, 2022
f47fd0d
merge master
lastincisor Dec 2, 2022
f3bab00
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
45d98c8
resolve conflicts
keeplearning20221 Dec 2, 2022
9031dc5
merge master conflict
lastincisor Dec 2, 2022
bedbb12
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 2, 2022
bccb3c9
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 2, 2022
9cd433f
merge master conflict
lastincisor Dec 2, 2022
10c5bc7
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
baedd7b
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 2, 2022
0082aca
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 2, 2022
750b46a
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
1c0f6d5
ErrUserPasswordFailed error compatible mysql error
lastincisor Dec 2, 2022
8fc9459
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
6443f01
modified: session/session.go
keeplearning20221 Dec 2, 2022
f222635
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
92d0ce4
modified: privilege/privilege.go
keeplearning20221 Dec 2, 2022
53002c6
IsAccountAutoLockEnabled comment
lastincisor Dec 2, 2022
1138fd4
modified: executor/simple.go
keeplearning20221 Dec 2, 2022
d82d012
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
694e245
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
4368383
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
47c504e
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
a6edfa1
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
bee00e8
merge master
lastincisor Dec 2, 2022
0c86a78
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
1ef49bd
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
033d74b
merge master
lastincisor Dec 2, 2022
0104a1e
modified: executor/simple.go
bob34007 Dec 2, 2022
6c0cd90
merge master
lastincisor Dec 2, 2022
43b7122
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 2, 2022
c1a5c90
Apply suggestions from code review
bob34007 Dec 2, 2022
e41db6c
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 2, 2022
9ddd41f
EnableSandBoxMode bug fix
lastincisor Dec 2, 2022
fb90ce5
modified: executor/simple.go
bob34007 Dec 2, 2022
26db9f2
Merge branch 'failed-login-tracking' of github.com:lastincisor/tidb i…
bob34007 Dec 2, 2022
b8414db
Merge branch 'master' into failed-login-tracking
lastincisor Dec 2, 2022
1a6ba47
add notes
keeplearning20221 Dec 3, 2022
e7f8ac5
Merge branch 'master' into failed-login-tracking
lastincisor Dec 3, 2022
9999b38
modified: privilege/privileges/privileges.go
keeplearning20221 Dec 3, 2022
b092cc6
modified: privilege/privileges/BUILD.bazel
keeplearning20221 Dec 3, 2022
dd3dc96
modified: session/session.go
bob34007 Dec 4, 2022
a28d9de
modified: privilege/privileges/privileges.go
keeplearning20221 Dec 5, 2022
7dc874a
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 5, 2022
8f3b06f
changeAutoLockedLastChanged timeout 1s
lastincisor Dec 5, 2022
1b0e80f
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 5, 2022
1b27955
modified: privilege/privilege.go
bob34007 Dec 5, 2022
738b959
modified: session/session.go
bob34007 Dec 5, 2022
d47ea33
modified: session/session.go
bob34007 Dec 5, 2022
4138170
parser_test add test case
lastincisor Dec 5, 2022
90591c7
failedLoginTracking Commit
lastincisor Dec 5, 2022
931d4bf
modified: privilege/privilege.go
bob34007 Dec 5, 2022
051450f
Merge branch 'failed-login-tracking' of github.com:lastincisor/tidb i…
bob34007 Dec 5, 2022
d329e29
modified: session/session.go
bob34007 Dec 5, 2022
e5fba41
Merge branch 'master' into failed-login-tracking
bob34007 Dec 5, 2022
8c2b6d8
modified: session/session.go
bob34007 Dec 5, 2022
e609c1a
Merge branch 'failed-login-tracking' of github.com:lastincisor/tidb i…
bob34007 Dec 5, 2022
4edbbca
remove BEGIN PESSIMISTIC rollback
lastincisor Dec 5, 2022
16da95d
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 5, 2022
c8ad39f
VerifyAccountAutoLockInMemory comment
lastincisor Dec 5, 2022
1a03325
Merge branch 'master' into failed-login-tracking
lastincisor Dec 5, 2022
3cac9b3
remove validate_password_dictionary_file
lastincisor Dec 5, 2022
6ee17d2
Merge remote-tracking branch 'origin/failed-login-tracking' into fail…
lastincisor Dec 5, 2022
479f50c
Fix unauthorized failure
keeplearning20221 Dec 5, 2022
466faae
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 5, 2022
2a7b0f5
modified: privileges_test.go
keeplearning20221 Dec 5, 2022
3c697be
Merge branch 'master' into failed-login-tracking
lastincisor Dec 5, 2022
f64877e
Fix merge bug
keeplearning20221 Dec 5, 2022
c687cf6
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 5, 2022
5ce0241
modified: privilege/privileges/privileges_test.go
bob34007 Dec 5, 2022
82e8101
modified: simple_test.go
keeplearning20221 Dec 5, 2022
f2c23f9
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 5, 2022
eeff5ae
modified: privilege/privileges/privileges_test.go
bob34007 Dec 5, 2022
8f775ad
remove validate_password_dictionary_file
lastincisor Dec 5, 2022
1122386
modified: ../../executor/simple.go
bob34007 Dec 5, 2022
06dfb0f
Merge branch 'failed-login-tracking' of github.com:lastincisor/tidb i…
bob34007 Dec 5, 2022
39786a3
modified: privilege/privileges/privileges_test.go
keeplearning20221 Dec 5, 2022
e92cfea
TODO: add more tests in TestPasswordManagement
CbcWestwolf Dec 5, 2022
5e64a36
Format
CbcWestwolf Dec 5, 2022
8e0e71e
Merge branch 'master' into failed-login-tracking
keeplearning20221 Dec 6, 2022
d60d44c
fix build error
keeplearning20221 Dec 6, 2022
1fbb402
TestPasswordExpiredAndTacking test case
lastincisor Dec 6, 2022
32b304a
modified: simple_test.go
keeplearning20221 Dec 6, 2022
57e75b6
Merge branch 'master' into failed-login-tracking
lastincisor Dec 6, 2022
e5ad265
modified: executor/simpletest/BUILD.bazel
keeplearning20221 Dec 6, 2022
9cb12a7
Merge branch 'master' into failed-login-tracking
keeplearning20221 Dec 6, 2022
dd6dfcd
modified: privileges_test.go
bob34007 Dec 6, 2022
38bca31
Merge branch 'failed-login-tracking' of github.com:lastincisor/tidb i…
bob34007 Dec 6, 2022
bc2eeaf
modified: privileges_test.go
bob34007 Dec 6, 2022
20c98c8
Fix upgrade error
CbcWestwolf Dec 6, 2022
ca85e55
modified: simple_test.go
keeplearning20221 Dec 6, 2022
87b4ceb
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 6, 2022
66c795e
fix: sandbox mode can only set password for current user
CbcWestwolf Dec 6, 2022
b863270
privilege: add VerificationInfo for Manager.ConnectionVerification
CbcWestwolf Dec 6, 2022
17c0e45
Merge branch 'master' into failed-login-tracking
CbcWestwolf Dec 6, 2022
2806e07
modified: simple_test.go
keeplearning20221 Dec 6, 2022
fd38034
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 6, 2022
de62593
modified: executor/simpletest/BUILD.bazel
keeplearning20221 Dec 6, 2022
82efd62
Merge branch 'master' into failed-login-tracking
keeplearning20221 Dec 6, 2022
142d8df
modified: privileges_test.go
bob34007 Dec 6, 2022
889ec67
Merge branch 'master' of github.com:pingcap/tidb into failed-login-tr…
CbcWestwolf Dec 6, 2022
5385a8b
Fix typo error; format some code snippets
CbcWestwolf Dec 6, 2022
fc40d76
Fix typo error; format some code snippets
CbcWestwolf Dec 6, 2022
392f9b7
Merge branch 'master' into failed-login-tracking
lastincisor Dec 7, 2022
d131831
fix reuse password error handling by default
keeplearning20221 Dec 7, 2022
3772d8b
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 7, 2022
f2a68de
modified: ../show.go
bob34007 Dec 7, 2022
8fdbe42
modified: privileges_test.go
bob34007 Dec 7, 2022
7744e15
modified: ../../session/session.go
bob34007 Dec 7, 2022
7de5f1c
Solve the problem of asymmetric encryption and cannot check the consi…
keeplearning20221 Dec 7, 2022
f9144fa
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 7, 2022
ef314e1
Merge branch 'master' of github.com:pingcap/tidb into failed-login-tr…
CbcWestwolf Dec 7, 2022
604de6b
add mutiDifferentAuth
keeplearning20221 Dec 7, 2022
9f59560
Merge branch 'failed-login-tracking' of https://github.com/lastinciso…
keeplearning20221 Dec 7, 2022
216a877
Fix UT failure
CbcWestwolf Dec 7, 2022
e05bdd4
AuthTiDBAuthToken is the token login method on the cloud, and the Pas…
keeplearning20221 Dec 7, 2022
d35c0da
Merge branch 'master' into failed-login-tracking
keeplearning20221 Dec 7, 2022
3fd30f4
modified: ../privilege/privilege.go
bob34007 Dec 8, 2022
b39df8e
Merge branch 'master' into failed-login-tracking
bob34007 Dec 8, 2022
6e61507
Update executor/simpletest/simple_test.go
CbcWestwolf Dec 8, 2022
4580c34
Update session/session.go
CbcWestwolf Dec 8, 2022
5b42394
Summarize the tests
CbcWestwolf Dec 8, 2022
be1830c
Merge branch 'master' of github.com:pingcap/tidb into failed-login-tr…
CbcWestwolf Dec 8, 2022
4f652e6
Merge branch 'master' into failed-login-tracking
lastincisor Dec 9, 2022
6e0089b
Modify as suggested by bb7133
keeplearning20221 Dec 9, 2022
8f6b926
Merge branch 'master' into failed-login-tracking
ti-chi-bot Dec 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errno/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ const (
ErrFunctionalIndexDataIsTooLong = 3907
ErrFunctionalIndexNotApplicable = 3909
ErrDynamicPrivilegeNotRegistered = 3929
ErUserAccessDeniedForUserAccountBlockedByPasswordLock = 3955
ErrTableWithoutPrimaryKey = 3750
// MariaDB errors.
ErrOnlyOneDefaultPartionAllowed = 4030
Expand Down
1 change: 1 addition & 0 deletions errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrDependentByGeneratedColumn: mysql.Message("Column '%s' has a generated column dependency.", nil),
ErrGeneratedColumnRefAutoInc: mysql.Message("Generated column '%s' cannot refer to auto-increment column.", nil),
ErrAccountHasBeenLocked: mysql.Message("Access denied for user '%s'@'%s'. Account is locked.", nil),
ErUserAccessDeniedForUserAccountBlockedByPasswordLock: mysql.Message("Access denied for user '%s'@'%s'. Account is blocked for %s day(s) (%s day(s) remaining) due to %d consecutive failed logins.", nil),
ErrWarnConflictingHint: mysql.Message("Hint %s is ignored as conflicting/duplicated.", nil),
ErrUnresolvedHintName: mysql.Message("Unresolved name '%s' for %s hint", nil),
ErrForeignKeyCascadeDepthExceeded: mysql.Message("Foreign key cascade delete/update exceeds max depth of %v.", nil),
Expand Down
21 changes: 18 additions & 3 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,8 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {

exec := e.ctx.(sqlexec.RestrictedSQLExecutor)

rows, _, err := exec.ExecRestrictedSQL(ctx, nil, `SELECT plugin, Account_locked, JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.metadata')), Token_issuer
rows, _, err := exec.ExecRestrictedSQL(ctx, nil, `SELECT plugin, Account_locked, JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.metadata')), Token_issuer,
JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.Password_locking.failed_login_attempts')), JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.Password_locking.password_lock_time_days'))
FROM %n.%n WHERE User=%? AND Host=%?`,
mysql.SystemDB, mysql.UserTable, userName, strings.ToLower(hostName))
if err != nil {
Expand Down Expand Up @@ -1546,6 +1547,20 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {
tokenIssuer = " token_issuer " + tokenIssuer
}

failedLoginAttempts := rows[0].GetString(4)
if len(failedLoginAttempts) > 0 {
failedLoginAttempts = " FAILED_LOGIN_ATTEMPTS " + failedLoginAttempts
}

passwordLockTimeDays := rows[0].GetString(5)
if len(passwordLockTimeDays) > 0 {
lastincisor marked this conversation as resolved.
Show resolved Hide resolved
if passwordLockTimeDays == "-1" {
passwordLockTimeDays = " PASSWORD_LOCK_TIME UNBOUNDED"
} else {
passwordLockTimeDays = " PASSWORD_LOCK_TIME " + passwordLockTimeDays
}
}

rows, _, err = exec.ExecRestrictedSQL(ctx, nil, `SELECT Priv FROM %n.%n WHERE User=%? AND Host=%?`, mysql.SystemDB, mysql.GlobalPrivTable, userName, hostName)
if err != nil {
return errors.Trace(err)
Expand All @@ -1569,8 +1584,8 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {
}

// FIXME: the returned string is not escaped safely
showStr := fmt.Sprintf("CREATE USER '%s'@'%s' IDENTIFIED WITH '%s'%s REQUIRE %s%s PASSWORD EXPIRE DEFAULT ACCOUNT %s%s",
e.User.Username, e.User.Hostname, authplugin, authStr, require, tokenIssuer, accountLocked, userAttributes)
showStr := fmt.Sprintf("CREATE USER '%s'@'%s' IDENTIFIED WITH '%s'%s REQUIRE %s%s PASSWORD EXPIRE DEFAULT ACCOUNT %s%s%s%s",
e.User.Username, e.User.Hostname, authplugin, authStr, require, tokenIssuer, accountLocked, userAttributes, failedLoginAttempts, passwordLockTimeDays)
e.appendRow([]interface{}{showStr})
return nil
}
Expand Down
232 changes: 196 additions & 36 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"os"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -51,6 +53,7 @@ import (
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mathutil"
pwdValidator "github.com/pingcap/tidb/util/password-validation"
"github.com/pingcap/tidb/util/sem"
"github.com/pingcap/tidb/util/sqlexec"
Expand Down Expand Up @@ -801,6 +804,152 @@ func (e *SimpleExec) isValidatePasswordEnabled() bool {
return variable.TiDBOptOn(validatePwdEnable)
}

type passwordOrLockOptionsInfo struct {
LockAccount string
FailedLoginAttempts int64
PasswordLockTime int64
FailedLoginAttemptsChange bool
PasswordLockTimeChange bool
}

type alterUserPasswordLocking struct {
FailedLoginAttempts int64
PasswordLockTime int64
FailedLoginAttemptsNotFound bool
PasswordLockTimeChangeNotFound bool
commentIsNull bool
}

func (info *passwordOrLockOptionsInfo) passwordOrLockOptionsInfoParser(plOption []*ast.PasswordOrLockOption) {
// If "ACCOUNT LOCK" or "ACCOUNT UNLOCK" appears many times,
// the last declaration takes effect.
for _, option := range plOption {
switch option.Type {
case ast.Lock:
info.LockAccount = "Y"
case ast.Unlock:
info.LockAccount = "N"
case ast.FailedLoginAttempts:
info.FailedLoginAttempts = mathutil.Min(option.Count, math.MaxInt16)
info.FailedLoginAttemptsChange = true
case ast.PasswordLockTime:
info.PasswordLockTime = mathutil.Min(option.Count, math.MaxInt16)
info.PasswordLockTimeChange = true
case ast.PasswordLockTimeUnbounded:
info.PasswordLockTime = -1
info.PasswordLockTimeChange = true
}
}
}

func createUserFailedLoginJSON(info *passwordOrLockOptionsInfo) string {
if (info.FailedLoginAttemptsChange || info.PasswordLockTimeChange) && (info.FailedLoginAttempts != 0 || info.PasswordLockTime != 0) {
return fmt.Sprintf("{\"Password_locking\": {\"failed_login_attempts\": %d,\"password_lock_time_days\": %d}}",
info.FailedLoginAttempts, info.PasswordLockTime)
}
return ""
}

func alterUserFailedLoginJSON(info *alterUserPasswordLocking, lockAccount string) string {
passwordLockingArray := []string{}
if lockAccount == "N" && (info.FailedLoginAttempts != 0 || info.PasswordLockTime != 0) {
passwordLockingArray = append(passwordLockingArray, fmt.Sprintf("\"auto_account_locked\": \"%s\"", lockAccount))
passwordLockingArray = append(passwordLockingArray, fmt.Sprintf("\"auto_locked_last_changed\": \"%s\"", time.Now().Format(time.UnixDate)))
passwordLockingArray = append(passwordLockingArray, fmt.Sprintf("\"failed_login_count\": %d", 0))
}
if info.FailedLoginAttempts != 0 || info.PasswordLockTime != 0 {
passwordLockingArray = append(passwordLockingArray, fmt.Sprintf("\"failed_login_attempts\": %d", info.FailedLoginAttempts))
passwordLockingArray = append(passwordLockingArray, fmt.Sprintf("\"password_lock_time_days\": %d", info.PasswordLockTime))
}
if len(passwordLockingArray) > 0 {
return fmt.Sprintf("\"Password_locking\": {%s}", strings.Join(passwordLockingArray, ","))
}
return ""
}

func readUserAttributes(ctx context.Context, sqlExecutor sqlexec.SQLExecutor, name string, host string, pLO *passwordOrLockOptionsInfo) (*alterUserPasswordLocking, error) {
alterUserInfo := &alterUserPasswordLocking{0, 0, false, false, false}
lastincisor marked this conversation as resolved.
Show resolved Hide resolved
sql := new(strings.Builder)
sqlexec.MustFormatSQL(sql, `SELECT JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.Password_locking.failed_login_attempts')), JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.Password_locking.password_lock_time_days')),
JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.metadata')) FROM %n.%n WHERE User=%? AND Host=%?;`, mysql.SystemDB, mysql.UserTable, name, strings.ToLower(host))
recordSet, err := sqlExecutor.ExecuteInternal(ctx, sql.String())
if err != nil {
return nil, err
}
rows, err := sqlexec.DrainRecordSet(ctx, recordSet, 3)
if err != nil {
return nil, err
}

if pLO.FailedLoginAttemptsChange {
alterUserInfo.FailedLoginAttempts = pLO.FailedLoginAttempts
} else {
FailedLoginAttempts := rows[0].GetString(0)
lastincisor marked this conversation as resolved.
Show resolved Hide resolved
if len(FailedLoginAttempts) > 0 {
alterUserInfo.FailedLoginAttempts, err = strconv.ParseInt(FailedLoginAttempts, 10, 64)
if err != nil {
return nil, err
}
if alterUserInfo.FailedLoginAttempts < 0 {
alterUserInfo.FailedLoginAttempts = 0
} else {
alterUserInfo.FailedLoginAttempts = mathutil.Min(alterUserInfo.FailedLoginAttempts, math.MaxInt16)
}
} else {
alterUserInfo.FailedLoginAttempts = 0
alterUserInfo.FailedLoginAttemptsNotFound = true
}
}

if pLO.PasswordLockTimeChange {
alterUserInfo.PasswordLockTime = pLO.PasswordLockTime
} else {
PasswordLockTime := rows[0].GetString(1)
lastincisor marked this conversation as resolved.
Show resolved Hide resolved
if len(PasswordLockTime) > 0 {
alterUserInfo.PasswordLockTime, err = strconv.ParseInt(PasswordLockTime, 10, 64)
if err != nil {
return nil, err
}
if alterUserInfo.PasswordLockTime < -1 {
alterUserInfo.PasswordLockTime = -1
} else {
alterUserInfo.PasswordLockTime = mathutil.Min(alterUserInfo.PasswordLockTime, math.MaxInt16)
}
} else {
alterUserInfo.PasswordLockTime = 0
alterUserInfo.PasswordLockTimeChangeNotFound = true
}
}
if len(rows[0].GetString(2)) > 0 {
alterUserInfo.commentIsNull = false
} else {
alterUserInfo.commentIsNull = true
}
return alterUserInfo, nil
}

// If FailedLoginAttempts = 0 and PasswordLockTime = 0 delete Password_locking info
func deleteFailedLogin(ctx context.Context, sqlExecutor sqlexec.SQLExecutor, name string, host string, alterUser *alterUserPasswordLocking) error {
if alterUser.FailedLoginAttemptsNotFound && alterUser.PasswordLockTimeChangeNotFound {
return nil
}
if alterUser.FailedLoginAttempts != 0 || alterUser.PasswordLockTime != 0 {
return nil
}
sql := new(strings.Builder)
if alterUser.commentIsNull {
sqlexec.MustFormatSQL(sql, `UPDATE %n.%n SET user_attributes=NULL `, mysql.SystemDB, mysql.UserTable)
} else {
sqlexec.MustFormatSQL(sql, `UPDATE %n.%n SET user_attributes=JSON_REMOVE(user_attributes, '$.Password_locking') `, mysql.SystemDB, mysql.UserTable)
}
sqlexec.MustFormatSQL(sql, " WHERE Host=%? and User=%?;", host, name)
_, err := sqlExecutor.ExecuteInternal(ctx, sql.String())
if err != nil {
return err
}
return nil
}

func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStmt) error {
internalCtx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnPrivilege)
// Check `CREATE USER` privilege.
Expand All @@ -822,46 +971,42 @@ func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStm
}
}
}

privData, err := tlsOption2GlobalPriv(s.AuthTokenOrTLSOptions)
if err != nil {
return err
}

lockAccount := "N"
if length := len(s.PasswordOrLockOptions); length > 0 {
// If "ACCOUNT LOCK" or "ACCOUNT UNLOCK" appears many times,
// the last declaration takes effect.
for i := length - 1; i >= 0; i-- {
if s.PasswordOrLockOptions[i].Type == ast.Lock {
lockAccount = "Y"
break
} else if s.PasswordOrLockOptions[i].Type == ast.Unlock {
break
}
}
plInfo := &passwordOrLockOptionsInfo{LockAccount: lockAccount, FailedLoginAttemptsChange: false, PasswordLockTimeChange: false}
plInfo.passwordOrLockOptionsInfoParser(s.PasswordOrLockOptions)
PasswordLocking := createUserFailedLoginJSON(plInfo)
if plInfo.LockAccount != "" {
lockAccount = plInfo.LockAccount
}
if s.IsCreateRole {
lockAccount = "Y"
}

var userAttributes any = nil
if s.CommentOrAttributeOption != nil {
if s.CommentOrAttributeOption.Type == ast.UserCommentType {
userAttributes = fmt.Sprintf("{\"metadata\": {\"comment\": \"%s\"}}", s.CommentOrAttributeOption.Value)
} else if s.CommentOrAttributeOption.Type == ast.UserAttributeType {
userAttributes = fmt.Sprintf("{\"metadata\": %s}", s.CommentOrAttributeOption.Value)
}
if plInfo.FailedLoginAttemptsChange || plInfo.PasswordLockTimeChange {
userAttributes = fmt.Sprintf("{%s,%s}", userAttributes, PasswordLocking)
}
} else {
if plInfo.FailedLoginAttemptsChange || plInfo.PasswordLockTimeChange {
userAttributes = PasswordLocking
}
}

tokenIssuer := ""
for _, authTokenOption := range s.AuthTokenOrTLSOptions {
switch authTokenOption.Type {
case ast.TokenIssuer:
tokenIssuer = authTokenOption.Value
}
}

sql := new(strings.Builder)
sqlexec.MustFormatSQL(sql, `INSERT INTO %n.%n (Host, User, authentication_string, plugin, user_attributes, Account_locked, Token_issuer) VALUES `, mysql.SystemDB, mysql.UserTable)

Expand Down Expand Up @@ -917,7 +1062,6 @@ func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStm
default:
return ErrPluginIsNotLoaded.GenWithStackByArgs(spec.AuthOpt.AuthPlugin)
}

recordTokenIssuer := tokenIssuer
if len(recordTokenIssuer) > 0 && authPlugin != mysql.AuthTiDBAuthToken {
err := fmt.Errorf("TOKEN_ISSUER is not needed for '%s' user", authPlugin)
Expand All @@ -927,7 +1071,6 @@ func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStm
err := fmt.Errorf("TOKEN_ISSUER is needed for 'tidb_auth_token' user, please use 'alter user' to declare it")
e.ctx.GetSessionVars().StmtCtx.AppendWarning(err)
}

hostName := strings.ToLower(spec.User.Hostname)
sqlexec.MustFormatSQL(sql, `(%?, %?, %?, %?, %?, %?, %?)`, hostName, spec.User.Username, pwd, authPlugin, userAttributes, lockAccount, recordTokenIssuer)
users = append(users, spec.User)
Expand Down Expand Up @@ -992,22 +1135,12 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
}
s.Specs = []*ast.UserSpec{spec}
}

lockAccount := ""
if len(s.PasswordOrLockOptions) > 0 {
// If "ACCOUNT LOCK" or "ACCOUNT UNLOCK" appears many times,
// the last declaration takes effect.
for i := len(s.PasswordOrLockOptions) - 1; i >= 0; i-- {
if s.PasswordOrLockOptions[i].Type == ast.Lock {
lockAccount = "Y"
break
} else if s.PasswordOrLockOptions[i].Type == ast.Unlock {
lockAccount = "N"
break
}
}
plOptions := passwordOrLockOptionsInfo{LockAccount: lockAccount}
plOptions.passwordOrLockOptionsInfoParser(s.PasswordOrLockOptions)
if plOptions.LockAccount != "" {
lockAccount = plOptions.LockAccount
}

privData, err := tlsOption2GlobalPriv(s.AuthTokenOrTLSOptions)
if err != nil {
return err
Expand All @@ -1031,6 +1164,13 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
}
}

restrictedCtx, err := e.getSysSession()
if err != nil {
return err
}
defer e.releaseSysSession(ctx, restrictedCtx)
sqlExecutor := restrictedCtx.(sqlexec.SQLExecutor)
exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
for _, spec := range s.Specs {
user := e.ctx.GetSessionVars().User
if spec.User.CurrentUser || ((user != nil) && (user.Username == spec.User.Username) && (user.AuthHostname == spec.User.Hostname)) {
Expand Down Expand Up @@ -1091,7 +1231,6 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
authTokenOptionHandler = OptionalAuthTokenOptions
}

exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
type alterField struct {
expr string
value string
Expand Down Expand Up @@ -1134,14 +1273,31 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
fields = append(fields, alterField{"account_locked=%?", lockAccount})
}

alterUserPassword, err := readUserAttributes(ctx, sqlExecutor, spec.User.Username, spec.User.Hostname, &plOptions)
if err != nil {
return err
}
AlterPasswordLocking := alterUserFailedLoginJSON(alterUserPassword, lockAccount)

if s.CommentOrAttributeOption != nil {
alterUserPassword.commentIsNull = false
newAttributesStr := ""
if s.CommentOrAttributeOption.Type == ast.UserCommentType {
newAttributesStr = fmt.Sprintf(`{"metadata": {"comment": "%s"}}`, s.CommentOrAttributeOption.Value)
newAttributesStr = fmt.Sprintf(`"metadata": {"comment": "%s"}`, s.CommentOrAttributeOption.Value)
} else {
newAttributesStr = fmt.Sprintf(`"metadata": %s`, s.CommentOrAttributeOption.Value)
}
if AlterPasswordLocking != "" {
newAttributesStr = fmt.Sprintf("{%s,%s}", newAttributesStr, AlterPasswordLocking)
} else {
newAttributesStr = fmt.Sprintf(`{"metadata": %s}`, s.CommentOrAttributeOption.Value)
newAttributesStr = fmt.Sprintf("{%s}", newAttributesStr)
}
fields = append(fields, alterField{"user_attributes=json_merge_patch(coalesce(user_attributes, '{}'), %?)", newAttributesStr})
} else {
if AlterPasswordLocking != "" {
newAttributesStr := fmt.Sprintf("{%s}", AlterPasswordLocking)
fields = append(fields, alterField{"user_attributes=json_merge_patch(coalesce(user_attributes, '{}'), %?)", newAttributesStr})
}
}

switch authTokenOptionHandler {
Expand Down Expand Up @@ -1183,7 +1339,11 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
continue
}
}

err = deleteFailedLogin(ctx, sqlExecutor, spec.User.Username, spec.User.Hostname, alterUserPassword)
if err != nil {
failedUsers = append(failedUsers, spec.User.String())
continue
}
if len(privData) > 0 {
_, _, err := exec.ExecRestrictedSQL(ctx, nil, "INSERT INTO %n.%n (Host, User, Priv) VALUES (%?,%?,%?) ON DUPLICATE KEY UPDATE Priv = values(Priv)", mysql.SystemDB, mysql.GlobalPrivTable, spec.User.Hostname, spec.User.Username, string(hack.String(privData)))
if err != nil {
Expand Down
Loading