Skip to content

Commit 1a08a3c

Browse files
[fix](auth) journal DISCARD OLD PASSWORD as a no-op carrier for pre-feature FEs
DISCARD OLD PASSWORD used to ride OP_SET_PASSWORD with the account's unchanged primary so that an FE binary without the feature could still replay the entry. The primary value did survive that replay, but the password-policy state did not: a pre-feature set-password replay appends the primary to the password history again and refreshes the password creation time. The entry is now an OP_ALTER_USER log whose carrier op is SET_PASSWORD_POLICY with every option UNSET, plus a discard marker (AlterUserOperationLog.discardOldPassword). A pre-feature binary drops the unknown field and replays a policy update that changes nothing (every UNSET branch returns early, no password is journaled), while a binary with the feature reads the marker and drops the secondary password. A new AlterUserOpType name is still not journaled: a pre-feature binary deserializes it as null and fails replay. PrivInfo loses the discardPasswd flag (RETAIN keeps retainPasswd). Auth's retainCurrentPassword parameter is renamed retainCurrent (the name UserManager already uses): master's credential-log checkstyle rule flags any logged identifier ending in Password, and this one is a boolean, not a credential. Tests: DualPasswordTest moves to JUnit 5 like the rest of the tree; testDiscardJournalsAsNoOpPolicyEntry pins the journal shape and its GSON round trip; testDiscardReplayLeavesPasswordPolicyUntouched replays the entry both as a pre-feature binary sees it (marker dropped, the same alterUserInternal path) and as a current one, asserting the history size and the password creation time are unchanged either way, with the old OP_SET_PASSWORD carrier as the contrast that does change them. Signed-off-by: Raghvendra Singh <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 789e270 commit 1a08a3c

5 files changed

Lines changed: 254 additions & 169 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/alter/AlterUserOpType.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public enum AlterUserOpType {
2727
MODIFY_COMMENT,
2828
SET_TLS_REQUIRE,
2929
// MySQL-compatible "DISCARD OLD PASSWORD": evict the retained secondary
30-
// password. NB: NEVER journaled via OP_ALTER_USER — a pre-feature binary
31-
// would fail replay on the unknown enum value. It rides OP_SET_PASSWORD
32-
// instead (PrivInfo.discardPasswd; see Auth.discardOldPasswordInternal),
33-
// which older binaries replay as a harmless same-password set.
30+
// password. NB: this name is NEVER written to the journal — a pre-feature
31+
// binary would deserialize the unknown enum value as null and fail replay.
32+
// The entry is journaled with op = SET_PASSWORD_POLICY (every option
33+
// UNSET, a no-op for such binaries) plus a discard marker; see
34+
// AlterUserOperationLog.discardOldPassword / Auth.discardOldPasswordInternal.
3435
DISCARD_OLD_PASSWORD
3536
}

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/Auth.java‎

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,21 +1037,13 @@ public void setPassword(UserIdentity userIdentity, byte[] password) throws DdlEx
10371037
// MySQL-compatible SET PASSWORD ... RETAIN CURRENT PASSWORD: keep the
10381038
// previous password valid as the secondary password.
10391039
public void setPassword(UserIdentity userIdentity, byte[] password,
1040-
boolean retainCurrentPassword) throws DdlException {
1040+
boolean retainCurrent) throws DdlException {
10411041
setPasswordInternal(userIdentity, password, null, true /* err on non exist */,
1042-
false /* set by resolver */, retainCurrentPassword, false);
1042+
false /* set by resolver */, retainCurrent, false);
10431043
}
10441044

