Skip to content

Commit 3ba2e14

Browse files
author
shiwenyan
committed
Remove password history feature in iotdb.
1 parent 2e77bf4 commit 3ba2e14

10 files changed

Lines changed: 0 additions & 660 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import java.util.concurrent.Callable;
5353

5454
import static org.apache.iotdb.commons.auth.entity.User.INTERNAL_USER_END_ID;
55-
import static org.apache.iotdb.db.audit.DNAuditLogger.PREFIX_PASSWORD_HISTORY;
5655
import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
5756
import static org.apache.iotdb.db.it.utils.TestUtils.executeNonQuery;
5857
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
@@ -1521,107 +1520,6 @@ public void testStrongPassword() throws SQLException {
15211520
}
15221521
}
15231522

1524-
@Test
1525-
public void testPasswordHistory() {
1526-
try (Connection connection = EnvFactory.getEnv().getConnection();
1527-
Statement statement = connection.createStatement()) {
1528-
testPasswordHistoryEncrypted(statement);
1529-
testPasswordHistoryCreateAndDrop(statement);
1530-
testPasswordHistoryAlter(statement);
1531-
} catch (SQLException e) {
1532-
e.printStackTrace();
1533-
fail(e.getMessage());
1534-
}
1535-
}
1536-
1537-
public void testPasswordHistoryEncrypted(Statement statement) throws SQLException {
1538-
ResultSet resultSet =
1539-
statement.executeQuery("SELECT password,oldPassword from root.__audit.password_history._0");
1540-
assertTrue(resultSet.next());
1541-
assertEquals(
1542-
AuthUtils.encryptPassword(CommonDescriptor.getInstance().getConfig().getAdminPassword()),
1543-
resultSet.getString("root.__audit.password_history._0.password"));
1544-
assertEquals(
1545-
AuthUtils.encryptPassword(CommonDescriptor.getInstance().getConfig().getAdminPassword()),
1546-
resultSet.getString("root.__audit.password_history._0.oldPassword"));
1547-
}
1548-
1549-
public void testPasswordHistoryCreateAndDrop(Statement statement) throws SQLException {
1550-
statement.execute("create user userA 'abcdef123456'");
1551-
1552-
long expectedUserAId = INTERNAL_USER_END_ID + 1;
1553-
try (ResultSet resultSet =
1554-
statement.executeQuery(
1555-
String.format(
1556-
"select last password from %s.`_" + expectedUserAId + "`",
1557-
PREFIX_PASSWORD_HISTORY))) {
1558-
if (!resultSet.next()) {
1559-
fail("Password history not found");
1560-
}
1561-
assertEquals(AuthUtils.encryptPassword("abcdef123456"), resultSet.getString("Value"));
1562-
}
1563-
1564-
try (ResultSet resultSet =
1565-
statement.executeQuery(
1566-
String.format(
1567-
"select last oldPassword from %s.`_" + expectedUserAId + "`",
1568-
PREFIX_PASSWORD_HISTORY))) {
1569-
if (!resultSet.next()) {
1570-
fail("Password history not found");
1571-
}
1572-
assertEquals(AuthUtils.encryptPassword("abcdef123456"), resultSet.getString("Value"));
1573-
}
1574-
1575-
statement.execute("drop user userA");
1576-
1577-
try (ResultSet resultSet =
1578-
statement.executeQuery(
1579-
String.format(
1580-
"select last password from %s.`_" + expectedUserAId + "`",
1581-
PREFIX_PASSWORD_HISTORY))) {
1582-
assertFalse(resultSet.next());
1583-
}
1584-
1585-
try (ResultSet resultSet =
1586-
statement.executeQuery(
1587-
String.format(
1588-
"select last oldPassword from %s.`_" + expectedUserAId + "`",
1589-
PREFIX_PASSWORD_HISTORY))) {
1590-
assertFalse(resultSet.next());
1591-
}
1592-
}
1593-
1594-
public void testPasswordHistoryAlter(Statement statement) throws SQLException {
1595-
statement.execute("create user userA 'abcdef123456'");
1596-
statement.execute("alter user userA set password 'abcdef654321'");
1597-
1598-
long expectedUserAId = INTERNAL_USER_END_ID + 2;
1599-
try (ResultSet resultSet =
1600-
statement.executeQuery(
1601-
String.format(
1602-
"select last password from %s.`_" + expectedUserAId + "`",
1603-
PREFIX_PASSWORD_HISTORY))) {
1604-
if (!resultSet.next()) {
1605-
fail("Password history not found");
1606-
}
1607-
assertEquals(AuthUtils.encryptPassword("abcdef654321"), resultSet.getString("Value"));
1608-
}
1609-
1610-
try (ResultSet resultSet =
1611-
statement.executeQuery(
1612-
String.format(
1613-
"select oldPassword from %s.`_" + expectedUserAId + "` order by time desc limit 1",
1614-
PREFIX_PASSWORD_HISTORY))) {
1615-
if (!resultSet.next()) {
1616-
fail("Password history not found");
1617-
}
1618-
assertEquals(
1619-
AuthUtils.encryptPassword("abcdef123456"),
1620-
resultSet.getString(
1621-
String.format("%s._" + expectedUserAId + ".oldPassword", PREFIX_PASSWORD_HISTORY)));
1622-
}
1623-
}
1624-
16251523
@Test
16261524
public void testChangeBackPassword() {
16271525
try (Connection connection = EnvFactory.getEnv().getConnection();

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/audit/DNAuditLogger.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.function.Supplier;
3333

3434
public class DNAuditLogger extends AbstractAuditLogger {
35-
public static final String PREFIX_PASSWORD_HISTORY = "root.__audit.password_history";
3635

3736
private Coordinator coordinator;
3837

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategyType;
106106
import org.apache.iotdb.db.tools.schema.SRStatementGenerator;
107107
import org.apache.iotdb.db.tools.schema.SchemaRegionSnapshotParser;
108-
import org.apache.iotdb.db.utils.DataNodeAuthUtils;
109108
import org.apache.iotdb.pipe.api.exception.PipeException;
110109
import org.apache.iotdb.rpc.RpcUtils;
111110
import org.apache.iotdb.rpc.TSStatusCode;
@@ -955,14 +954,6 @@ protected TSStatus login() {
955954
return RpcUtils.getStatus(openSessionResp.getCode(), openSessionResp.getMessage());
956955
}
957956

958-
long userId = AuthorityChecker.getUserId(username).orElse(-1L);
959-
Long timeToExpire = DataNodeAuthUtils.checkPasswordExpiration(userId, password, false);
960-
if (timeToExpire != null && timeToExpire <= System.currentTimeMillis()) {
961-
return RpcUtils.getStatus(
962-
TSStatusCode.ILLEGAL_PASSWORD.getStatusCode(),
963-
"Password has expired, please use \"ALTER USER\" to change to a new one");
964-
}
965-
966957
return AuthorityChecker.checkUser(username, password);
967958
}
968959

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/session/SessionManager.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
import org.apache.iotdb.commons.audit.AuditLogFields;
2525
import org.apache.iotdb.commons.audit.AuditLogOperation;
2626
import org.apache.iotdb.commons.audit.UserEntity;
27-
import org.apache.iotdb.commons.conf.CommonDescriptor;
2827
import org.apache.iotdb.commons.conf.IoTDBConstant;
2928
import org.apache.iotdb.commons.service.JMXService;
3029
import org.apache.iotdb.commons.service.ServiceType;
3130
import org.apache.iotdb.commons.service.metric.MetricService;
3231
import org.apache.iotdb.commons.service.metric.enums.Metric;
3332
import org.apache.iotdb.commons.service.metric.enums.Tag;
34-
import org.apache.iotdb.commons.utils.AuthUtils;
3533
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
3634
import org.apache.iotdb.db.audit.DNAuditLogger;
3735
import org.apache.iotdb.db.auth.AuthorityChecker;
@@ -42,7 +40,6 @@
4240
import org.apache.iotdb.db.queryengine.common.SessionInfo;
4341
import org.apache.iotdb.db.queryengine.plan.execution.config.session.PreparedStatementMemoryManager;
4442
import org.apache.iotdb.db.storageengine.dataregion.read.control.QueryResourceManager;
45-
import org.apache.iotdb.db.utils.DataNodeAuthUtils;
4643
import org.apache.iotdb.metrics.utils.MetricLevel;
4744
import org.apache.iotdb.metrics.utils.MetricType;
4845
import org.apache.iotdb.rpc.RpcUtils;
@@ -55,10 +52,7 @@
5552
import org.slf4j.Logger;
5653
import org.slf4j.LoggerFactory;
5754

58-
import java.time.Instant;
59-
import java.time.LocalDateTime;
6055
import java.time.ZoneId;
61-
import java.time.format.DateTimeFormatter;
6256
import java.util.Comparator;
6357
import java.util.List;
6458
import java.util.Map;
@@ -148,16 +142,6 @@ public BasicOpenSessionResp login(
148142

149143
final long userId = AuthorityChecker.getUserId(username).orElse(-1L);
150144

151-
Long timeToExpire =
152-
DataNodeAuthUtils.checkPasswordExpiration(userId, password, useEncryptedPassword);
153-
if (timeToExpire != null && timeToExpire <= System.currentTimeMillis()) {
154-
openSessionResp
155-
.sessionId(-1)
156-
.setCode(TSStatusCode.ILLEGAL_PASSWORD.getStatusCode())
157-
.setMessage("Password has expired, please use \"ALTER USER\" to change to a new one");
158-
return openSessionResp;
159-
}
160-
161145
boolean enableLoginLock = userId != -1;
162146
LoginLockManager loginLockManager = LoginLockManager.getInstance();
163147
if (enableLoginLock && loginLockManager.checkLock(userId, session.getClientAddress())) {
@@ -182,42 +166,6 @@ public BasicOpenSessionResp login(
182166
session.setSqlDialect(sqlDialect);
183167
supplySession(session, userId, username, ZoneId.of(zoneId), clientVersion);
184168
String logInMessage = "Login successfully";
185-
if (timeToExpire != null && timeToExpire != Long.MAX_VALUE) {
186-
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
187-
logInMessage +=
188-
". Your password will expire at "
189-
+ dateFormat.format(
190-
LocalDateTime.ofInstant(
191-
Instant.ofEpochMilli(timeToExpire), ZoneId.systemDefault()));
192-
} else if (timeToExpire == null) {
193-
LOGGER.info(
194-
"No password history for user {}, using the current time to create a new one",
195-
username);
196-
long currentTime = CommonDateTimeUtils.currentTime();
197-
TSStatus tsStatus =
198-
DataNodeAuthUtils.recordPasswordHistory(
199-
userId, password, AuthUtils.encryptPassword(password), currentTime);
200-
if (tsStatus.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
201-
openSessionResp
202-
.sessionId(-1)
203-
.setCode(tsStatus.getCode())
204-
.setMessage(tsStatus.getMessage());
205-
return openSessionResp;
206-
}
207-
timeToExpire =
208-
CommonDateTimeUtils.convertIoTDBTimeToMillis(currentTime)
209-
+ CommonDescriptor.getInstance().getConfig().getPasswordExpirationDays()
210-
* 1000
211-
* 86400;
212-
if (timeToExpire > System.currentTimeMillis()) {
213-
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
214-
logInMessage +=
215-
". Your password will expire at "
216-
+ dateFormat.format(
217-
LocalDateTime.ofInstant(
218-
Instant.ofEpochMilli(timeToExpire), ZoneId.systemDefault()));
219-
}
220-
}
221169
openSessionResp
222170
.sessionId(session.getId())
223171
.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode())

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@
249249
import org.apache.iotdb.db.queryengine.plan.statement.sys.ShowConfigurationStatement;
250250
import org.apache.iotdb.db.queryengine.plan.statement.sys.StartRepairDataStatement;
251251
import org.apache.iotdb.db.queryengine.plan.statement.sys.StopRepairDataStatement;
252-
import org.apache.iotdb.db.utils.DataNodeAuthUtils;
253252
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
254253
import org.apache.iotdb.rpc.TSStatusCode;
255254

@@ -1497,7 +1496,6 @@ private void visitUpdateUser(RelationalAuthorStatement node) {
14971496
throw new SemanticException("User " + node.getUserName() + " not found");
14981497
}
14991498
node.setOldPassword(user.getPassword());
1500-
DataNodeAuthUtils.verifyPasswordReuse(node.getAssociatedUserId(), node.getPassword());
15011499
}
15021500

15031501
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@
227227
import org.apache.iotdb.db.queryengine.plan.statement.sys.quota.SetThrottleQuotaStatement;
228228
import org.apache.iotdb.db.queryengine.plan.statement.sys.quota.ShowSpaceQuotaStatement;
229229
import org.apache.iotdb.db.queryengine.plan.statement.sys.quota.ShowThrottleQuotaStatement;
230-
import org.apache.iotdb.db.utils.DataNodeAuthUtils;
231230
import org.apache.iotdb.rpc.TSStatusCode;
232231

233232
import org.apache.tsfile.exception.NotImplementedException;
@@ -346,8 +345,6 @@ private void visitUpdateUser(AuthorStatement statement) {
346345
throw new SemanticException("User " + statement.getUserName() + " not found");
347346
}
348347
statement.setPassWord(user.getPassword());
349-
DataNodeAuthUtils.verifyPasswordReuse(
350-
statement.getAssociatedUsedId(), statement.getNewPassword());
351348
}
352349

353350
private void visitRenameUser(AuthorStatement statement) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/RelationalAuthorStatement.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@
2222
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
2323
import org.apache.iotdb.commons.schema.table.Audit;
2424
import org.apache.iotdb.commons.schema.table.InformationSchema;
25-
import org.apache.iotdb.commons.utils.AuthUtils;
26-
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
2725
import org.apache.iotdb.db.auth.AuthorityChecker;
2826
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
2927
import org.apache.iotdb.db.queryengine.plan.relational.type.AuthorRType;
30-
import org.apache.iotdb.db.utils.DataNodeAuthUtils;
3128
import org.apache.iotdb.rpc.RpcUtils;
32-
import org.apache.iotdb.rpc.StatementExecutionException;
3329

3430
import com.google.common.collect.ImmutableList;
3531
import org.apache.tsfile.utils.RamUsageEstimator;
@@ -300,53 +296,6 @@ public String toString() {
300296
* @return null if the post-process succeeds, a status otherwise.
301297
*/
302298
public TSStatus onSuccess() {
303-
if (authorType == AuthorRType.CREATE_USER) {
304-
return onCreateUserSuccess();
305-
} else if (authorType == AuthorRType.UPDATE_USER) {
306-
return onUpdateUserSuccess();
307-
} else if (authorType == AuthorRType.DROP_USER) {
308-
return onDropUserSuccess();
309-
}
310-
return null;
311-
}
312-
313-
private TSStatus onCreateUserSuccess() {
314-
associatedUserId = AuthorityChecker.getUserId(userName).orElse(-1L);
315-
// the old password is expected to be encrypted during updates, so we also encrypt it here to
316-
// keep consistency
317-
TSStatus tsStatus =
318-
DataNodeAuthUtils.recordPasswordHistory(
319-
associatedUserId,
320-
password,
321-
AuthUtils.encryptPassword(password),
322-
CommonDateTimeUtils.currentTime());
323-
try {
324-
RpcUtils.verifySuccess(tsStatus);
325-
} catch (StatementExecutionException e) {
326-
return new TSStatus(e.getStatusCode()).setMessage(e.getMessage());
327-
}
328-
return null;
329-
}
330-
331-
private TSStatus onUpdateUserSuccess() {
332-
TSStatus tsStatus =
333-
DataNodeAuthUtils.recordPasswordHistory(
334-
associatedUserId, password, oldPassword, CommonDateTimeUtils.currentTime());
335-
try {
336-
RpcUtils.verifySuccess(tsStatus);
337-
} catch (StatementExecutionException e) {
338-
return new TSStatus(e.getStatusCode()).setMessage(e.getMessage());
339-
}
340-
return null;
341-
}
342-
343-
private TSStatus onDropUserSuccess() {
344-
TSStatus tsStatus = DataNodeAuthUtils.deletePasswordHistory(associatedUserId);
345-
try {
346-
RpcUtils.verifySuccess(tsStatus);
347-
} catch (StatementExecutionException e) {
348-
return new TSStatus(e.getStatusCode()).setMessage(e.getMessage());
349-
}
350299
return null;
351300
}
352301

0 commit comments

Comments
 (0)