10451045
public void replaySetPassword(PrivInfo info) {
10461046
try {
1047-
if (info.isDiscardPasswd()) {
1048-
// DISCARD OLD PASSWORD rides OP_SET_PASSWORD — see
1049-
// discardOldPasswordInternal for why. The journaled passwd is
1050-
// the account's unchanged primary (for older binaries); here
1051-
// only the discard matters.
1052-
discardOldPasswordInternal(info.getUserIdent(), true);
1053-
return;
1054-
}
10551047
setPasswordInternal(info.getUserIdent(), info.getPasswd(), null, true /* err on non exist */,
10561048
false /* set by resolver */, info.isRetainPasswd(), true);
10571049
} catch (DdlException e) {
@@ -1066,7 +1058,7 @@ public void setPasswordInternal(UserIdentity userIdent, byte[] password, UserIde
10661058
}
10671059

10681060
public void setPasswordInternal(UserIdentity userIdent, byte[] password, UserIdentity domainUserIdent,
1069-
boolean errOnNonExist, boolean setByResolver, boolean retainCurrentPassword,
1061+
boolean errOnNonExist, boolean setByResolver, boolean retainCurrent,
10701062
boolean isReplay) throws DdlException {
10711063
Preconditions.checkArgument(!setByResolver || domainUserIdent != null, setByResolver + ", " + domainUserIdent);
10721064
writeLock();
@@ -1076,7 +1068,7 @@ public void setPasswordInternal(UserIdentity userIdent, byte[] password, UserIde
10761068
ErrorReport.reportDdlException(ErrorCode.ERR_CREDENTIALS_CONTRADICT_TO_HISTORY,
10771069
userIdent.getQualifiedUser(), userIdent.getHost());
10781070
}
1079-
if (retainCurrentPassword) {
1071+
if (retainCurrent) {
10801072
// MySQL-compatible RETAIN CURRENT PASSWORD constraint:
10811073
// "If you specify RETAIN CURRENT PASSWORD for an account
10821074
// that has an empty primary password, the statement
@@ -1095,48 +1087,45 @@ public void setPasswordInternal(UserIdentity userIdent, byte[] password, UserIde
10951087
}
10961088
}
10971089
}
1098-
userManager.setPassword(userIdent, password, errOnNonExist, retainCurrentPassword);
1090+
userManager.setPassword(userIdent, password, errOnNonExist, retainCurrent);
10991091
if (password != null) {
11001092
// save password to password history
11011093
passwdPolicyManager.updatePassword(userIdent, password);
11021094
}
11031095

11041096
if (!isReplay) {
1105-
PrivInfo info = new PrivInfo(userIdent, null, password, null, null, retainCurrentPassword, false);
1097+
PrivInfo info = new PrivInfo(userIdent, null, password, null, null, retainCurrent);
11061098
Env.getCurrentEnv().getEditLog().logSetPassword(info);
11071099
}
11081100
} finally {
11091101
writeUnlock();
11101102
}
11111103
LOG.info("finished to set password for {}. is replay: {}, retain current: {}",
1112-
userIdent, isReplay, retainCurrentPassword);
1104+
userIdent, isReplay, retainCurrent);
11131105
}
11141106

11151107
/**
11161108
* MySQL-compatible "ALTER USER ... DISCARD OLD PASSWORD": drop the
1117-
* retained secondary password.
1109+
* retained secondary password. Not a password change, so the password
1110+
* policy state (history, creation time) is left untouched.
11181111
*
1119-
* <p>Journaled via OP_SET_PASSWORD/PrivInfo with the discard flag and
1120-
* passwd = the account's CURRENT primary password, NOT via a new
1121-
* operation value on OP_ALTER_USER: an FE binary without this feature
1122-
* deserializes an unknown AlterUserOpType enum name as null and fails
1123-
* replay, whereas it replays this entry as a plain set-password to the
1124-
* value the account already holds — a harmless no-op. That keeps the
1125-
* journal readable by pre-feature binaries.
1112+
* <p>Journaled as an OP_ALTER_USER entry whose carrier op is
1113+
* SET_PASSWORD_POLICY with every option UNSET plus a discard marker
1114+
* ({@link AlterUserOperationLog#discardOldPassword}). An FE binary
1115+
* without this feature ignores the marker and replays a policy update
1116+
* that changes nothing, so the journal stays readable by pre-feature
1117+
* binaries with no side effect. A new AlterUserOpType name is not an
1118+
* option there (an unknown enum name deserializes as null and fails
1119+
* replay), and neither is OP_SET_PASSWORD with the unchanged primary (a
1120+
* pre-feature binary's set-password replay appends that primary to the
1121+
* password history and refreshes the password creation time).
11261122
*/
11271123
private void discardOldPasswordInternal(UserIdentity userIdent, boolean isReplay) throws DdlException {
11281124
writeLock();
11291125
try {
1130-
User user = userManager.getUserByUserIdentity(userIdent);
1131-
if (user == null) {
1132-
throw new DdlException("user " + userIdent + " does not exist");
1133-
}
1134-
userManager.discardOldPassword(userIdent, true);
1126+
userManager.discardOldPassword(userIdent, true /* err on non exist */);
11351127
if (!isReplay) {
1136-
byte[] currentPrimary = user.getPassword() == null || user.getPassword().getPassword() == null
1137-
? new byte[0] : user.getPassword().getPassword();
1138-
PrivInfo info = new PrivInfo(userIdent, null, currentPrimary, null, null, false, true);
1139-
Env.getCurrentEnv().getEditLog().logSetPassword(info);
1128+
Env.getCurrentEnv().getEditLog().logAlterUser(AlterUserOperationLog.discardOldPassword(userIdent));
11401129
}
11411130
} finally {
11421131
writeUnlock();
@@ -2008,10 +1997,14 @@ public void alterUser(AlterUserInfo info) throws DdlException {
20081997

20091998
public void replayAlterUser(AlterUserOperationLog log) {
20101999
try {
2011-
// retainCurrentPassword is always false here: the SET_PASSWORD
2000+
// A DISCARD OLD PASSWORD entry carries op = SET_PASSWORD_POLICY
2001+
// (a no-op for pre-feature binaries) plus the discard marker; the
2002+
// marker decides what this binary replays.
2003+
AlterUserOpType opType = log.isDiscardOldPassword() ? AlterUserOpType.DISCARD_OLD_PASSWORD : log.getOp();
2004+
// retainCurrent is always false here: the SET_PASSWORD
20122005
// branch (the only one it applies to) journals via
20132006
// logSetPassword/PrivInfo, which carries the flag itself.
2014-
alterUserInternal(true, log.getOp(), log.getUserIdent(), log.getPassword(), log.getRole(),
2007+
alterUserInternal(true, opType, log.getUserIdent(), log.getPassword(), log.getRole(),
20152008
log.getPasswordOptions(), log.getComment(), false, true);
20162009
} catch (DdlException e) {
20172010
LOG.error("should not happen", e);
@@ -2020,7 +2013,7 @@ public void replayAlterUser(AlterUserOperationLog log) {
20202013

20212014
private void alterUserInternal(boolean ifExists, AlterUserOpType opType, UserIdentity userIdent, byte[] password,
20222015
String role, PasswordOptions passwordOptions, String comment,
2023-
boolean retainCurrentPassword, boolean isReplay) throws DdlException {
2016+
boolean retainCurrent, boolean isReplay) throws DdlException {
20242017
writeLock();
20252018
try {
20262019
if (!doesUserExist(userIdent)) {
@@ -2031,13 +2024,12 @@ private void alterUserInternal(boolean ifExists, AlterUserOpType opType, UserIde
20312024
}
20322025
switch (opType) {
20332026
case SET_PASSWORD:
2034-
setPasswordInternal(userIdent, password, null, false, false, retainCurrentPassword, isReplay);
2027+
setPasswordInternal(userIdent, password, null, false, false, retainCurrent, isReplay);
20352028
break;
20362029
case DISCARD_OLD_PASSWORD:
20372030
// MySQL-compatible "ALTER USER ... DISCARD OLD PASSWORD":
20382031
// evict the retained secondary password early. Journals
2039-
// via OP_SET_PASSWORD (see discardOldPasswordInternal),
2040-
// never via OP_ALTER_USER.
2032+
// its own OP_ALTER_USER entry (see discardOldPasswordInternal).
20412033
discardOldPasswordInternal(userIdent, isReplay);
20422034
break;
20432035
case SET_ROLE:
@@ -2064,7 +2056,7 @@ private void alterUserInternal(boolean ifExists, AlterUserOpType opType, UserIde
20642056
// the edit log is wrote in "setPasswordInternal"
20652057
// For DISCARD_OLD_PASSWORD:
20662058
// the edit log is wrote in "discardOldPasswordInternal"
2067-
// (as OP_SET_PASSWORD, readable by pre-feature binaries)
2059+
// (a no-op carrier for pre-feature binaries)
20682060
AlterUserOperationLog log = new AlterUserOperationLog(opType, userIdent, password, role,
20692061
passwordOptions, comment);
20702062
Env.getCurrentEnv().getEditLog().logAlterUser(log);

‎fe/fe-core/src/main/java/org/apache/doris/persist/AlterUserOperationLog.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public class AlterUserOperationLog implements Writable {
4545
@SerializedName(value = "comment")
4646
private String comment;
4747

48+
// MySQL-compatible "ALTER USER ... DISCARD OLD PASSWORD" marker. Such an
49+
// entry is journaled with op = SET_PASSWORD_POLICY and every option UNSET,
50+
// so an FE binary WITHOUT this feature (which ignores this field) replays
51+
// it as a password-policy update that changes nothing, while a binary with
52+
// the feature drops the retained secondary password. Absent in journals
53+
// written before this feature (GSON default: false). See
54+
// Auth.discardOldPasswordInternal.
55+
@SerializedName(value = "discardOldPasswd")
56+
private boolean discardOldPassword;
57+
4858
public AlterUserOperationLog(AlterUserOpType opType, UserIdentity userIdent, byte[] password,
4959
String role, PasswordOptions passwordOptions, String comment) {
5060
this.op = opType;
@@ -55,10 +65,30 @@ public AlterUserOperationLog(AlterUserOpType opType, UserIdentity userIdent, byt
5565
this.comment = comment;
5666
}
5767

68+
/**
69+
* The journal entry for "ALTER USER ... DISCARD OLD PASSWORD". Its carrier
70+
* op is SET_PASSWORD_POLICY with {@link PasswordOptions#UNSET_OPTION}: on
71+
* a pre-feature binary that replays as a no-op (every UNSET branch of the
72+
* policy update returns early and no password is journaled), whereas an
73+
* unknown AlterUserOpType name would deserialize as null and fail replay,
74+
* and an OP_SET_PASSWORD carrier would append the primary to the password
75+
* history and refresh the password creation time.
76+
*/
77+
public static AlterUserOperationLog discardOldPassword(UserIdentity userIdent) {
78+
AlterUserOperationLog log = new AlterUserOperationLog(AlterUserOpType.SET_PASSWORD_POLICY, userIdent,
79+
null, null, PasswordOptions.UNSET_OPTION, null);
80+
log.discardOldPassword = true;
81+
return log;
82+
}
83+
5884
public AlterUserOpType getOp() {
5985
return op;
6086
}
6187

88+
public boolean isDiscardOldPassword() {
89+
return discardOldPassword;
90+
}
91+
6292
public UserIdentity getUserIdent() {
6393
return userIdent;
6494
}

‎fe/fe-core/src/main/java/org/apache/doris/persist/PrivInfo.java‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ public class PrivInfo implements Writable {
7171
@SerializedName(value = "retainPasswd")
7272
private boolean retainPasswd;
7373

74-
// MySQL-compatible "DISCARD OLD PASSWORD": drop the retained secondary
75-
// password. Rides OP_SET_PASSWORD (with passwd = the account's current
76-
// primary) instead of a new operation type, so an FE binary WITHOUT this
77-
// feature replays the entry as a plain set-password to the value the
78-
// account already holds — a harmless no-op — rather than failing on an
79-
// unknown operation. See Auth.discardOldPasswordInternal.
80-
@SerializedName(value = "discardPasswd")
81-
private boolean discardPasswd;
82-
8374
private PrivInfo() {
8475

8576
}
@@ -90,13 +81,12 @@ public PrivInfo(UserIdentity userIdent, PrivBitSet privs, byte[] passwd, String
9081
this(userIdent, privs, passwd, role, passwordOptions, null, null);
9182
}
9283

93-
// For set password with the MySQL-compatible dual password clauses
94-
// (RETAIN CURRENT PASSWORD on a change; DISCARD OLD PASSWORD standalone)
84+
// For set password with the MySQL-compatible RETAIN CURRENT PASSWORD
85+
// clause (DISCARD OLD PASSWORD journals via AlterUserOperationLog instead)
9586
public PrivInfo(UserIdentity userIdent, PrivBitSet privs, byte[] passwd, String role,
96-
PasswordOptions passwordOptions, boolean retainPasswd, boolean discardPasswd) {
87+
PasswordOptions passwordOptions, boolean retainPasswd) {
9788
this(userIdent, privs, passwd, role, passwordOptions, null, null);
9889
this.retainPasswd = retainPasswd;
99-
this.discardPasswd = discardPasswd;
10090
}
10191

10292
public PrivInfo(UserIdentity userIdent, PrivBitSet privs, byte[] passwd, String role,
@@ -187,10 +177,6 @@ public boolean isRetainPasswd() {
187177
return retainPasswd;
188178
}
189179

190-
public boolean isDiscardPasswd() {
191-
return discardPasswd;
192-
}
193-
194180
public String getRole() {
195181
return role;
196182
}

0 commit comments

Comments
 (0)