You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2026/01/05 02:54:22 UTC
(iotdb) branch master updated: Pipe: Enabled config audit logger & Fixed some checks of config privilege & keep the tree model show pipes aligned with table model's & Fixed the bug that password with "-" prefix cannot be directly entered in Cli & Fixed some pipe ITs & Added the missing source privilege check for PipeAlterEncodingCompressorPlan (#16957)
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new ecd7d92f8aa Pipe: Enabled config audit logger & Fixed some checks of config privilege & keep the tree model show pipes aligned with table model's & Fixed the bug that password with "-" prefix cannot be directly entered in Cli & Fixed some pipe ITs & Added the missing source privilege check for PipeAlterEncodingCompressorPlan (#16957)
ecd7d92f8aa is described below
commit ecd7d92f8aaba8c6544b2992ce970e9f14985597
Author: Caideyipi <87...@users.noreply.github.com>
AuthorDate: Mon Jan 5 10:54:16 2026 +0800
Pipe: Enabled config audit logger & Fixed some checks of config privilege & keep the tree model show pipes aligned with table model's & Fixed the bug that password with "-" prefix cannot be directly entered in Cli & Fixed some pipe ITs & Added the missing source privilege check for PipeAlterEncodingCompressorPlan (#16957)
* fix
* permission-change
* user_role
* part
* fix
* f
* fix
* fix
* fix
* no-excep
* pw-args
* fix
* test
* partial
* hdx
* Update IoTDBConfigNodeReceiver.java
* part
* fix
* refactor
* fix
* IT-fix
* fix-SQL
* clean
* fix
* add-test
* fix
---
.../treemodel/auto/basic/IoTDBPipeLifeCycleIT.java | 10 +-
.../treemodel/manual/IoTDBPipePermissionIT.java | 15 +-
.../java/org/apache/iotdb/cli/AbstractCli.java | 4 +-
.../iotdb/confignode/manager/ConfigManager.java | 17 -
.../confignode/manager/PermissionManager.java | 6 -
.../receiver/protocol/IoTDBConfigNodeReceiver.java | 478 +++++++++++++--------
.../pipe/source/IoTDBConfigRegionSource.java | 5 +-
.../PipeConfigTablePrivilegeParseVisitor.java | 287 ++++++-------
.../PipeConfigTreePrivilegeParseVisitor.java | 430 ++++++++++++------
.../PipeConfigTreePrivilegeParseVisitorTest.java | 101 ++++-
.../protocol/thrift/IoTDBDataNodeReceiver.java | 4 +-
.../execution/config/TableConfigTaskVisitor.java | 7 +-
.../relational/security/AccessControlImpl.java | 130 ++++--
.../relational/security/ITableAuthCheckerImpl.java | 68 ++-
.../security/TreeAccessCheckVisitor.java | 180 ++++----
.../iotdb/commons/audit/AbstractAuditLogger.java | 16 +-
.../iotdb/commons/auth/entity/PrivilegeUnion.java | 2 +-
.../commons/pipe/receiver/IoTDBFileReceiver.java | 11 +-
.../iotdb/commons/pipe/source/IoTDBSource.java | 2 +
19 files changed, 1058 insertions(+), 715 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/auto/basic/IoTDBPipeLifeCycleIT.java b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/auto/basic/IoTDBPipeLifeCycleIT.java
index b4519ca9500..226c9344e7a 100644
--- a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/auto/basic/IoTDBPipeLifeCycleIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/auto/basic/IoTDBPipeLifeCycleIT.java
@@ -833,12 +833,8 @@ public class IoTDBPipeLifeCycleIT extends AbstractPipeDualTreeModelAutoIT {
"803: No permissions for this operation, please add privilege SYSTEM",
"test",
"test123123456");
- assertTestFail(
- senderEnv,
- "show pipes",
- "803: No permissions for this operation, please add privilege SYSTEM",
- "test",
- "test123123456");
+ // Will not throw exception
+ executeQueryWithRetry(senderEnv, "show pipes", "test", "test123123456");
assertNonQueryTestFail(
senderEnv,
"start pipe testPipe",
@@ -866,7 +862,7 @@ public class IoTDBPipeLifeCycleIT extends AbstractPipeDualTreeModelAutoIT {
"test123123456");
assertTestFail(
senderEnv,
- "show pipe plugins",
+ "show pipePlugins",
"803: No permissions for this operation, please add privilege SYSTEM",
"test",
"test123123456");
diff --git a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipePermissionIT.java b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipePermissionIT.java
index 1bb6acb35f2..b0f2feffe42 100644
--- a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipePermissionIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipePermissionIT.java
@@ -22,7 +22,6 @@ package org.apache.iotdb.pipe.it.dual.treemodel.manual;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
-import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.it.utils.TestUtils;
import org.apache.iotdb.it.env.MultiEnvFactory;
@@ -39,6 +38,7 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import java.sql.Connection;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
@@ -360,8 +360,9 @@ public class IoTDBPipePermissionIT extends AbstractPipeDualTreeModelManualIT {
TestUtils.executeNonQuery(senderEnv, "create database root.test1");
// Shall be transferred
+ // The root.test may or may not be transferred due to delayed start of the config source
TestUtils.assertDataEventuallyOnEnv(
- receiverEnv, "count databases root.tes*", "count,", Collections.singleton("1,"));
+ receiverEnv, "count databases root.test1", "count,", Collections.singleton("1,"));
// Alter pipe, throw exception if no privileges
try (final Connection connection = senderEnv.getConnection();
@@ -417,10 +418,12 @@ public class IoTDBPipePermissionIT extends AbstractPipeDualTreeModelManualIT {
TestUtils.executeNonQuery(senderEnv, "revoke SYSTEM on root.** from user thulab");
// A user shall only see its own pipe
- try (final SyncConfigNodeIServiceClient client =
- (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
- Assert.assertEquals(
- 1, client.showPipe(new TShowPipeReq().setUserName("thulab")).pipeInfoList.size());
+ try (final Connection connection = senderEnv.getConnection("thulab", "passwD@123456");
+ final Statement statement = connection.createStatement()) {
+ // Will not throw any exception
+ final ResultSet resultSet = statement.executeQuery("show pipes");
+ Assert.assertTrue(resultSet.next());
+ Assert.assertFalse(resultSet.next());
} catch (Exception e) {
fail(e.getMessage());
}
diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
index 17587cf8811..8fd0a179063 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
@@ -321,9 +321,7 @@ public abstract class AbstractCli {
}
}
if (index >= 0) {
- if (index + 1 >= args.length
- || args[index + 1].startsWith("-")
- || (keywordSet.contains(args[index + 1]))) {
+ if (index + 1 >= args.length || keywordSet.contains(args[index + 1])) {
return ArrayUtils.remove(args, index);
}
}
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index 2cd39798613..ed9210c9ff1 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -1353,23 +1353,6 @@ public class ConfigManager implements IManager {
}
}
- public TPermissionInfoResp checkUserPrivilegeGrantOpt(String username, PrivilegeUnion union) {
- TSStatus status = confirmLeader();
- TPermissionInfoResp resp = new TPermissionInfoResp();
- if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
- try {
- resp = permissionManager.checkUserPrivilegeGrantOpt(username, union);
- } catch (AuthException e) {
- status.setCode(e.getCode().getStatusCode()).setMessage(e.getMessage());
- resp.setStatus(status);
- return resp;
- }
- } else {
- resp.setStatus(status);
- }
- return resp;
- }
-
public TPermissionInfoResp checkRoleOfUser(String username, String rolename) {
TSStatus status = confirmLeader();
TPermissionInfoResp resp = new TPermissionInfoResp();
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
index f7ee6069e87..06be2818593 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
@@ -134,12 +134,6 @@ public class PermissionManager {
return authorInfo.generateRawAuthorizedPTree(userName, type);
}
- public TPermissionInfoResp checkUserPrivilegeGrantOpt(String username, PrivilegeUnion union)
- throws AuthException {
- union.setGrantOption(true);
- return authorInfo.checkUserPrivileges(username, union);
- }
-
public TPermissionInfoResp checkRoleOfUser(String username, String rolename)
throws AuthException {
return authorInfo.checkRoleOfUser(username, rolename);
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/receiver/protocol/IoTDBConfigNodeReceiver.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/receiver/protocol/IoTDBConfigNodeReceiver.java
index daf91c51c4c..215e5ff20c0 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/receiver/protocol/IoTDBConfigNodeReceiver.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/receiver/protocol/IoTDBConfigNodeReceiver.java
@@ -20,6 +20,8 @@
package org.apache.iotdb.confignode.manager.pipe.receiver.protocol;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.audit.AuditLogOperation;
+import org.apache.iotdb.commons.audit.IAuditEntity;
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
import org.apache.iotdb.commons.conf.CommonDescriptor;
@@ -46,6 +48,7 @@ import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
import org.apache.iotdb.commons.schema.ttl.TTLCache;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.StatusUtils;
+import org.apache.iotdb.confignode.audit.CNAuditLogger;
import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
@@ -80,8 +83,10 @@ import org.apache.iotdb.confignode.consensus.request.write.table.view.RenameView
import org.apache.iotdb.confignode.consensus.request.write.table.view.SetViewCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.view.SetViewPropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
+import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.ExtendSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.trigger.DeleteTriggerInTablePlan;
+import org.apache.iotdb.confignode.consensus.request.write.trigger.UpdateTriggerStateInTablePlan;
import org.apache.iotdb.confignode.manager.ConfigManager;
import org.apache.iotdb.confignode.manager.pipe.event.PipeConfigRegionSnapshotEvent;
import org.apache.iotdb.confignode.manager.pipe.metric.receiver.PipeConfigNodeReceiverMetrics;
@@ -135,6 +140,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -143,6 +149,10 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.apache.iotdb.confignode.manager.pipe.source.PipeConfigTreePrivilegeParseVisitor.checkGlobalOrAnyStatus;
+import static org.apache.iotdb.confignode.manager.pipe.source.PipeConfigTreePrivilegeParseVisitor.checkGlobalStatus;
+import static org.apache.iotdb.confignode.manager.pipe.source.PipeConfigTreePrivilegeParseVisitor.checkPathsStatus;
+
public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBConfigNodeReceiver.class);
@@ -157,6 +167,7 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
new PipeConfigPhysicalPlanExceptionVisitor();
private final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ private final CNAuditLogger auditLogger = configManager.getAuditLogger();
@Override
public TPipeTransferResp receive(final TPipeTransferReq req) {
@@ -184,6 +195,7 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
resp =
handleTransferHandshakeV2(
PipeTransferConfigNodeHandshakeV2Req.fromTPipeTransferReq(req));
+ userEntity.setAuditLogOperation(AuditLogOperation.DDL);
PipeConfigNodeReceiverMetrics.getInstance()
.recordHandshakeConfigNodeV2Timer(System.nanoTime() - startTime);
return resp;
@@ -290,63 +302,64 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
return status;
}
+ final String database;
+ final String templateName;
+ final String triggerName;
+ final String entityName;
switch (plan.getType()) {
case CreateDatabase:
- return PathUtils.isTableModelDatabase(((DatabaseSchemaPlan) plan).getSchema().getName())
- ? configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((DatabaseSchemaPlan) plan).getSchema().getName(), PrivilegeType.CREATE))
- .getStatus()
- : configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_DATABASE))
- .getStatus();
+ database = ((DatabaseSchemaPlan) plan).getSchema().getName();
+ if (PathUtils.isTableModelDatabase(database)) {
+ status = checkDatabaseStatus(userEntity, PrivilegeType.CREATE, database);
+ return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ ? status
+ : checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, database, true);
+ }
+ return checkGlobalStatus(userEntity, PrivilegeType.MANAGE_DATABASE, database, true);
case AlterDatabase:
- return PathUtils.isTableModelDatabase(((DatabaseSchemaPlan) plan).getSchema().getName())
- ? configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((DatabaseSchemaPlan) plan).getSchema().getName(), PrivilegeType.ALTER))
- .getStatus()
- : configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_DATABASE))
- .getStatus();
+ database = ((DatabaseSchemaPlan) plan).getSchema().getName();
+ if (PathUtils.isTableModelDatabase(database)) {
+ status = checkDatabaseStatus(userEntity, PrivilegeType.ALTER, database);
+ return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ ? status
+ : checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, database, true);
+ }
+ return checkGlobalStatus(userEntity, PrivilegeType.MANAGE_DATABASE, database, true);
case DeleteDatabase:
- return PathUtils.isTableModelDatabase(((DeleteDatabasePlan) plan).getName())
- ? configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(((DeleteDatabasePlan) plan).getName(), PrivilegeType.DROP))
- .getStatus()
- : configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_DATABASE))
- .getStatus();
+ database = ((DeleteDatabasePlan) plan).getName();
+ if (PathUtils.isTableModelDatabase(database)) {
+ status = checkDatabaseStatus(userEntity, PrivilegeType.DELETE, database);
+ return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ ? status
+ : checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, database, true);
+ }
+ return checkGlobalStatus(userEntity, PrivilegeType.MANAGE_DATABASE, database, true);
case ExtendSchemaTemplate:
- return configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.EXTEND_TEMPLATE))
- .getStatus();
+ return checkGlobalStatus(
+ userEntity,
+ PrivilegeType.EXTEND_TEMPLATE,
+ ((ExtendSchemaTemplatePlan) plan).getTemplateExtendInfo().getTemplateName(),
+ true);
case CreateSchemaTemplate:
+ templateName = ((CreateSchemaTemplatePlan) plan).getTemplate().getName();
+ return checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, templateName, true);
case CommitSetSchemaTemplate:
+ templateName = ((CommitSetSchemaTemplatePlan) plan).getName();
+ return checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, templateName, true);
case PipeUnsetTemplate:
- return CommonDescriptor.getInstance().getConfig().getDefaultAdminName().equals(username)
- ? StatusUtils.OK
- : new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
- .setMessage("Only the admin user can perform this operation");
+ templateName = ((PipeUnsetSchemaTemplatePlan) plan).getName();
+ return checkGlobalStatus(userEntity, PrivilegeType.SYSTEM, templateName, true);
case PipeDeleteTimeSeries:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- new ArrayList<>(
- PathPatternTree.deserialize(
- ((PipeDeleteTimeSeriesPlan) plan).getPatternTreeBytes())
- .getAllPathPatterns()),
- PrivilegeType.WRITE_SCHEMA))
- .getStatus();
+ return checkPathsStatus(
+ userEntity,
+ PrivilegeType.WRITE_SCHEMA,
+ new ArrayList<>(
+ PathPatternTree.deserialize(((PipeDeleteTimeSeriesPlan) plan).getPatternTreeBytes())
+ .getAllPathPatterns()),
+ true);
case PipeAlterEncodingCompressor:
- // Judge here in the future
+ // The audit check will only filter but not block the plan
+ // Hence we do not write any audit log here
if (configManager
.checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.AUDIT))
.getStatus()
@@ -364,81 +377,79 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
if (((PipeAlterEncodingCompressorPlan) plan).isMayAlterAudit()) {
pathPatternTree.appendPathPattern(Audit.TREE_MODEL_AUDIT_DATABASE_PATH_PATTERN, true);
}
- ((PipeAlterEncodingCompressorPlan) plan)
- .setPatternTreeBytes(
- PathPatternTreeUtils.intersectWithFullPathPrefixTree(
- PathPatternTree.deserialize(
- ((PipeAlterEncodingCompressorPlan) plan).getPatternTreeBytes()),
- pathPatternTree)
- .serialize());
+ final String auditObject = pathPatternTree.getAllPathPatterns().toString();
+ final PathPatternTree tree =
+ PathPatternTreeUtils.intersectWithFullPathPrefixTree(
+ PathPatternTree.deserialize(
+ ((PipeAlterEncodingCompressorPlan) plan).getPatternTreeBytes()),
+ pathPatternTree);
+ ((PipeAlterEncodingCompressorPlan) plan).setPatternTreeBytes(tree.serialize());
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity
+ .setPrivilegeType(PrivilegeType.WRITE_SCHEMA)
+ .setResult(!tree.isEmpty()),
+ () -> auditObject);
return StatusUtils.OK;
} else {
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- new ArrayList<>(
- PathPatternTree.deserialize(
- ((PipeAlterEncodingCompressorPlan) plan).getPatternTreeBytes())
- .getAllPathPatterns()),
- PrivilegeType.WRITE_SCHEMA))
- .getStatus();
+ return checkPathsStatus(
+ userEntity,
+ PrivilegeType.WRITE_SCHEMA,
+ new ArrayList<>(
+ PathPatternTree.deserialize(
+ ((PipeAlterEncodingCompressorPlan) plan).getPatternTreeBytes())
+ .getAllPathPatterns()),
+ true);
}
case PipeDeleteLogicalView:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- new ArrayList<>(
- PathPatternTree.deserialize(
- ((PipeDeleteLogicalViewPlan) plan).getPatternTreeBytes())
- .getAllPathPatterns()),
- PrivilegeType.WRITE_SCHEMA))
- .getStatus();
+ return checkPathsStatus(
+ userEntity,
+ PrivilegeType.WRITE_SCHEMA,
+ new ArrayList<>(
+ PathPatternTree.deserialize(
+ ((PipeDeleteLogicalViewPlan) plan).getPatternTreeBytes())
+ .getAllPathPatterns()),
+ true);
case PipeDeactivateTemplate:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- new ArrayList<>(
- ((PipeDeactivateTemplatePlan) plan).getTemplateSetInfo().keySet()),
- PrivilegeType.WRITE_SCHEMA))
- .getStatus();
+ return checkPathsStatus(
+ userEntity,
+ PrivilegeType.WRITE_SCHEMA,
+ new ArrayList<>(((PipeDeactivateTemplatePlan) plan).getTemplateSetInfo().keySet()),
+ true);
case SetTTL:
- return Objects.equals(
- configManager
- .getTTLManager()
- .getAllTTL()
- .get(
- String.join(
- String.valueOf(IoTDBConstant.PATH_SEPARATOR),
- ((SetTTLPlan) plan).getPathPattern())),
- ((SetTTLPlan) plan).getTTL())
- ? StatusUtils.OK
- : configManager
- .checkUserPrivileges(
- username,
- ((SetTTLPlan) plan).isDataBase()
- ? new PrivilegeUnion(PrivilegeType.MANAGE_DATABASE)
- : new PrivilegeUnion(
- Collections.singletonList(
- new PartialPath(((SetTTLPlan) plan).getPathPattern())),
- PrivilegeType.WRITE_SCHEMA))
- .getStatus();
+ if (Objects.equals(
+ configManager
+ .getTTLManager()
+ .getAllTTL()
+ .get(
+ String.join(
+ String.valueOf(IoTDBConstant.PATH_SEPARATOR),
+ ((SetTTLPlan) plan).getPathPattern())),
+ ((SetTTLPlan) plan).getTTL())) {
+ return StatusUtils.OK;
+ }
+ final String[] paths = ((SetTTLPlan) plan).getPathPattern();
+ return ((SetTTLPlan) plan).isDataBase()
+ ? checkGlobalStatus(
+ userEntity, PrivilegeType.MANAGE_DATABASE, Arrays.toString(paths), true)
+ : checkPathsStatus(
+ userEntity,
+ PrivilegeType.WRITE_SCHEMA,
+ Collections.singletonList(new PartialPath(paths)),
+ true);
case UpdateTriggerStateInTable:
+ triggerName = ((UpdateTriggerStateInTablePlan) plan).getTriggerName();
+ return checkGlobalStatus(userEntity, PrivilegeType.USE_TRIGGER, triggerName, true);
case DeleteTriggerInTable:
- return configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.USE_TRIGGER))
- .getStatus();
+ triggerName = ((DeleteTriggerInTablePlan) plan).getTriggerName();
+ return checkGlobalStatus(userEntity, PrivilegeType.USE_TRIGGER, triggerName, true);
case PipeCreateTableOrView:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((PipeCreateTableOrViewPlan) plan).getDatabase(),
- ((PipeCreateTableOrViewPlan) plan).getTable().getTableName(),
- PrivilegeType.CREATE))
- .getStatus();
+ return checkTableStatus(
+ userEntity,
+ PrivilegeType.CREATE,
+ ((PipeCreateTableOrViewPlan) plan).getDatabase(),
+ ((PipeCreateTableOrViewPlan) plan).getTable().getTableName());
case AddTableColumn:
case AddViewColumn:
case SetTableProperties:
@@ -452,75 +463,90 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
case RenameViewColumn:
case RenameTable:
case RenameView:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((AbstractTablePlan) plan).getDatabase(),
- ((AbstractTablePlan) plan).getTableName(),
- PrivilegeType.ALTER))
- .getStatus();
+ return checkTableStatus(
+ userEntity,
+ PrivilegeType.ALTER,
+ ((AbstractTablePlan) plan).getDatabase(),
+ ((AbstractTablePlan) plan).getTableName());
case CommitDeleteTable:
case CommitDeleteView:
- return configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((CommitDeleteTablePlan) plan).getDatabase(),
- ((CommitDeleteTablePlan) plan).getTableName(),
- PrivilegeType.DROP))
- .getStatus();
+ return checkTableStatus(
+ userEntity,
+ PrivilegeType.DELETE,
+ ((CommitDeleteTablePlan) plan).getDatabase(),
+ ((CommitDeleteTablePlan) plan).getTableName());
case GrantRole:
case GrantUser:
case RevokeUser:
case RevokeRole:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.GrantUser
+ || plan.getType() == ConfigPhysicalPlanType.RevokeUser
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
+ status = checkGlobalStatus(userEntity, PrivilegeType.SECURITY, entityName, false);
+ if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ return status;
+ }
for (final int permission : ((AuthorTreePlan) plan).getPermissions()) {
status =
- configManager
- .checkUserPrivilegeGrantOpt(
- username,
- PrivilegeType.values()[permission].isPathPrivilege()
- ? new PrivilegeUnion(
- ((AuthorTreePlan) plan).getNodeNameList(),
- PrivilegeType.values()[permission],
- true)
- : new PrivilegeUnion(PrivilegeType.values()[permission], true))
- .getStatus();
+ PrivilegeType.values()[permission].isPathPrivilege()
+ ? checkPathsStatus(
+ userEntity,
+ PrivilegeType.values()[permission],
+ ((AuthorTreePlan) plan).getNodeNameList(),
+ false,
+ entityName)
+ : checkGlobalStatus(
+ userEntity, PrivilegeType.values()[permission], entityName, false, true);
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case RGrantUserAny:
case RGrantRoleAny:
case RRevokeUserAny:
case RRevokeRoleAny:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.RGrantUserAny
+ || plan.getType() == ConfigPhysicalPlanType.RRevokeUserAny
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
for (final int permission : ((AuthorRelationalPlan) plan).getPermissions()) {
status =
- configManager
- .checkUserPrivileges(
- username, new PrivilegeUnion(PrivilegeType.values()[permission], true, true))
- .getStatus();
+ checkGlobalOrAnyStatus(
+ userEntity, PrivilegeType.values()[permission], entityName, false, true, true);
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case RGrantUserAll:
case RGrantRoleAll:
case RRevokeUserAll:
case RRevokeRoleAll:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.RGrantUserAll
+ || plan.getType() == ConfigPhysicalPlanType.RRevokeUserAll
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
for (PrivilegeType privilegeType : PrivilegeType.values()) {
if (privilegeType.isRelationalPrivilege()) {
status =
- configManager
- .checkUserPrivileges(username, new PrivilegeUnion(privilegeType, true, true))
- .getStatus();
+ checkGlobalOrAnyStatus(userEntity, privilegeType, entityName, false, true, true);
} else if (privilegeType.forRelationalSys()) {
- status =
- configManager
- .checkUserPrivileges(username, new PrivilegeUnion(privilegeType, true))
- .getStatus();
+ status = checkGlobalStatus(userEntity, privilegeType, entityName, false, true);
} else {
continue;
}
@@ -528,70 +554,102 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case RGrantUserDBPriv:
case RGrantRoleDBPriv:
case RRevokeUserDBPriv:
case RRevokeRoleDBPriv:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.RGrantUserDBPriv
+ || plan.getType() == ConfigPhysicalPlanType.RRevokeUserDBPriv
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
for (final int permission : ((AuthorRelationalPlan) plan).getPermissions()) {
status =
- configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((AuthorRelationalPlan) plan).getDatabaseName(),
- PrivilegeType.values()[permission],
- true))
- .getStatus();
+ checkDatabaseStatus(
+ userEntity,
+ PrivilegeType.values()[permission],
+ ((AuthorRelationalPlan) plan).getDatabaseName(),
+ true);
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case RGrantUserTBPriv:
case RGrantRoleTBPriv:
case RRevokeUserTBPriv:
case RRevokeRoleTBPriv:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.RGrantUserTBPriv
+ || plan.getType() == ConfigPhysicalPlanType.RRevokeUserTBPriv
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
for (final int permission : ((AuthorRelationalPlan) plan).getPermissions()) {
status =
- configManager
- .checkUserPrivileges(
- username,
- new PrivilegeUnion(
- ((AuthorRelationalPlan) plan).getDatabaseName(),
- ((AuthorRelationalPlan) plan).getTableName(),
- PrivilegeType.values()[permission],
- true))
- .getStatus();
+ checkTableStatus(
+ userEntity,
+ PrivilegeType.values()[permission],
+ ((AuthorRelationalPlan) plan).getDatabaseName(),
+ ((AuthorRelationalPlan) plan).getTableName(),
+ false,
+ true);
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case RGrantUserSysPri:
case RGrantRoleSysPri:
case RRevokeUserSysPri:
case RRevokeRoleSysPri:
+ entityName =
+ plan.getType() == ConfigPhysicalPlanType.RGrantUserSysPri
+ || plan.getType() == ConfigPhysicalPlanType.RRevokeUserSysPri
+ ? ((AuthorPlan) plan).getUserName()
+ : ((AuthorPlan) plan).getRoleName();
for (final int permission : ((AuthorRelationalPlan) plan).getPermissions()) {
status =
- configManager
- .checkUserPrivileges(
- username, new PrivilegeUnion(PrivilegeType.values()[permission], true))
- .getStatus();
+ checkGlobalStatus(
+ userEntity, PrivilegeType.values()[permission], entityName, false, true);
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
}
}
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ () -> entityName);
return StatusUtils.OK;
case UpdateUser:
case UpdateUserV2:
case RUpdateUser:
case RUpdateUserV2:
- return ((AuthorPlan) plan).getUserName().equals(username)
- ? StatusUtils.OK
- : configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_USER))
- .getStatus();
+ if (((AuthorPlan) plan).getUserName().equals(username)) {
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(null).setResult(true), () -> username);
+ return StatusUtils.OK;
+ }
+ return checkGlobalStatus(
+ userEntity, PrivilegeType.MANAGE_USER, ((AuthorPlan) plan).getUserName(), true);
case CreateUser:
case RCreateUser:
case CreateUserWithRawPassword:
@@ -599,9 +657,8 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
case DropUserV2:
case RDropUser:
case RDropUserV2:
- return configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_USER))
- .getStatus();
+ return checkGlobalStatus(
+ userEntity, PrivilegeType.MANAGE_USER, ((AuthorPlan) plan).getUserName(), true);
case CreateRole:
case RCreateRole:
case DropRole:
@@ -610,14 +667,71 @@ public class IoTDBConfigNodeReceiver extends IoTDBFileReceiver {
case RGrantUserRole:
case RevokeRoleFromUser:
case RRevokeUserRole:
- return configManager
- .checkUserPrivileges(username, new PrivilegeUnion(PrivilegeType.MANAGE_ROLE))
- .getStatus();
+ return checkGlobalStatus(
+ userEntity, PrivilegeType.MANAGE_ROLE, ((AuthorPlan) plan).getRoleName(), true);
default:
return StatusUtils.OK;
}
}
+ private TSStatus checkDatabaseStatus(
+ final IAuditEntity userEntity, final PrivilegeType privilegeType, final String database) {
+ return checkDatabaseStatus(userEntity, privilegeType, database, false);
+ }
+
+ private TSStatus checkDatabaseStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String database,
+ final boolean grantOption) {
+ final TSStatus result =
+ configManager
+ .getPermissionManager()
+ .checkUserPrivileges(
+ userEntity.getUsername(), new PrivilegeUnion(database, privilegeType, grantOption))
+ .getStatus();
+ if (result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ auditLogger.recordObjectAuthenticationAuditLog(
+ userEntity
+ .setPrivilegeType(privilegeType)
+ .setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+ () -> database);
+ }
+ return result;
+ }
+
+ private TSStatus checkTableStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String database,
+ final String tableName) {
+ return checkTableStatus(userEntity, privilegeType, database, tableName, true, false);
+ }
+
+ private TSStatus checkTableStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String database,
+ final String tableName,
+ final boolean isLastCheck,
+ final boolean grantOption) {
+ final TSStatus result =
+ configManager
+ .getPermissionManager()
+ .checkUserPrivileges(
+ userEntity.getUsername(),
+ new PrivilegeUnion(database, tableName, privilegeType, grantOption))
+ .getStatus();
+ if (result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode() || isLastCheck) {
+ auditLogger.recordObjectAuthenticationAuditLog(
+ userEntity
+ .setPrivilegeType(privilegeType)
+ .setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+ () -> tableName);
+ }
+ return result;
+ }
+
private TSStatus executePlan(final ConfigPhysicalPlan plan) throws ConsensusException {
final String queryId = generatePseudoQueryId();
switch (plan.getType()) {
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/IoTDBConfigRegionSource.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/IoTDBConfigRegionSource.java
index 86a10d16f1b..60512887703 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/IoTDBConfigRegionSource.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/IoTDBConfigRegionSource.java
@@ -246,7 +246,8 @@ public class IoTDBConfigRegionSource extends IoTDBNonDataRegionSource {
((PipeConfigRegionWritePlanEvent) event).getConfigPhysicalPlan();
final Boolean isTableDatabasePlan = isTableDatabasePlan(plan);
if (!Boolean.TRUE.equals(isTableDatabasePlan)) {
- final Optional<ConfigPhysicalPlan> result = treePrivilegeParseVisitor.process(plan, userName);
+ final Optional<ConfigPhysicalPlan> result =
+ treePrivilegeParseVisitor.process(plan, userEntity);
if (result.isPresent()) {
return Optional.of(
new PipeConfigRegionWritePlanEvent(result.get(), event.isGeneratedByPipe()));
@@ -254,7 +255,7 @@ public class IoTDBConfigRegionSource extends IoTDBNonDataRegionSource {
}
if (!Boolean.FALSE.equals(isTableDatabasePlan)) {
final Optional<ConfigPhysicalPlan> result =
- TABLE_PRIVILEGE_PARSE_VISITOR.process(plan, userName);
+ TABLE_PRIVILEGE_PARSE_VISITOR.process(plan, userEntity);
if (result.isPresent()) {
return Optional.of(
new PipeConfigRegionWritePlanEvent(result.get(), event.isGeneratedByPipe()));
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTablePrivilegeParseVisitor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTablePrivilegeParseVisitor.java
index bf0871f0032..9f3d92e29f1 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTablePrivilegeParseVisitor.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTablePrivilegeParseVisitor.java
@@ -19,8 +19,10 @@
package org.apache.iotdb.confignode.manager.pipe.source;
+import org.apache.iotdb.commons.audit.IAuditEntity;
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
+import org.apache.iotdb.confignode.audit.CNAuditLogger;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanVisitor;
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorRelationalPlan;
@@ -37,353 +39,334 @@ import org.apache.iotdb.confignode.consensus.request.write.table.RenameTablePlan
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
+import org.apache.iotdb.confignode.manager.ConfigManager;
import org.apache.iotdb.confignode.service.ConfigNode;
import org.apache.iotdb.rpc.TSStatusCode;
import java.util.Optional;
public class PipeConfigTablePrivilegeParseVisitor
- extends ConfigPhysicalPlanVisitor<Optional<ConfigPhysicalPlan>, String> {
+ extends ConfigPhysicalPlanVisitor<Optional<ConfigPhysicalPlan>, IAuditEntity> {
@Override
public Optional<ConfigPhysicalPlan> visitPlan(
- final ConfigPhysicalPlan plan, final String userName) {
+ final ConfigPhysicalPlan plan, final IAuditEntity userEntity) {
return Optional.of(plan);
}
@Override
public Optional<ConfigPhysicalPlan> visitCreateDatabase(
- final DatabaseSchemaPlan createDatabasePlan, final String userName) {
- return visitDatabaseSchemaPlan(createDatabasePlan, userName);
+ final DatabaseSchemaPlan createDatabasePlan, final IAuditEntity userEntity) {
+ return visitDatabaseSchemaPlan(createDatabasePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitAlterDatabase(
- final DatabaseSchemaPlan alterDatabasePlan, final String userName) {
- return visitDatabaseSchemaPlan(alterDatabasePlan, userName);
+ final DatabaseSchemaPlan alterDatabasePlan, final IAuditEntity userEntity) {
+ return visitDatabaseSchemaPlan(alterDatabasePlan, userEntity);
}
public Optional<ConfigPhysicalPlan> visitDatabaseSchemaPlan(
- final DatabaseSchemaPlan databaseSchemaPlan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(
- userName, new PrivilegeUnion(databaseSchemaPlan.getSchema().getName(), null))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ final DatabaseSchemaPlan databaseSchemaPlan, final IAuditEntity userEntity) {
+ return isDatabaseVisible(userEntity, databaseSchemaPlan.getSchema().getName())
? Optional.of(databaseSchemaPlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitDeleteDatabase(
- final DeleteDatabasePlan deleteDatabasePlan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(
- userName, new PrivilegeUnion(deleteDatabasePlan.getName(), null))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ final DeleteDatabasePlan deleteDatabasePlan, final IAuditEntity userEntity) {
+ return isDatabaseVisible(userEntity, deleteDatabasePlan.getName())
? Optional.of(deleteDatabasePlan)
: Optional.empty();
}
- @Override
- public Optional<ConfigPhysicalPlan> visitPipeCreateTableOrView(
- final PipeCreateTableOrViewPlan pipeCreateTableOrViewPlan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
+ private boolean isDatabaseVisible(final IAuditEntity userEntity, final String database) {
+ final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ final CNAuditLogger logger = configManager.getAuditLogger();
+ final boolean result =
+ configManager
.getPermissionManager()
- .checkUserPrivileges(
- userName,
- new PrivilegeUnion(
- pipeCreateTableOrViewPlan.getDatabase(),
- pipeCreateTableOrViewPlan.getTable().getTableName(),
- null))
+ .checkUserPrivileges(userEntity.getUsername(), new PrivilegeUnion(database, null))
.getStatus()
.getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ == TSStatusCode.SUCCESS_STATUS.getStatusCode();
+ if (result) {
+ logger.recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA).setResult(true), () -> database);
+ return true;
+ }
+ return PipeConfigTreePrivilegeParseVisitor.hasGlobalPrivilege(
+ userEntity, PrivilegeType.SYSTEM, database, true);
+ }
+
+ @Override
+ public Optional<ConfigPhysicalPlan> visitPipeCreateTableOrView(
+ final PipeCreateTableOrViewPlan pipeCreateTableOrViewPlan, final IAuditEntity userEntity) {
+ return isTableVisible(
+ userEntity,
+ pipeCreateTableOrViewPlan.getDatabase(),
+ pipeCreateTableOrViewPlan.getTable().getTableName())
? Optional.of(pipeCreateTableOrViewPlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitAddTableColumn(
- final AddTableColumnPlan addTableColumnPlan, final String userName) {
- return visitAbstractTablePlan(addTableColumnPlan, userName);
+ final AddTableColumnPlan addTableColumnPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(addTableColumnPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitSetTableProperties(
- final SetTablePropertiesPlan setTablePropertiesPlan, final String userName) {
- return visitAbstractTablePlan(setTablePropertiesPlan, userName);
+ final SetTablePropertiesPlan setTablePropertiesPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(setTablePropertiesPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitCommitDeleteColumn(
- final CommitDeleteColumnPlan commitDeleteColumnPlan, final String userName) {
- return visitAbstractTablePlan(commitDeleteColumnPlan, userName);
+ final CommitDeleteColumnPlan commitDeleteColumnPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(commitDeleteColumnPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRenameTableColumn(
- final RenameTableColumnPlan renameTableColumnPlan, final String userName) {
- return visitAbstractTablePlan(renameTableColumnPlan, userName);
+ final RenameTableColumnPlan renameTableColumnPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(renameTableColumnPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitCommitDeleteTable(
- final CommitDeleteTablePlan commitDeleteTablePlan, final String userName) {
- return visitAbstractTablePlan(commitDeleteTablePlan, userName);
+ final CommitDeleteTablePlan commitDeleteTablePlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(commitDeleteTablePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitPipeDeleteDevices(
- final PipeDeleteDevicesPlan pipeDeleteDevicesPlan, final String userName) {
- return visitAbstractTablePlan(pipeDeleteDevicesPlan, userName);
+ final PipeDeleteDevicesPlan pipeDeleteDevicesPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(pipeDeleteDevicesPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitSetTableComment(
- final SetTableCommentPlan setTableCommentPlan, final String userName) {
- return visitAbstractTablePlan(setTableCommentPlan, userName);
+ final SetTableCommentPlan setTableCommentPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(setTableCommentPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitSetTableColumnComment(
- final SetTableColumnCommentPlan setTableColumnCommentPlan, final String userName) {
- return visitAbstractTablePlan(setTableColumnCommentPlan, userName);
+ final SetTableColumnCommentPlan setTableColumnCommentPlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(setTableColumnCommentPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRenameTable(
- final RenameTablePlan renameTablePlan, final String userName) {
- return visitAbstractTablePlan(renameTablePlan, userName);
+ final RenameTablePlan renameTablePlan, final IAuditEntity userEntity) {
+ return visitAbstractTablePlan(renameTablePlan, userEntity);
}
private Optional<ConfigPhysicalPlan> visitAbstractTablePlan(
- final AbstractTablePlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
+ final AbstractTablePlan plan, final IAuditEntity userEntity) {
+ return isTableVisible(userEntity, plan.getDatabase(), plan.getTableName())
+ ? Optional.of(plan)
+ : Optional.empty();
+ }
+
+ private boolean isTableVisible(
+ final IAuditEntity userEntity, final String database, final String tableName) {
+ final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ final CNAuditLogger logger = configManager.getAuditLogger();
+ final boolean result =
+ configManager
.getPermissionManager()
.checkUserPrivileges(
- userName, new PrivilegeUnion(plan.getDatabase(), plan.getTableName(), null))
+ userEntity.getUsername(), new PrivilegeUnion(database, tableName, null))
.getStatus()
.getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- ? Optional.of(plan)
- : Optional.empty();
+ == TSStatusCode.SUCCESS_STATUS.getStatusCode();
+ if (result) {
+ logger.recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA).setResult(true), () -> database);
+ return true;
+ }
+ return PipeConfigTreePrivilegeParseVisitor.hasGlobalPrivilege(
+ userEntity, PrivilegeType.SYSTEM, tableName, true);
}
@Override
public Optional<ConfigPhysicalPlan> visitRCreateUser(
- final AuthorRelationalPlan rCreateUserPlan, final String userName) {
- return visitUserPlan(rCreateUserPlan, userName);
+ final AuthorRelationalPlan rCreateUserPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rCreateUserPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRCreateRole(
- final AuthorRelationalPlan rCreateRolePlan, final String userName) {
- return visitRolePlan(rCreateRolePlan, userName);
+ final AuthorRelationalPlan rCreateRolePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rCreateRolePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRUpdateUser(
- final AuthorRelationalPlan rUpdateUserPlan, final String userName) {
- return visitUserPlan(rUpdateUserPlan, userName);
+ final AuthorRelationalPlan rUpdateUserPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rUpdateUserPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRDropUserPlan(
- final AuthorRelationalPlan rDropUserPlan, final String userName) {
- return visitUserPlan(rDropUserPlan, userName);
+ final AuthorRelationalPlan rDropUserPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rDropUserPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRDropRolePlan(
- final AuthorRelationalPlan rDropRolePlan, final String userName) {
- return visitRolePlan(rDropRolePlan, userName);
+ final AuthorRelationalPlan rDropRolePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rDropRolePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserRole(
- final AuthorRelationalPlan rGrantUserRolePlan, final String userName) {
- return visitUserRolePlan(rGrantUserRolePlan, userName);
+ final AuthorRelationalPlan rGrantUserRolePlan, final IAuditEntity userEntity) {
+ return visitUserRolePlan(rGrantUserRolePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserRole(
- final AuthorRelationalPlan rRevokeUserRolePlan, final String userName) {
- return visitUserRolePlan(rRevokeUserRolePlan, userName);
+ final AuthorRelationalPlan rRevokeUserRolePlan, final IAuditEntity userEntity) {
+ return visitUserRolePlan(rRevokeUserRolePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserAny(
- final AuthorRelationalPlan rGrantUserAnyPlan, final String userName) {
- return visitUserPlan(rGrantUserAnyPlan, userName);
+ final AuthorRelationalPlan rGrantUserAnyPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rGrantUserAnyPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleAny(
- final AuthorRelationalPlan rGrantRoleAnyPlan, final String userName) {
- return visitRolePlan(rGrantRoleAnyPlan, userName);
+ final AuthorRelationalPlan rGrantRoleAnyPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rGrantRoleAnyPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserAll(
- final AuthorRelationalPlan rGrantUserAllPlan, final String userName) {
- return visitUserPlan(rGrantUserAllPlan, userName);
+ final AuthorRelationalPlan rGrantUserAllPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rGrantUserAllPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleAll(
- final AuthorRelationalPlan rGrantRoleAllPlan, final String userName) {
- return visitRolePlan(rGrantRoleAllPlan, userName);
+ final AuthorRelationalPlan rGrantRoleAllPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rGrantRoleAllPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserDB(
- final AuthorRelationalPlan rGrantUserDBPlan, final String userName) {
- return visitUserPlan(rGrantUserDBPlan, userName);
+ final AuthorRelationalPlan rGrantUserDBPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rGrantUserDBPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserTB(
- final AuthorRelationalPlan rGrantUserTBPlan, final String userName) {
- return visitUserPlan(rGrantUserTBPlan, userName);
+ final AuthorRelationalPlan rGrantUserTBPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rGrantUserTBPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleDB(
- final AuthorRelationalPlan rGrantRoleDBPlan, final String userName) {
- return visitRolePlan(rGrantRoleDBPlan, userName);
+ final AuthorRelationalPlan rGrantRoleDBPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rGrantRoleDBPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleTB(
- final AuthorRelationalPlan rGrantRoleTBPlan, final String userName) {
- return visitRolePlan(rGrantRoleTBPlan, userName);
+ final AuthorRelationalPlan rGrantRoleTBPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rGrantRoleTBPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserAny(
- final AuthorRelationalPlan rRevokeUserAnyPlan, final String userName) {
- return visitUserPlan(rRevokeUserAnyPlan, userName);
+ final AuthorRelationalPlan rRevokeUserAnyPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rRevokeUserAnyPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleAny(
- final AuthorRelationalPlan rRevokeRoleAnyPlan, final String userName) {
- return visitRolePlan(rRevokeRoleAnyPlan, userName);
+ final AuthorRelationalPlan rRevokeRoleAnyPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rRevokeRoleAnyPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserAll(
- final AuthorRelationalPlan rRevokeUserAllPlan, final String userName) {
- return visitUserPlan(rRevokeUserAllPlan, userName);
+ final AuthorRelationalPlan rRevokeUserAllPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rRevokeUserAllPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleAll(
- final AuthorRelationalPlan rRevokeRoleAllPlan, final String userName) {
- return visitRolePlan(rRevokeRoleAllPlan, userName);
+ final AuthorRelationalPlan rRevokeRoleAllPlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rRevokeRoleAllPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserDBPrivilege(
- final AuthorRelationalPlan rRevokeUserDBPrivilegePlan, final String userName) {
- return visitUserPlan(rRevokeUserDBPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeUserDBPrivilegePlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rRevokeUserDBPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserTBPrivilege(
- final AuthorRelationalPlan rRevokeUserTBPrivilegePlan, final String userName) {
- return visitUserPlan(rRevokeUserTBPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeUserTBPrivilegePlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rRevokeUserTBPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleDBPrivilege(
- final AuthorRelationalPlan rRevokeRoleTBPrivilegePlan, final String userName) {
- return visitRolePlan(rRevokeRoleTBPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeRoleTBPrivilegePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rRevokeRoleTBPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleTBPrivilege(
- final AuthorRelationalPlan rRevokeRoleTBPrivilegePlan, final String userName) {
- return visitRolePlan(rRevokeRoleTBPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeRoleTBPrivilegePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rRevokeRoleTBPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserSysPrivilege(
- final AuthorRelationalPlan rGrantUserSysPrivilegePlan, final String userName) {
- return visitUserPlan(rGrantUserSysPrivilegePlan, userName);
+ final AuthorRelationalPlan rGrantUserSysPrivilegePlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rGrantUserSysPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleSysPrivilege(
- final AuthorRelationalPlan rGrantRoleSysPrivilegePlan, final String userName) {
- return visitRolePlan(rGrantRoleSysPrivilegePlan, userName);
+ final AuthorRelationalPlan rGrantRoleSysPrivilegePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rGrantRoleSysPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserSysPrivilege(
- final AuthorRelationalPlan rRevokeUserSysPrivilegePlan, final String userName) {
- return visitUserPlan(rRevokeUserSysPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeUserSysPrivilegePlan, final IAuditEntity userEntity) {
+ return visitUserPlan(rRevokeUserSysPrivilegePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleSysPrivilege(
- final AuthorRelationalPlan rRevokeRoleSysPrivilegePlan, final String userName) {
- return visitRolePlan(rRevokeRoleSysPrivilegePlan, userName);
+ final AuthorRelationalPlan rRevokeRoleSysPrivilegePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(rRevokeRoleSysPrivilegePlan, userEntity);
}
private Optional<ConfigPhysicalPlan> visitUserPlan(
- final AuthorRelationalPlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_USER))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- ? Optional.of(plan)
- : Optional.empty();
+ final AuthorRelationalPlan plan, final IAuditEntity userEntity) {
+ return PipeConfigTreePrivilegeParseVisitor.visitUserPlan(plan, userEntity);
}
private Optional<ConfigPhysicalPlan> visitRolePlan(
- final AuthorRelationalPlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_ROLE))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- ? Optional.of(plan)
- : Optional.empty();
+ final AuthorRelationalPlan plan, final IAuditEntity userEntity) {
+ return PipeConfigTreePrivilegeParseVisitor.visitRolePlan(plan, userEntity);
}
private Optional<ConfigPhysicalPlan> visitUserRolePlan(
- final AuthorRelationalPlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_ROLE))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- || ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_USER))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- ? Optional.of(plan)
- : Optional.empty();
+ final AuthorRelationalPlan plan, final IAuditEntity userEntity) {
+ return PipeConfigTreePrivilegeParseVisitor.visitUserRolePlan(plan, userEntity);
}
}
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
index 0d5f331bc39..6080437e527 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
@@ -19,6 +19,8 @@
package org.apache.iotdb.confignode.manager.pipe.source;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.audit.IAuditEntity;
import org.apache.iotdb.commons.auth.AuthException;
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
@@ -27,12 +29,15 @@ import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathPatternTree;
import org.apache.iotdb.commons.schema.template.Template;
+import org.apache.iotdb.confignode.audit.CNAuditLogger;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanVisitor;
+import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorPlan;
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorTreePlan;
import org.apache.iotdb.confignode.consensus.request.write.database.DatabaseSchemaPlan;
import org.apache.iotdb.confignode.consensus.request.write.database.DeleteDatabasePlan;
import org.apache.iotdb.confignode.consensus.request.write.database.SetTTLPlan;
+import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeAlterEncodingCompressorPlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeactivateTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeleteLogicalViewPlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeleteTimeSeriesPlan;
@@ -40,24 +45,30 @@ import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeUnse
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.ExtendSchemaTemplatePlan;
+import org.apache.iotdb.confignode.manager.ConfigManager;
import org.apache.iotdb.confignode.service.ConfigNode;
import org.apache.iotdb.rpc.TSStatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import static org.apache.iotdb.commons.conf.IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
import static org.apache.iotdb.commons.schema.SchemaConstant.ALL_MATCH_SCOPE;
public class PipeConfigTreePrivilegeParseVisitor
- extends ConfigPhysicalPlanVisitor<Optional<ConfigPhysicalPlan>, String> {
+ extends ConfigPhysicalPlanVisitor<Optional<ConfigPhysicalPlan>, IAuditEntity> {
private static final Logger LOGGER =
LoggerFactory.getLogger(PipeConfigTreePrivilegeParseVisitor.class);
private final boolean skip;
@@ -68,102 +79,79 @@ public class PipeConfigTreePrivilegeParseVisitor
@Override
public Optional<ConfigPhysicalPlan> visitPlan(
- final ConfigPhysicalPlan plan, final String context) {
+ final ConfigPhysicalPlan plan, final IAuditEntity context) {
return Optional.of(plan);
}
@Override
public Optional<ConfigPhysicalPlan> visitCreateDatabase(
- final DatabaseSchemaPlan createDatabasePlan, final String userName) {
- return canReadSysSchema(createDatabasePlan.getSchema().getName(), userName, true)
+ final DatabaseSchemaPlan createDatabasePlan, final IAuditEntity userEntity) {
+ return canReadSysSchema(createDatabasePlan.getSchema().getName(), userEntity, true)
? Optional.of(createDatabasePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitAlterDatabase(
- final DatabaseSchemaPlan alterDatabasePlan, final String userName) {
- return canReadSysSchema(alterDatabasePlan.getSchema().getName(), userName, true)
+ final DatabaseSchemaPlan alterDatabasePlan, final IAuditEntity userEntity) {
+ return canReadSysSchema(alterDatabasePlan.getSchema().getName(), userEntity, true)
? Optional.of(alterDatabasePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitDeleteDatabase(
- final DeleteDatabasePlan deleteDatabasePlan, final String userName) {
- return canReadSysSchema(deleteDatabasePlan.getName(), userName, true)
+ final DeleteDatabasePlan deleteDatabasePlan, final IAuditEntity userEntity) {
+ return canReadSysSchema(deleteDatabasePlan.getName(), userEntity, true)
? Optional.of(deleteDatabasePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitCreateSchemaTemplate(
- final CreateSchemaTemplatePlan createSchemaTemplatePlan, final String userName) {
- return canShowSchemaTemplate(createSchemaTemplatePlan.getTemplate().getName(), userName)
+ final CreateSchemaTemplatePlan createSchemaTemplatePlan, final IAuditEntity userEntity) {
+ return canShowSchemaTemplate(createSchemaTemplatePlan.getTemplate().getName(), userEntity)
? Optional.of(createSchemaTemplatePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitCommitSetSchemaTemplate(
- final CommitSetSchemaTemplatePlan commitSetSchemaTemplatePlan, final String userName) {
- return canReadSysSchema(commitSetSchemaTemplatePlan.getPath(), userName, false)
+ final CommitSetSchemaTemplatePlan commitSetSchemaTemplatePlan,
+ final IAuditEntity userEntity) {
+ return canReadSysSchema(commitSetSchemaTemplatePlan.getPath(), userEntity, false)
? Optional.of(commitSetSchemaTemplatePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitPipeUnsetSchemaTemplate(
- final PipeUnsetSchemaTemplatePlan pipeUnsetSchemaTemplatePlan, final String userName) {
- return canReadSysSchema(pipeUnsetSchemaTemplatePlan.getPath(), userName, false)
+ final PipeUnsetSchemaTemplatePlan pipeUnsetSchemaTemplatePlan,
+ final IAuditEntity userEntity) {
+ return canReadSysSchema(pipeUnsetSchemaTemplatePlan.getPath(), userEntity, false)
? Optional.of(pipeUnsetSchemaTemplatePlan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitExtendSchemaTemplate(
- final ExtendSchemaTemplatePlan extendSchemaTemplatePlan, final String userName) {
+ final ExtendSchemaTemplatePlan extendSchemaTemplatePlan, final IAuditEntity userEntity) {
return canShowSchemaTemplate(
- extendSchemaTemplatePlan.getTemplateExtendInfo().getTemplateName(), userName)
+ extendSchemaTemplatePlan.getTemplateExtendInfo().getTemplateName(), userEntity)
? Optional.of(extendSchemaTemplatePlan)
: Optional.empty();
}
- public boolean canShowSchemaTemplate(final String templateName, final String userName) {
+ public boolean canShowSchemaTemplate(final String templateName, final IAuditEntity userEntity) {
try {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.SYSTEM))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ return hasGlobalPrivilege(userEntity, PrivilegeType.SYSTEM, templateName, false)
|| ConfigNode.getInstance()
.getConfigManager()
.getClusterSchemaManager()
.getPathsSetTemplate(templateName, ALL_MATCH_SCOPE)
.getPathList()
.stream()
- .anyMatch(
- path -> {
- try {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(
- userName,
- new PrivilegeUnion(
- Collections.singletonList(
- new PartialPath(path)
- .concatNode(MULTI_LEVEL_PATH_WILDCARD)),
- PrivilegeType.READ_SCHEMA))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode();
- } catch (final IllegalPathException e) {
- throw new RuntimeException(e);
- }
- });
+ .anyMatch(path -> hasReadPrivilege(userEntity, path, true, true));
} catch (final Exception e) {
LOGGER.warn(
"Un-parse-able path name encountered during template privilege trimming, please check",
@@ -173,116 +161,130 @@ public class PipeConfigTreePrivilegeParseVisitor
}
public boolean canReadSysSchema(
- final String path, final String userName, final boolean canSkipMulti) {
- try {
- return canSkipMulti
- && ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(
- userName,
- new PrivilegeUnion(
- Collections.singletonList(new PartialPath(path)),
- PrivilegeType.READ_SCHEMA))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- || ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(
- userName,
- new PrivilegeUnion(
- Collections.singletonList(
- new PartialPath(path).concatNode(MULTI_LEVEL_PATH_WILDCARD)),
- PrivilegeType.READ_SCHEMA))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- || ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.SYSTEM))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode();
- } catch (final IllegalPathException e) {
- LOGGER.warn("Un-parse-able path name encountered during privilege trimming, please check", e);
- return false;
- }
+ final String path, final IAuditEntity userEntity, final boolean canSkipMulti) {
+ return canSkipMulti && hasReadPrivilege(userEntity, path, false, false)
+ || hasReadPrivilege(userEntity, path, true, false)
+ || hasGlobalPrivilege(userEntity, PrivilegeType.SYSTEM, path, true);
}
@Override
public Optional<ConfigPhysicalPlan> visitGrantUser(
- final AuthorTreePlan grantUserPlan, final String userName) {
- return visitUserPlan(grantUserPlan, userName);
+ final AuthorTreePlan grantUserPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(grantUserPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRevokeUser(
- final AuthorTreePlan revokeUserPlan, final String userName) {
- return visitUserPlan(revokeUserPlan, userName);
+ final AuthorTreePlan revokeUserPlan, final IAuditEntity userEntity) {
+ return visitUserPlan(revokeUserPlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitGrantRole(
- final AuthorTreePlan grantRolePlan, final String userName) {
- return visitRolePlan(grantRolePlan, userName);
+ final AuthorTreePlan grantRolePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(grantRolePlan, userEntity);
}
@Override
public Optional<ConfigPhysicalPlan> visitRevokeRole(
- final AuthorTreePlan revokeRolePlan, final String userName) {
- return visitRolePlan(revokeRolePlan, userName);
+ final AuthorTreePlan revokeRolePlan, final IAuditEntity userEntity) {
+ return visitRolePlan(revokeRolePlan, userEntity);
}
- private Optional<ConfigPhysicalPlan> visitUserPlan(
- final AuthorTreePlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_USER))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ @Override
+ public Optional<ConfigPhysicalPlan> visitGrantRoleToUser(
+ final AuthorTreePlan grantRoleToUserPlan, final IAuditEntity userEntity) {
+ return visitUserRolePlan(grantRoleToUserPlan, userEntity);
+ }
+
+ @Override
+ public Optional<ConfigPhysicalPlan> visitRevokeRoleFromUser(
+ final AuthorTreePlan revokeRoleFromUserPlan, final IAuditEntity userEntity) {
+ return visitUserRolePlan(revokeRoleFromUserPlan, userEntity);
+ }
+
+ public static Optional<ConfigPhysicalPlan> visitUserRolePlan(
+ final AuthorPlan plan, final IAuditEntity userEntity) {
+ final Optional<ConfigPhysicalPlan> result = visitUserPlan(plan, userEntity, false);
+ return result.isPresent() ? result : visitRolePlan(plan, userEntity);
+ }
+
+ public static Optional<ConfigPhysicalPlan> visitUserPlan(
+ final AuthorPlan plan, final IAuditEntity userEntity) {
+ return visitUserPlan(plan, userEntity, true);
+ }
+
+ public static Optional<ConfigPhysicalPlan> visitUserPlan(
+ final AuthorPlan plan, final IAuditEntity userEntity, final boolean isLastCheck) {
+ final String auditObject = plan.getUserName();
+ if (userEntity.getUsername().equals(plan.getUserName())) {
+ ConfigNode.getInstance()
+ .getConfigManager()
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(null).setResult(true), () -> auditObject);
+ return Optional.of(plan);
+ }
+ return hasGlobalPrivilege(
+ userEntity, PrivilegeType.MANAGE_USER, plan.getUserName(), isLastCheck)
? Optional.of(plan)
: Optional.empty();
}
- private Optional<ConfigPhysicalPlan> visitRolePlan(
- final AuthorTreePlan plan, final String userName) {
- return ConfigNode.getInstance()
- .getConfigManager()
- .getPermissionManager()
- .checkUserPrivileges(userName, new PrivilegeUnion(PrivilegeType.MANAGE_ROLE))
- .getStatus()
- .getCode()
- == TSStatusCode.SUCCESS_STATUS.getStatusCode()
+ public static Optional<ConfigPhysicalPlan> visitRolePlan(
+ final AuthorPlan plan, final IAuditEntity userEntity) {
+ final String auditObject = plan.getRoleName();
+ final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ try {
+ if (configManager
+ .getPermissionManager()
+ .checkRoleOfUser(userEntity.getUsername(), plan.getRoleName())
+ .getStatus()
+ .getCode()
+ == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ configManager
+ .getAuditLogger()
+ .recordObjectAuthenticationAuditLog(
+ userEntity.setPrivilegeType(null).setResult(true), () -> auditObject);
+ return Optional.of(plan);
+ }
+ } catch (final Exception ignore) {
+ // Check manage role
+ }
+ return hasGlobalPrivilege(userEntity, PrivilegeType.MANAGE_ROLE, plan.getRoleName(), true)
? Optional.of(plan)
: Optional.empty();
}
@Override
public Optional<ConfigPhysicalPlan> visitPipeDeleteTimeSeries(
- final PipeDeleteTimeSeriesPlan pipeDeleteTimeSeriesPlan, final String userName) {
+ final PipeDeleteTimeSeriesPlan pipeDeleteTimeSeriesPlan, final IAuditEntity userEntity) {
+ final CNAuditLogger logger = ConfigNode.getInstance().getConfigManager().getAuditLogger();
+ final PathPatternTree originalTree =
+ PathPatternTree.deserialize(pipeDeleteTimeSeriesPlan.getPatternTreeBytes());
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
+ final String auditObject = originalTree.getAllPathPatterns().toString();
try {
- final PathPatternTree originalTree =
- PathPatternTree.deserialize(pipeDeleteTimeSeriesPlan.getPatternTreeBytes());
final PathPatternTree intersectedTree =
- originalTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userName));
+ originalTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userEntity));
if (!skip && !originalTree.equals(intersectedTree)) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
throw new AccessDeniedException(
"Not has privilege to transfer plan: " + pipeDeleteTimeSeriesPlan);
}
- return !intersectedTree.isEmpty()
+ final boolean result = !intersectedTree.isEmpty();
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), () -> auditObject);
+ return result
? Optional.of(new PipeDeleteTimeSeriesPlan(intersectedTree.serialize()))
: Optional.empty();
} catch (final IOException e) {
LOGGER.warn(
"Serialization failed for the delete time series plan in pipe transmission, skip transfer",
e);
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
return Optional.empty();
} catch (final AuthException e) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
if (skip) {
return Optional.empty();
} else {
@@ -294,25 +296,33 @@ public class PipeConfigTreePrivilegeParseVisitor
@Override
public Optional<ConfigPhysicalPlan> visitPipeDeleteLogicalView(
- final PipeDeleteLogicalViewPlan pipeDeleteLogicalViewPlan, final String userName) {
+ final PipeDeleteLogicalViewPlan pipeDeleteLogicalViewPlan, final IAuditEntity userEntity) {
+ final CNAuditLogger logger = ConfigNode.getInstance().getConfigManager().getAuditLogger();
+ final PathPatternTree originalTree =
+ PathPatternTree.deserialize(pipeDeleteLogicalViewPlan.getPatternTreeBytes());
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
+ final String auditObject = originalTree.getAllPathPatterns().toString();
try {
- final PathPatternTree originalTree =
- PathPatternTree.deserialize(pipeDeleteLogicalViewPlan.getPatternTreeBytes());
final PathPatternTree intersectedTree =
- originalTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userName));
+ originalTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userEntity));
if (!skip && !originalTree.equals(intersectedTree)) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
throw new AccessDeniedException(
"Not has privilege to transfer plan: " + pipeDeleteLogicalViewPlan);
}
- return !intersectedTree.isEmpty()
+ final boolean result = !intersectedTree.isEmpty();
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), () -> auditObject);
+ return result
? Optional.of(new PipeDeleteLogicalViewPlan(intersectedTree.serialize()))
: Optional.empty();
} catch (final IOException e) {
LOGGER.warn(
"Serialization failed for the delete time series plan in pipe transmission, skip transfer",
e);
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
return Optional.empty();
} catch (final AuthException e) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
if (skip) {
return Optional.empty();
} else {
@@ -322,16 +332,63 @@ public class PipeConfigTreePrivilegeParseVisitor
}
}
+ @Override
+ public Optional<ConfigPhysicalPlan> visitPipeAlterEncodingCompressor(
+ final PipeAlterEncodingCompressorPlan pipeAlterEncodingCompressor,
+ final IAuditEntity userEntity) {
+ final CNAuditLogger logger = ConfigNode.getInstance().getConfigManager().getAuditLogger();
+ final PathPatternTree originalTree =
+ PathPatternTree.deserialize(pipeAlterEncodingCompressor.getPatternTreeBytes());
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
+ final String auditObject = originalTree.getAllPathPatterns().toString();
+ try {
+ final PathPatternTree intersectedTree =
+ originalTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userEntity));
+ if (!skip && !originalTree.equals(intersectedTree)) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
+ throw new AccessDeniedException(
+ "Not has privilege to transfer plan: " + pipeAlterEncodingCompressor);
+ }
+ final boolean result = !intersectedTree.isEmpty();
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), () -> auditObject);
+ return result
+ ? Optional.of(
+ new PipeAlterEncodingCompressorPlan(
+ intersectedTree.serialize(),
+ pipeAlterEncodingCompressor.getEncoding(),
+ pipeAlterEncodingCompressor.getCompressor(),
+ pipeAlterEncodingCompressor.isMayAlterAudit()))
+ : Optional.empty();
+ } catch (final IOException e) {
+ LOGGER.warn(
+ "Serialization failed for the delete time series plan in pipe transmission, skip transfer",
+ e);
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
+ return Optional.empty();
+ } catch (final AuthException e) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
+ if (skip) {
+ return Optional.empty();
+ } else {
+ throw new AccessDeniedException(
+ "Not has privilege to transfer plan: " + pipeAlterEncodingCompressor);
+ }
+ }
+ }
+
@Override
public Optional<ConfigPhysicalPlan> visitPipeDeactivateTemplate(
- final PipeDeactivateTemplatePlan pipeDeactivateTemplatePlan, final String userName) {
+ final PipeDeactivateTemplatePlan pipeDeactivateTemplatePlan, final IAuditEntity userEntity) {
+ final CNAuditLogger logger = ConfigNode.getInstance().getConfigManager().getAuditLogger();
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
+ final String auditObject = pipeDeactivateTemplatePlan.getTemplateSetInfo().toString();
try {
final Map<PartialPath, List<Template>> newTemplateSetInfo = new HashMap<>();
for (final Map.Entry<PartialPath, List<Template>> templateEntry :
pipeDeactivateTemplatePlan.getTemplateSetInfo().entrySet()) {
for (final PartialPath intersectedPath :
getAllIntersectedPatterns(
- templateEntry.getKey(), userName, pipeDeactivateTemplatePlan)) {
+ templateEntry.getKey(), userEntity, pipeDeactivateTemplatePlan)) {
// root.db.device2.measurement -> root.db.device.** = root.db
// Note that we cannot take this circumstance into account
if (intersectedPath.getNodeLength() == templateEntry.getKey().getNodeLength()) {
@@ -339,10 +396,13 @@ public class PipeConfigTreePrivilegeParseVisitor
}
}
}
+ final boolean result = !newTemplateSetInfo.isEmpty();
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), () -> auditObject);
return !newTemplateSetInfo.isEmpty()
? Optional.of(new PipeDeactivateTemplatePlan(newTemplateSetInfo))
: Optional.empty();
} catch (final AuthException e) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
if (skip) {
return Optional.empty();
} else {
@@ -353,17 +413,25 @@ public class PipeConfigTreePrivilegeParseVisitor
}
@Override
- public Optional<ConfigPhysicalPlan> visitTTL(final SetTTLPlan setTTLPlan, final String userName) {
+ public Optional<ConfigPhysicalPlan> visitTTL(
+ final SetTTLPlan setTTLPlan, final IAuditEntity userEntity) {
+ final CNAuditLogger logger = ConfigNode.getInstance().getConfigManager().getAuditLogger();
+ userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
+ final String auditObject = Arrays.toString(setTTLPlan.getPathPattern());
try {
final List<PartialPath> paths =
getAllIntersectedPatterns(
- new PartialPath(setTTLPlan.getPathPattern()), userName, setTTLPlan);
+ new PartialPath(setTTLPlan.getPathPattern()), userEntity, setTTLPlan);
// The intersectionList is either a singleton list or an empty list, because the pipe
// pattern and TTL path are each either a prefix path or a full path
- return !paths.isEmpty() && paths.get(0).getNodeLength() == setTTLPlan.getPathPattern().length
+ final boolean result =
+ !paths.isEmpty() && paths.get(0).getNodeLength() == setTTLPlan.getPathPattern().length;
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), () -> auditObject);
+ return result
? Optional.of(new SetTTLPlan(paths.get(0).getNodes(), setTTLPlan.getTTL()))
: Optional.empty();
} catch (final AuthException e) {
+ logger.recordObjectAuthenticationAuditLog(userEntity.setResult(false), () -> auditObject);
if (skip) {
return Optional.empty();
} else {
@@ -373,23 +441,133 @@ public class PipeConfigTreePrivilegeParseVisitor
}
private List<PartialPath> getAllIntersectedPatterns(
- final PartialPath partialPath, final String userName, final ConfigPhysicalPlan plan)
+ final PartialPath partialPath, final IAuditEntity userEntity, final ConfigPhysicalPlan plan)
throws AuthException {
final PathPatternTree thisPatternTree = new PathPatternTree();
thisPatternTree.appendPathPattern(partialPath);
thisPatternTree.constructTree();
final PathPatternTree intersectedTree =
- thisPatternTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userName));
+ thisPatternTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userEntity));
if (!skip && !thisPatternTree.equals(intersectedTree)) {
throw new AccessDeniedException("Not has privilege to transfer plan: " + plan);
}
return intersectedTree.getAllPathPatterns();
}
- private PathPatternTree getAuthorizedPTree(final String userName) throws AuthException {
+ private PathPatternTree getAuthorizedPTree(final IAuditEntity userEntity) throws AuthException {
return ConfigNode.getInstance()
.getConfigManager()
.getPermissionManager()
- .fetchRawAuthorizedPTree(userName, PrivilegeType.READ_SCHEMA);
+ .fetchRawAuthorizedPTree(userEntity.getUsername(), PrivilegeType.READ_SCHEMA);
+ }
+
+ public static TSStatus checkGlobalStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String auditObject,
+ final boolean isLastCheck) {
+ return checkGlobalStatus(userEntity, privilegeType, auditObject, isLastCheck, false);
+ }
+
+ public static TSStatus checkGlobalStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String auditObject,
+ final boolean isLastCheck,
+ final boolean grantOption) {
+ return checkGlobalOrAnyStatus(
+ userEntity, privilegeType, auditObject, isLastCheck, grantOption, false);
+ }
+
+ public static TSStatus checkGlobalOrAnyStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String auditObject,
+ final boolean isLastCheck,
+ final boolean grantOption,
+ final boolean isAny) {
+ final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ final CNAuditLogger logger = configManager.getAuditLogger();
+ final TSStatus result =
+ configManager
+ .getPermissionManager()
+ .checkUserPrivileges(
+ userEntity.getUsername(), new PrivilegeUnion(privilegeType, grantOption, isAny))
+ .getStatus();
+ if (result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode() || isLastCheck) {
+ logger.recordObjectAuthenticationAuditLog(
+ userEntity
+ .setPrivilegeType(privilegeType)
+ .setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+ () -> auditObject);
+ }
+ return result;
+ }
+
+ public static boolean hasGlobalPrivilege(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final String auditObject,
+ final boolean isLastCheck) {
+ return checkGlobalStatus(userEntity, privilegeType, auditObject, isLastCheck).getCode()
+ == TSStatusCode.SUCCESS_STATUS.getStatusCode();
+ }
+
+ public static TSStatus checkPathsStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final @Nonnull List<PartialPath> paths,
+ final boolean isLastCheck) {
+ return checkPathsStatus(userEntity, privilegeType, paths, isLastCheck, null);
+ }
+
+ public static TSStatus checkPathsStatus(
+ final IAuditEntity userEntity,
+ final PrivilegeType privilegeType,
+ final @Nonnull List<PartialPath> paths,
+ final boolean isLastCheck,
+ final @Nullable String grantName) {
+ final ConfigManager configManager = ConfigNode.getInstance().getConfigManager();
+ final CNAuditLogger logger = configManager.getAuditLogger();
+ final TSStatus result =
+ ConfigNode.getInstance()
+ .getConfigManager()
+ .getPermissionManager()
+ .checkUserPrivileges(
+ userEntity.getUsername(),
+ new PrivilegeUnion(paths, privilegeType, Objects.nonNull(grantName)))
+ .getStatus();
+ if (result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode() || isLastCheck) {
+ logger.recordObjectAuthenticationAuditLog(
+ userEntity
+ .setPrivilegeType(PrivilegeType.READ_SCHEMA)
+ .setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+ Objects.nonNull(grantName) ? () -> grantName : paths::toString);
+ }
+ return result;
+ }
+
+ private boolean hasReadPrivilege(
+ final IAuditEntity userEntity,
+ final String path,
+ final boolean withWildcard,
+ final boolean isLastCheck) {
+ PartialPath partialPath;
+ try {
+ partialPath = new PartialPath(path);
+ } catch (final IllegalPathException e) {
+ LOGGER.warn("Unable to parse path when checking READ privilege, path: {}", path);
+ return false;
+ }
+ if (withWildcard) {
+ partialPath = partialPath.concatNode(MULTI_LEVEL_PATH_WILDCARD);
+ }
+ return checkPathsStatus(
+ userEntity,
+ PrivilegeType.READ_SCHEMA,
+ Collections.singletonList(partialPath),
+ isLastCheck)
+ .getCode()
+ == TSStatusCode.SUCCESS_STATUS.getStatusCode();
}
}
diff --git a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
index 7823513bf26..73d370b5a00 100644
--- a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
+++ b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.confignode.manager.pipe.source;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.audit.UserEntity;
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
import org.apache.iotdb.commons.exception.MetadataException;
@@ -32,6 +33,7 @@ import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorTreePlan;
import org.apache.iotdb.confignode.consensus.request.write.database.DatabaseSchemaPlan;
import org.apache.iotdb.confignode.consensus.request.write.database.SetTTLPlan;
+import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeAlterEncodingCompressorPlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeactivateTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeleteLogicalViewPlan;
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeDeleteTimeSeriesPlan;
@@ -54,10 +56,11 @@ import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Objects;
import java.util.function.BiFunction;
public class PipeConfigTreePrivilegeParseVisitorTest {
-
+ private static final UserEntity FAKE_USER_ENTITY = new UserEntity(0L, "", "");
private final PipeConfigTreePrivilegeParseVisitor skipVisitor =
new PipeConfigTreePrivilegeParseVisitor(true);
private final PipeConfigTreePrivilegeParseVisitor throwVisitor =
@@ -85,28 +88,28 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
public void testCanReadSysSchema() {
permissionManager.setUserPrivilege(
(userName, privilegeUnion) -> privilegeUnion.getPrivilegeType() == PrivilegeType.SYSTEM);
- Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
+ Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
permissionManager.setUserPrivilege(
(userName, privilegeUnion) ->
privilegeUnion.getPrivilegeType() == PrivilegeType.READ_SCHEMA
&& privilegeUnion.getPaths().stream().allMatch(path -> path.equals("root.db")));
- Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
- Assert.assertFalse(skipVisitor.canReadSysSchema("root.db", null, false));
+ Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
+ Assert.assertFalse(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, false));
Assert.assertFalse(
throwVisitor
.visitCreateDatabase(
new DatabaseSchemaPlan(
ConfigPhysicalPlanType.CreateDatabase, new TDatabaseSchema("root.db1")),
- null)
+ FAKE_USER_ENTITY)
.isPresent());
permissionManager.setUserPrivilege(
(userName, privilegeUnion) ->
privilegeUnion.getPrivilegeType() == PrivilegeType.READ_SCHEMA
&& privilegeUnion.getPaths().stream().allMatch(path -> path.equals("root.db.**")));
- Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
- Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, false));
+ Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
+ Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, false));
}
@Test
@@ -116,40 +119,62 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_USER);
Assert.assertTrue(
skipVisitor
- .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null)
+ .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), FAKE_USER_ENTITY)
.isPresent());
Assert.assertTrue(
skipVisitor
- .visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null)
+ .visitRevokeUser(
+ new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), FAKE_USER_ENTITY)
.isPresent());
Assert.assertFalse(
skipVisitor
- .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null)
+ .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), FAKE_USER_ENTITY)
.isPresent());
Assert.assertFalse(
skipVisitor
- .visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null)
+ .visitRevokeRole(
+ new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), FAKE_USER_ENTITY)
.isPresent());
+ permissionManager.setUserPrivilege((userName, privilegeUnion) -> false);
+ AuthorTreePlan plan = new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser);
+ plan.setUserName("");
+ Assert.assertTrue(skipVisitor.visitGrantUser(plan, FAKE_USER_ENTITY).isPresent());
+ Assert.assertTrue(skipVisitor.visitRevokeUser(plan, FAKE_USER_ENTITY).isPresent());
+ plan.setUserName("another");
+ Assert.assertFalse(skipVisitor.visitGrantUser(plan, FAKE_USER_ENTITY).isPresent());
+ Assert.assertFalse(skipVisitor.visitRevokeUser(plan, FAKE_USER_ENTITY).isPresent());
+
permissionManager.setUserPrivilege(
(userName, privilegeUnion) ->
privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_ROLE);
Assert.assertFalse(
skipVisitor
- .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null)
+ .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), FAKE_USER_ENTITY)
.isPresent());
Assert.assertFalse(
skipVisitor
- .visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null)
+ .visitRevokeUser(
+ new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), FAKE_USER_ENTITY)
.isPresent());
Assert.assertTrue(
skipVisitor
- .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null)
+ .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), FAKE_USER_ENTITY)
.isPresent());
Assert.assertTrue(
skipVisitor
- .visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null)
+ .visitRevokeRole(
+ new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), FAKE_USER_ENTITY)
.isPresent());
+
+ permissionManager.setUserPrivilege((userName, privilegeUnion) -> false);
+ plan = new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser);
+ plan.setRoleName("");
+ Assert.assertTrue(skipVisitor.visitGrantRole(plan, FAKE_USER_ENTITY).isPresent());
+ Assert.assertTrue(skipVisitor.visitRevokeRole(plan, FAKE_USER_ENTITY).isPresent());
+ plan.setRoleName("another");
+ Assert.assertFalse(skipVisitor.visitGrantRole(plan, FAKE_USER_ENTITY).isPresent());
+ Assert.assertFalse(skipVisitor.visitRevokeRole(plan, FAKE_USER_ENTITY).isPresent());
}
@Test
@@ -172,7 +197,8 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
PathPatternTree.deserialize(
((PipeDeleteTimeSeriesPlan)
skipVisitor
- .visitPipeDeleteTimeSeries(new PipeDeleteTimeSeriesPlan(buffer), null)
+ .visitPipeDeleteTimeSeries(
+ new PipeDeleteTimeSeriesPlan(buffer), FAKE_USER_ENTITY)
.get())
.getPatternTreeBytes())
.getAllPathPatterns());
@@ -181,16 +207,39 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
PathPatternTree.deserialize(
((PipeDeleteLogicalViewPlan)
skipVisitor
- .visitPipeDeleteLogicalView(new PipeDeleteLogicalViewPlan(buffer), null)
+ .visitPipeDeleteLogicalView(
+ new PipeDeleteLogicalViewPlan(buffer), FAKE_USER_ENTITY)
+ .get())
+ .getPatternTreeBytes())
+ .getAllPathPatterns());
+ Assert.assertEquals(
+ Collections.singletonList(matchedPath),
+ PathPatternTree.deserialize(
+ ((PipeAlterEncodingCompressorPlan)
+ skipVisitor
+ .visitPipeAlterEncodingCompressor(
+ new PipeAlterEncodingCompressorPlan(
+ buffer, (byte) 0, (byte) 0, false),
+ FAKE_USER_ENTITY)
.get())
.getPatternTreeBytes())
.getAllPathPatterns());
Assert.assertThrows(
AccessDeniedException.class,
- () -> throwVisitor.visitPipeDeleteTimeSeries(new PipeDeleteTimeSeriesPlan(buffer), null));
+ () ->
+ throwVisitor.visitPipeDeleteTimeSeries(
+ new PipeDeleteTimeSeriesPlan(buffer), FAKE_USER_ENTITY));
+ Assert.assertThrows(
+ AccessDeniedException.class,
+ () ->
+ throwVisitor.visitPipeDeleteLogicalView(
+ new PipeDeleteLogicalViewPlan(buffer), FAKE_USER_ENTITY));
Assert.assertThrows(
AccessDeniedException.class,
- () -> throwVisitor.visitPipeDeleteLogicalView(new PipeDeleteLogicalViewPlan(buffer), null));
+ () ->
+ throwVisitor.visitPipeAlterEncodingCompressor(
+ new PipeAlterEncodingCompressorPlan(buffer, (byte) 0, (byte) 0, false),
+ FAKE_USER_ENTITY));
Assert.assertEquals(
Collections.singleton(matchedPath),
@@ -204,7 +253,7 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
put(unmatchedPath, Collections.singletonList(new Template()));
}
}),
- null)
+ FAKE_USER_ENTITY)
.get())
.getTemplateSetInfo()
.keySet());
@@ -215,13 +264,14 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
skipVisitor
.visitTTL(
new SetTTLPlan(new String[] {"root", "*", "device", "measurement"}, 100),
- null)
+ FAKE_USER_ENTITY)
.get())
.getPathPattern());
Assert.assertFalse(
skipVisitor
.visitTTL(
- new SetTTLPlan(new String[] {"root", "db2", "device", "measurement"}, 100), null)
+ new SetTTLPlan(new String[] {"root", "db2", "device", "measurement"}, 100),
+ FAKE_USER_ENTITY)
.isPresent());
}
@@ -255,5 +305,12 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
tree.constructTree();
return tree;
}
+
+ @Override
+ public TPermissionInfoResp checkRoleOfUser(String username, String rolename) {
+ return Objects.equals(username, rolename)
+ ? new TPermissionInfoResp(StatusUtils.OK)
+ : new TPermissionInfoResp(new TSStatus(TSStatusCode.USER_NOT_HAS_ROLE.getStatusCode()));
+ }
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java
index 2efa3abe2f0..b0122323799 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java
@@ -21,7 +21,6 @@ package org.apache.iotdb.db.pipe.receiver.protocol.thrift;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.audit.IAuditEntity;
-import org.apache.iotdb.commons.audit.UserEntity;
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeOutOfMemoryCriticalException;
@@ -1016,8 +1015,7 @@ public class IoTDBDataNodeReceiver extends IoTDBFileReceiver {
return;
}
- AuthorityChecker.getAccessControl()
- .checkCanCreateDatabase(username, database, new UserEntity(userId, username, cliHostname));
+ AuthorityChecker.getAccessControl().checkCanCreateDatabase(username, database, userEntity);
final TDatabaseSchema schema = new TDatabaseSchema(new TDatabaseSchema(database));
schema.setIsTableModel(true);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
index 1de3643cabe..fc973548ae8 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
@@ -41,6 +41,7 @@ import org.apache.iotdb.commons.schema.table.column.TimeColumnSchema;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+import org.apache.iotdb.db.audit.DNAuditLogger;
import org.apache.iotdb.db.auth.AuthorityChecker;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.exception.sql.SemanticException;
@@ -134,7 +135,6 @@ import org.apache.iotdb.db.queryengine.plan.relational.metadata.Metadata;
import org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName;
import org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.TableHeaderSchemaValidator;
import org.apache.iotdb.db.queryengine.plan.relational.security.AccessControl;
-import org.apache.iotdb.db.queryengine.plan.relational.security.ITableAuthCheckerImpl;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.AddColumn;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.AlterDB;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.AlterPipe;
@@ -500,8 +500,9 @@ public class TableConfigTaskVisitor extends AstVisitor<IConfigTask, MPPQueryCont
protected IConfigTask visitShowAvailableUrls(
final ShowAvailableUrls showAvailableUrls, final MPPQueryContext context) {
context.setQueryType(QueryType.READ);
- ITableAuthCheckerImpl.recordAuditLog(
- context.setAuditLogOperation(AuditLogOperation.QUERY).setResult(true), () -> "");
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ context.setAuditLogOperation(AuditLogOperation.QUERY).setResult(true), () -> "");
return new ShowAvailableUrlsTask();
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/AccessControlImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/AccessControlImpl.java
index 94323f30c96..c162508d45d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/AccessControlImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/AccessControlImpl.java
@@ -28,6 +28,7 @@ import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.schema.table.InformationSchema;
+import org.apache.iotdb.db.audit.DNAuditLogger;
import org.apache.iotdb.db.auth.AuthorityChecker;
import org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RelationalAuthorStatement;
@@ -117,9 +118,10 @@ public class AccessControlImpl implements AccessControl {
}
checkAuditDatabase(tableName.getDatabaseName());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SYSTEM)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.CREATE).setResult(true),
- tableName::getObjectName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.CREATE).setResult(true),
+ tableName::getObjectName);
return;
}
authChecker.checkTablePrivilege(userName, tableName, TableModelPrivilege.CREATE, auditEntity);
@@ -134,9 +136,10 @@ public class AccessControlImpl implements AccessControl {
InformationSchemaUtils.checkDBNameInWrite(tableName.getDatabaseName());
checkAuditDatabase(tableName.getDatabaseName());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SYSTEM)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.DROP).setResult(true),
- tableName::getObjectName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.DROP).setResult(true),
+ tableName::getObjectName);
return;
}
authChecker.checkTablePrivilege(userName, tableName, TableModelPrivilege.DROP, auditEntity);
@@ -148,7 +151,8 @@ public class AccessControlImpl implements AccessControl {
InformationSchemaUtils.checkDBNameInWrite(tableName.getDatabaseName());
checkAuditDatabase(tableName.getDatabaseName());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SYSTEM)) {
- ITableAuthCheckerImpl.recordAuditLog(auditEntity, tableName::getObjectName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(auditEntity, tableName::getObjectName);
return;
}
authChecker.checkTablePrivilege(userName, tableName, TableModelPrivilege.ALTER, auditEntity);
@@ -256,7 +260,9 @@ public class AccessControlImpl implements AccessControl {
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.SECURITY);
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getUserName);
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_USER, auditEntity);
@@ -266,19 +272,24 @@ public class AccessControlImpl implements AccessControl {
auditEntity.setAuditLogOperation(AuditLogOperation.DDL);
if (statement.getUserName().equals(userName)) {
// users can change the username and password of themselves
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getUserName);
return;
}
if (AuthorityChecker.SUPER_USER_ID
== AuthorityChecker.getUserId(statement.getUserName()).orElse(-1L)) {
// Only the superuser can alter him/herself
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(false), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(false), statement::getUserName);
throw new AccessDeniedException("Only the superuser can alter him/herself.");
}
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
// the superuser can alter anyone
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getUserName);
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_USER, auditEntity);
@@ -287,14 +298,17 @@ public class AccessControlImpl implements AccessControl {
auditEntity.setAuditLogOperation(AuditLogOperation.QUERY);
if (statement.getUserName().equals(userName)) {
// No need any privilege to list him/herself
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getUserName);
return;
}
// Require SECURITY privilege to list other users' privileges
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
- statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ statement::getUserName);
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_USER, auditEntity);
@@ -304,11 +318,13 @@ public class AccessControlImpl implements AccessControl {
if (!hasGlobalPrivilege(auditEntity, PrivilegeType.MANAGE_USER)) {
// No need to check privilege to list himself/herself
statement.setUserName(userName);
- ITableAuthCheckerImpl.recordAuditLog(auditEntity, statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(auditEntity, statement::getUserName);
} else {
// Require SECURITY privilege to list other users
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.SECURITY), statement::getUserName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.SECURITY), statement::getUserName);
}
return;
case CREATE_ROLE:
@@ -317,7 +333,9 @@ public class AccessControlImpl implements AccessControl {
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.SECURITY);
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getRoleName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getRoleName);
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_ROLE, auditEntity);
@@ -328,9 +346,10 @@ public class AccessControlImpl implements AccessControl {
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.SECURITY);
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true),
- () -> "user: " + statement.getUserName() + ", role: " + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> "user: " + statement.getUserName() + ", role: " + statement.getRoleName());
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_ROLE, auditEntity);
@@ -345,26 +364,32 @@ public class AccessControlImpl implements AccessControl {
if (!hasGlobalPrivilege(auditEntity, PrivilegeType.MANAGE_ROLE)) {
// No need to check privilege to list his/hers own role
statement.setUserName(userName);
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getRoleName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getRoleName);
} else {
// Require SECURITY privilege to list all roles
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
- statement::getRoleName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ statement::getRoleName);
}
return;
case LIST_ROLE_PRIV:
auditEntity.setAuditLogOperation(AuditLogOperation.QUERY);
if (AuthorityChecker.checkRole(userName, statement.getRoleName())) {
// No need any privilege to list his/hers own role
- ITableAuthCheckerImpl.recordAuditLog(auditEntity.setResult(true), statement::getRoleName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), statement::getRoleName);
return;
}
// Require SECURITY privilege to list other roles' privileges
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
- statement::getRoleName);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setPrivilegeType(PrivilegeType.SECURITY).setResult(true),
+ statement::getRoleName);
return;
}
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MANAGE_ROLE, auditEntity);
@@ -378,8 +403,10 @@ public class AccessControlImpl implements AccessControl {
.setPrivilegeType(PrivilegeType.SECURITY)
.setDatabase(statement.getDatabase());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SECURITY)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true), () -> statement.getUserName() + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> statement.getUserName() + statement.getRoleName());
return;
}
for (PrivilegeType privilegeType : statement.getPrivilegeTypes()) {
@@ -396,8 +423,10 @@ public class AccessControlImpl implements AccessControl {
.setPrivilegeType(PrivilegeType.SECURITY)
.setDatabase(statement.getDatabase());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SECURITY)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true), () -> statement.getUserName() + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> statement.getUserName() + statement.getRoleName());
return;
}
for (TableModelPrivilege privilege : TableModelPrivilege.values()) {
@@ -419,8 +448,10 @@ public class AccessControlImpl implements AccessControl {
.setPrivilegeType(PrivilegeType.SECURITY)
.setDatabase(statement.getDatabase());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SECURITY)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true), () -> statement.getUserName() + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> statement.getUserName() + statement.getRoleName());
return;
}
for (PrivilegeType privilegeType : statement.getPrivilegeTypes()) {
@@ -440,8 +471,10 @@ public class AccessControlImpl implements AccessControl {
.setPrivilegeType(PrivilegeType.SECURITY)
.setDatabase(statement.getDatabase());
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SECURITY)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true), () -> statement.getUserName() + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> statement.getUserName() + statement.getRoleName());
return;
}
for (PrivilegeType privilegeType : statement.getPrivilegeTypes()) {
@@ -462,8 +495,10 @@ public class AccessControlImpl implements AccessControl {
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.SECURITY);
if (hasGlobalPrivilege(auditEntity, PrivilegeType.SECURITY)) {
- ITableAuthCheckerImpl.recordAuditLog(
- auditEntity.setResult(true), () -> statement.getUserName() + statement.getRoleName());
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true),
+ () -> statement.getUserName() + statement.getRoleName());
return;
}
for (PrivilegeType privilegeType : statement.getPrivilegeTypes()) {
@@ -545,12 +580,13 @@ public class AccessControlImpl implements AccessControl {
public TSStatus checkCanAlterView(
IAuditEntity entity, List<PartialPath> sourcePaths, List<PartialPath> targetPaths) {
if (AuthorityChecker.SUPER_USER_ID == entity.getUserId()) {
- ITableAuthCheckerImpl.recordAuditLog(
- entity
- .setPrivilegeTypes(
- Arrays.asList(PrivilegeType.READ_SCHEMA, PrivilegeType.WRITE_SCHEMA))
- .setResult(true),
- () -> "source: " + sourcePaths + ", target: " + targetPaths);
+ DNAuditLogger.getInstance()
+ .recordObjectAuthenticationAuditLog(
+ entity
+ .setPrivilegeTypes(
+ Arrays.asList(PrivilegeType.READ_SCHEMA, PrivilegeType.WRITE_SCHEMA))
+ .setResult(true),
+ () -> "source: " + sourcePaths + ", target: " + targetPaths);
return SUCCEED;
}
TSStatus status = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/ITableAuthCheckerImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/ITableAuthCheckerImpl.java
index d1f60445295..16c32880c8e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/ITableAuthCheckerImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/ITableAuthCheckerImpl.java
@@ -33,20 +33,18 @@ import org.apache.iotdb.rpc.TSStatusCode;
import java.util.Collection;
import java.util.function.Supplier;
+import static org.apache.iotdb.commons.audit.AbstractAuditLogger.OBJECT_AUTHENTICATION_AUDIT_STR;
import static org.apache.iotdb.commons.schema.table.Audit.TABLE_MODEL_AUDIT_DATABASE;
public class ITableAuthCheckerImpl implements ITableAuthChecker {
private static final DNAuditLogger AUDIT_LOGGER = DNAuditLogger.getInstance();
- private static final String OBJECT_AUTHENTICATION_AUDIT_STR =
- "User %s (ID=%d) requests authority on object %s with result %s";
-
@Override
public void checkDatabaseVisibility(
String userName, String databaseName, IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -56,7 +54,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
// Information_schema is visible to any user
if (databaseName.equals(InformationSchema.INFORMATION_DATABASE)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -69,7 +67,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
// The audit database only requires audit privilege
boolean hasAuditPrivilege =
AuthorityChecker.checkSystemPermission(userName, PrivilegeType.AUDIT);
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.AUDIT)
@@ -82,7 +80,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
if (AuthorityChecker.checkSystemPermission(userName, PrivilegeType.SYSTEM)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -91,7 +89,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
return;
}
if (!AuthorityChecker.checkDBVisible(userName, databaseName)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -99,7 +97,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
() -> databaseName);
throw new AccessDeniedException("DATABASE " + databaseName);
}
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -121,7 +119,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -131,7 +129,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
if (AuthorityChecker.checkSystemPermission(userName, PrivilegeType.SYSTEM)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -161,7 +159,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
if (privilege == TableModelPrivilege.SELECT) {
checkCanSelectAuditTable(auditEntity);
} else {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -177,7 +175,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
String userName = auditEntity.getUsername();
if (AuthorityChecker.SUPER_USER_ID != auditEntity.getUserId()
&& !AuthorityChecker.checkSystemPermission(userName, PrivilegeType.AUDIT)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.SELECT)
@@ -201,7 +199,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
String.format(
"The database '%s' can only be queried by AUDIT admin.", TABLE_MODEL_AUDIT_DATABASE));
}
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.SELECT)
@@ -216,7 +214,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
TableModelPrivilege privilege,
IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -241,7 +239,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
IAuditEntity auditEntity) {
auditEntity.setDatabase(tableName.getDatabaseName());
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -269,7 +267,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
TableModelPrivilege privilege,
IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -305,7 +303,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
tableName.getObjectName())
.getCode()
== TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.CONTROL)
.setPrivilegeType(PrivilegeType.SYSTEM)
@@ -313,7 +311,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
tableName::getObjectName);
return true;
}
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.CONTROL)
.setPrivilegeType(PrivilegeType.SYSTEM)
@@ -327,7 +325,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
String userName, QualifiedObjectName tableName, IAuditEntity auditEntity) {
auditEntity.setDatabase(tableName.getDatabaseName());
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -341,7 +339,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
// The audit table only requires audit privilege
boolean hasAuditPrivilege =
AuthorityChecker.checkSystemPermission(userName, PrivilegeType.AUDIT);
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.AUDIT)
@@ -354,7 +352,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
if (AuthorityChecker.checkSystemPermission(userName, PrivilegeType.SYSTEM)) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -364,7 +362,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
}
if (!AuthorityChecker.checkTableVisible(
userName, tableName.getDatabaseName(), tableName.getObjectName())) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA)
@@ -378,7 +376,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
public void checkGlobalPrivilege(
String userName, TableModelPrivilege privilege, IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -398,7 +396,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
String username, Collection<PrivilegeType> privileges, IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
for (PrivilegeType privilege : privileges) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege)
@@ -419,7 +417,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
public void checkGlobalPrivilegeGrantOption(
String userName, TableModelPrivilege privilege, IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -440,7 +438,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
public void checkAnyScopePrivilegeGrantOption(
String userName, TableModelPrivilege privilege, IAuditEntity auditEntity) {
if (AuthorityChecker.SUPER_USER_ID == auditEntity.getUserId()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -463,7 +461,7 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
IAuditEntity auditEntity,
TSStatus result) {
if (result.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
@@ -471,23 +469,11 @@ public class ITableAuthCheckerImpl implements ITableAuthChecker {
auditObject);
throw new AccessDeniedException(result.getMessage());
}
- recordAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity
.setAuditLogOperation(privilege.getAuditLogOperation())
.setPrivilegeType(privilege.getPrivilegeType())
.setResult(true),
auditObject);
}
-
- public static void recordAuditLog(IAuditEntity auditEntity, Supplier<String> auditObject) {
- AUDIT_LOGGER.log(
- auditEntity.setAuditEventType(AuditEventType.OBJECT_AUTHENTICATION),
- () ->
- String.format(
- OBJECT_AUTHENTICATION_AUDIT_STR,
- auditEntity.getUsername(),
- auditEntity.getUserId(),
- auditObject.get(),
- auditEntity.getResult()));
- }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java
index e8ec61c206e..b9fc0cdddc0 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java
@@ -20,7 +20,6 @@
package org.apache.iotdb.db.queryengine.plan.relational.security;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
-import org.apache.iotdb.commons.audit.AuditEventType;
import org.apache.iotdb.commons.audit.AuditLogOperation;
import org.apache.iotdb.commons.audit.IAuditEntity;
import org.apache.iotdb.commons.auth.AuthException;
@@ -197,7 +196,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.READ_SCHEMA);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -206,12 +205,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
statement.setAuthorityScope(
AuthorityChecker.getAuthorizedPathTree(context.getUsername(), PrivilegeType.READ_SCHEMA));
} catch (AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(e.getCode().getStatusCode());
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
@@ -221,7 +220,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
final List<MeasurementPath> paths, final TreeAccessCheckContext context) {
context.setAuditLogOperation(AuditLogOperation.QUERY).setPrivilegeType(PrivilegeType.READ_DATA);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> paths.stream().distinct().collect(Collectors.toList()).toString());
return paths;
@@ -232,12 +231,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
originalTree.constructTree();
final PathPatternTree tree =
AuthorityChecker.getAuthorizedPathTree(context.getUsername(), PrivilegeType.READ_DATA);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> paths.stream().distinct().collect(Collectors.toList()).toString());
return originalTree.intersectWithFullPathPrefixTree(tree).getAllPathPatterns(true);
} catch (AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> paths.stream().distinct().collect(Collectors.toList()).toString());
return Collections.emptyList();
@@ -300,7 +299,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
ShowSchemaTemplateStatement statement, TreeAccessCheckContext context) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
statement.setCanSeeAll(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.SYSTEM)
@@ -380,7 +379,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
public TSStatus checkCanAlterTemplate(IAuditEntity entity, Supplier<String> auditObject) {
if (AuthorityChecker.SUPER_USER.equals(entity.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
entity
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.EXTEND_TEMPLATE)
@@ -411,7 +410,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(path)
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.AUDIT).setResult(false), path::toString);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
@@ -423,7 +422,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
if (statement.getQueryStatement() != null) {
statement.getQueryStatement().setCanSeeAuditDB(true);
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setPrivilegeTypes(
Arrays.asList(PrivilegeType.WRITE_SCHEMA, PrivilegeType.READ_SCHEMA))
@@ -481,7 +480,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
if (statement.getQueryStatement() != null) {
statement.getQueryStatement().setCanSeeAuditDB(true);
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setPrivilegeTypes(
Arrays.asList(PrivilegeType.READ_SCHEMA, PrivilegeType.WRITE_SCHEMA))
@@ -524,7 +523,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getNewName())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.WRITE_SCHEMA).setResult(false),
() -> statement.getOldName().toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -556,13 +555,15 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
context.setAuditLogOperation(AuditLogOperation.DDL);
if (statement.getUserName().equals(context.getUsername())) {
// users can change the username and password of themselves
- recordObjectAuthenticationAuditLog(context.setResult(true), context::getUsername);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(true), context::getUsername);
return RpcUtils.SUCCESS_STATUS;
}
if (AuthorityChecker.SUPER_USER_ID
== AuthorityChecker.getUserId(statement.getUserName()).orElse(-1L)) {
// Only the superuser can alter him/herself
- recordObjectAuthenticationAuditLog(context.setResult(false), context::getUsername);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(false), context::getUsername);
return AuthorityChecker.getTSStatus(
false,
"Has no permission to execute "
@@ -585,14 +586,15 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
}
// Can only list him/herself without MANAGE_USER privilege
statement.setUserName(context.getUsername());
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(null).setResult(true), context::getUsername);
return RpcUtils.SUCCESS_STATUS;
case LIST_USER_PRIVILEGE:
context.setAuditLogOperation(AuditLogOperation.QUERY);
if (context.getUsername().equals(statement.getUserName())) {
// No need any privilege to list his/her own privileges
- recordObjectAuthenticationAuditLog(context.setResult(true), context::getUsername);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(true), context::getUsername);
return RpcUtils.SUCCESS_STATUS;
}
// Require MANAGE_USER privilege to list other users' privileges
@@ -609,7 +611,8 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
statement::getRoleName);
} else {
// No need any privilege to list his/her own role's privileges
- recordObjectAuthenticationAuditLog(context.setResult(true), context::getUsername);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(true), context::getUsername);
return SUCCEED;
}
case LIST_ROLE:
@@ -623,12 +626,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// list roles of other user is not allowed
if (statement.getUserName() != null
&& !statement.getUserName().equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.MANAGE_ROLE).setResult(false),
context::getUsername);
return AuthorityChecker.getTSStatus(false, PrivilegeType.MANAGE_ROLE);
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(null).setResult(true), context::getUsername);
statement.setUserName(context.getUsername());
return RpcUtils.SUCCESS_STATUS;
@@ -654,10 +657,6 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
case GRANT_ROLE:
case REVOKE_ROLE:
case ACCOUNT_UNLOCK:
- context
- .setAuditLogOperation(AuditLogOperation.DDL)
- .setPrivilegeType(PrivilegeType.SECURITY);
- context.setAuditLogOperation(AuditLogOperation.DDL);
auditObject =
() ->
authorType == AuthorType.REVOKE_USER || authorType == AuthorType.GRANT_USER
@@ -706,7 +705,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
private TSStatus checkCQManagement(IAuditEntity auditEntity, Supplier<String> auditObject) {
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity.setPrivilegeType(PrivilegeType.USE_CQ).setResult(true), auditObject);
return SUCCEED;
}
@@ -732,7 +731,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
public TSStatus visitShowFunctions(
ShowFunctionsStatement statement, TreeAccessCheckContext context) {
// anyone can show functions
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setAuditLogOperation(AuditLogOperation.QUERY).setResult(true), null);
return SUCCEED;
}
@@ -829,8 +828,9 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
@Override
public TSStatus visitShowPipes(ShowPipesStatement statement, TreeAccessCheckContext context) {
- return checkPipeManagement(
- context.setAuditLogOperation(AuditLogOperation.DDL), statement::getPipeName);
+ // This query cannot be rejected, but will be filtered at configNode
+ // Does not need auth check here
+ return StatusUtils.OK;
}
@Override
@@ -900,7 +900,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
public TSStatus visitCreateTrigger(
CreateTriggerStatement statement, TreeAccessCheckContext context) {
if (TREE_MODEL_AUDIT_DATABASE_PATH.include(statement.getPathPattern())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setAuditLogOperation(AuditLogOperation.DDL)
.setPrivilegeType(PrivilegeType.USE_TRIGGER)
@@ -928,7 +928,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
private TSStatus checkTriggerManagement(IAuditEntity auditEntity, Supplier<String> auditObject) {
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity.setPrivilegeType(PrivilegeType.USE_TRIGGER).setResult(true), auditObject);
return SUCCEED;
}
@@ -962,7 +962,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.collect(Collectors.toList())
.toString());
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.SYSTEM).setResult(true), context::getDatabase);
return SUCCEED;
}
@@ -981,7 +981,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.collect(Collectors.toList())
.toString());
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.SYSTEM).setResult(true), context::getDatabase);
return SUCCEED;
}
@@ -998,7 +998,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
for (String prefixPath : statement.getPrefixPath()) {
// root.__audit can never be deleted
if (TREE_MODEL_AUDIT_DATABASE.equals(prefixPath)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.MANAGE_DATABASE).setResult(false),
() -> prefixPath);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1006,7 +1006,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
}
}
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(PrivilegeType.MANAGE_DATABASE).setResult(true),
() -> statement.getPrefixPath().toString());
return SUCCEED;
@@ -1026,13 +1026,15 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// root.__audit can never be created or alter by other users
return SUCCEED;
}
- recordObjectAuthenticationAuditLog(auditEntity.setResult(false), databaseName::getFullPath);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(false), databaseName::getFullPath);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
}
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
- recordObjectAuthenticationAuditLog(auditEntity.setResult(true), databaseName::getFullPath);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ auditEntity.setResult(true), databaseName::getFullPath);
return SUCCEED;
}
@@ -1049,7 +1051,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString())) {
return visitAuthorityInformation(statement, context);
} else {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setAuditLogOperation(AuditLogOperation.QUERY)
.setPrivilegeType(PrivilegeType.MANAGE_DATABASE)
@@ -1067,14 +1069,14 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(path)
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
}
}
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1091,7 +1093,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getDevice())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false), () -> statement.getDevice().toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
@@ -1112,7 +1114,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(path)
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
}
@@ -1125,7 +1127,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
context.setAuditLogOperation(AuditLogOperation.QUERY).setPrivilegeType(PrivilegeType.READ_DATA);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
statement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1136,12 +1138,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
statement.setAuthorityScope(
AuthorityChecker.getAuthorizedPathTree(context.getUsername(), PrivilegeType.READ_DATA));
} catch (AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(e.getCode().getStatusCode());
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
@@ -1165,7 +1167,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
PrivilegeType permission) {
context.setPrivilegeType(permission);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true), () -> checkedPathsSupplier.get().toString());
return SUCCEED;
}
@@ -1178,7 +1180,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
permission);
if (!AuthorityChecker.INTERNAL_AUDIT_USER.equals(context.getUsername())) {
// Internal auditor no needs audit log
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
checkedPaths::toString);
}
@@ -1189,13 +1191,15 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
IAuditEntity context, List<? extends PartialPath> checkedPaths, PrivilegeType permission) {
context.setPrivilegeType(permission);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(context.setResult(true), checkedPaths::toString);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(true), checkedPaths::toString);
return Collections.emptyList();
}
final List<Integer> results =
AuthorityChecker.checkFullPathOrPatternListPermission(
context.getUsername(), checkedPaths, permission);
- recordObjectAuthenticationAuditLog(context.setResult(true), checkedPaths::toString);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(true), checkedPaths::toString);
return results;
}
@@ -1208,7 +1212,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getPath())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1226,7 +1230,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getDevicePath())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1263,7 +1267,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
for (PartialPath path : statement.getDeviceMap().keySet()) {
if (includeByAuditTreeDB(path)
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(context.setResult(false), path::toString);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
}
@@ -1278,7 +1282,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getDevicePath())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1295,7 +1299,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.setPrivilegeTypes(Arrays.asList(PrivilegeType.READ_DATA, PrivilegeType.READ_SCHEMA));
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
statement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1312,7 +1316,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
} catch (AuthException e) {
return new TSStatus(e.getCode().getStatusCode());
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
@@ -1329,7 +1333,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.setPrivilegeType(PrivilegeType.READ_SCHEMA);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
statement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1344,12 +1348,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
AuthorityChecker.getAuthorizedPathTree(
context.getUsername(), PrivilegeType.READ_DATA)));
} catch (AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(e.getCode().getStatusCode());
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
@@ -1363,7 +1367,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
CountLevelTimeSeriesStatement countStatement, TreeAccessCheckContext context) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
countStatement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() ->
countStatement.getPaths().stream()
@@ -1381,7 +1385,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
CountNodesStatement countStatement, TreeAccessCheckContext context) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
countStatement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() ->
countStatement.getPaths().stream()
@@ -1399,7 +1403,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
ShowChildNodesStatement showChildNodesStatement, TreeAccessCheckContext context) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
showChildNodesStatement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() ->
showChildNodesStatement.getPaths().stream()
@@ -1417,7 +1421,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
ShowChildPathsStatement showChildPathsStatement, TreeAccessCheckContext context) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
showChildPathsStatement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() ->
showChildPathsStatement.getPaths().stream()
@@ -1437,7 +1441,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
// audit db is read-only
if (includeByAuditTreeDB(statement.getPath())
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1470,7 +1474,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
alterEncodingCompressorStatement.getPatternTree(), authTree));
return StatusUtils.OK;
} catch (final AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() ->
alterEncodingCompressorStatement.getPaths().stream()
@@ -1504,7 +1508,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
for (PartialPath path : statement.getPathPatternList()) {
if (includeByAuditTreeDB(path)
&& !context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
@@ -1589,7 +1593,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
AuthorityChecker.getTSStatus(
AuthorityChecker.checkUserMissingSystemPermissions(
context.getUsername(), relatedPrivileges));
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode())
.setAuditLogOperation(AuditLogOperation.CONTROL)
@@ -1597,7 +1601,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
() -> "");
return result;
} catch (IOException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false).setAuditLogOperation(AuditLogOperation.CONTROL), () -> "");
return AuthorityChecker.getTSStatus(false, "Failed to check config item permission");
}
@@ -1690,7 +1694,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
@Override
public TSStatus visitShowAvailableUrls(
ShowAvailableUrlsStatement showAvailableUrlsStatement, TreeAccessCheckContext context) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setAuditLogOperation(AuditLogOperation.QUERY).setResult(true), () -> "");
return SUCCEED;
}
@@ -1828,7 +1832,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
context.getUsername(), pathsForCheckingPermissions, PrivilegeType.WRITE_SCHEMA),
pathsForCheckingPermissions,
PrivilegeType.WRITE_SCHEMA);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context
.setPrivilegeType(PrivilegeType.WRITE_SCHEMA)
.setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
@@ -1859,7 +1863,8 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
context.getUsername(),
path.concatNode(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD),
PrivilegeType.READ_SCHEMA)) {
- recordObjectAuthenticationAuditLog(context.setResult(false), path::getFullPath);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
+ context.setResult(false), path::getFullPath);
return AuthorityChecker.getTSStatus(false, path, PrivilegeType.READ_SCHEMA);
}
}
@@ -1880,7 +1885,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.setPrivilegeTypes(Arrays.asList(PrivilegeType.READ_DATA, PrivilegeType.READ_SCHEMA));
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
statement.setCanSeeAuditDB(true);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1895,12 +1900,12 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
AuthorityChecker.getAuthorizedPathTree(
context.getUsername(), PrivilegeType.READ_DATA)));
} catch (AuthException e) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(false),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(e.getCode().getStatusCode());
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
@@ -1916,7 +1921,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
.setPrivilegeTypes(Arrays.asList(PrivilegeType.READ_DATA, PrivilegeType.READ_SCHEMA))
.setAuditLogOperation(AuditLogOperation.QUERY);
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(true),
() -> statement.getPaths().stream().distinct().collect(Collectors.toList()).toString());
return SUCCEED;
@@ -1949,7 +1954,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
return SUCCEED;
}
TSStatus result = AuthorityChecker.getTSStatus(false, requiredPrivilege);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setResult(result.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
auditObject);
return result;
@@ -1966,7 +1971,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
Supplier<String> auditObject,
boolean checkGrantOption) {
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(requiredPrivilege).setResult(true), auditObject);
return true;
}
@@ -1975,7 +1980,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
? AuthorityChecker.checkSystemPermissionGrantOption(
context.getUsername(), requiredPrivilege)
: AuthorityChecker.checkSystemPermission(context.getUsername(), requiredPrivilege);
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
context.setPrivilegeType(requiredPrivilege).setResult(result), auditObject);
return result;
}
@@ -1995,7 +2000,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
};
auditEntity.setPrivilegeTypes(privilegeList);
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
- recordObjectAuthenticationAuditLog(auditEntity.setResult(true), supplier);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(auditEntity.setResult(true), supplier);
return SUCCEED;
}
TSStatus status = SUCCEED;
@@ -2029,7 +2034,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
break;
}
}
- recordObjectAuthenticationAuditLog(
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(
auditEntity.setResult(status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
supplier);
return status;
@@ -2038,7 +2043,7 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
protected TSStatus checkWriteOnReadOnlyPath(IAuditEntity auditEntity, PartialPath path) {
if (includeByAuditTreeDB(path)
&& !AuthorityChecker.INTERNAL_AUDIT_USER.equals(path.getFullPath())) {
- recordObjectAuthenticationAuditLog(auditEntity, path::getFullPath);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(auditEntity, path::getFullPath);
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
.setMessage(String.format(READ_ONLY_DB_ERROR_MSG, TREE_MODEL_AUDIT_DATABASE));
}
@@ -2056,23 +2061,10 @@ public class TreeAccessCheckVisitor extends StatementVisitor<TSStatus, TreeAcces
IAuditEntity auditEntity, PrivilegeType privilegeType, Supplier<String> auditObject) {
auditEntity.setPrivilegeType(privilegeType);
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
- recordObjectAuthenticationAuditLog(auditEntity.setResult(true), auditObject);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(auditEntity.setResult(true), auditObject);
return SUCCEED;
}
- recordObjectAuthenticationAuditLog(auditEntity.setResult(false), auditObject);
+ AUDIT_LOGGER.recordObjectAuthenticationAuditLog(auditEntity.setResult(false), auditObject);
return AuthorityChecker.getTSStatus(false, "Only the admin user can perform this operation");
}
-
- protected static void recordObjectAuthenticationAuditLog(
- IAuditEntity auditEntity, Supplier<String> auditObject) {
- AUDIT_LOGGER.log(
- auditEntity.setAuditEventType(AuditEventType.OBJECT_AUTHENTICATION),
- () ->
- String.format(
- OBJECT_AUTHENTICATION_AUDIT_STR,
- auditEntity.getUsername(),
- auditEntity.getUserId(),
- auditObject.get(),
- auditEntity.getResult()));
- }
}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java
index cec03366321..d7c00c9128b 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/audit/AbstractAuditLogger.java
@@ -25,7 +25,8 @@ import org.apache.iotdb.commons.conf.CommonDescriptor;
import java.util.function.Supplier;
public abstract class AbstractAuditLogger {
-
+ public static final String OBJECT_AUTHENTICATION_AUDIT_STR =
+ "User %s (ID=%d) requests authority on object %s with result %s";
public static final String AUDIT_LOG_NODE_ID = "node_id";
public static final String AUDIT_LOG_USER_ID = "user_id";
public static final String AUDIT_LOG_USERNAME = "username";
@@ -47,4 +48,17 @@ public abstract class AbstractAuditLogger {
public boolean noNeedInsertAuditLog(IAuditEntity auditLogFields) {
return true;
}
+
+ public void recordObjectAuthenticationAuditLog(
+ final IAuditEntity auditEntity, final Supplier<String> auditObject) {
+ log(
+ auditEntity.setAuditEventType(AuditEventType.OBJECT_AUTHENTICATION),
+ () ->
+ String.format(
+ OBJECT_AUTHENTICATION_AUDIT_STR,
+ auditEntity.getUsername(),
+ auditEntity.getUserId(),
+ auditObject.get(),
+ auditEntity.getResult()));
+ }
}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeUnion.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeUnion.java
index c3ae41b16c4..44540ed3983 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeUnion.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeUnion.java
@@ -102,7 +102,7 @@ public class PrivilegeUnion {
public PrivilegeUnion(PrivilegeType type, boolean grantOption, boolean forAny) {
this.privilegeType = type;
- this.modelType = PrivilegeModelType.RELATIONAL;
+ this.modelType = forAny ? PrivilegeModelType.RELATIONAL : PrivilegeModelType.SYSTEM;
this.grantOption = grantOption;
this.forAny = forAny;
}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/receiver/IoTDBFileReceiver.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/receiver/IoTDBFileReceiver.java
index c0ee96e2b10..ff8c8dbd293 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/receiver/IoTDBFileReceiver.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/receiver/IoTDBFileReceiver.java
@@ -20,6 +20,8 @@
package org.apache.iotdb.commons.pipe.receiver;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.audit.IAuditEntity;
+import org.apache.iotdb.commons.audit.UserEntity;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.pipe.config.PipeConfig;
@@ -75,10 +77,9 @@ public abstract class IoTDBFileReceiver implements IoTDBReceiver {
// Used to restore the original thread name when the receiver is closed.
private String originalThreadName;
- protected long userId = -1;
protected String username = CONNECTOR_IOTDB_USER_DEFAULT_VALUE;
- protected String cliHostname = "";
protected String password = CONNECTOR_IOTDB_PASSWORD_DEFAULT_VALUE;
+ protected IAuditEntity userEntity;
protected long lastSuccessfulLoginTime = Long.MIN_VALUE;
@@ -288,6 +289,9 @@ public abstract class IoTDBFileReceiver implements IoTDBReceiver {
return new TPipeTransferResp(status);
}
+ long userId = -1;
+ String cliHostname = "";
+
final String userIdString =
req.getParams().get(PipeTransferHandshakeConstant.HANDSHAKE_KEY_USER_ID);
if (userIdString != null) {
@@ -303,6 +307,9 @@ public abstract class IoTDBFileReceiver implements IoTDBReceiver {
if (cliHostnameString != null) {
cliHostname = cliHostnameString;
}
+
+ userEntity = new UserEntity(userId, username, cliHostname);
+
final String passwordString =
req.getParams().get(PipeTransferHandshakeConstant.HANDSHAKE_KEY_PASSWORD);
if (passwordString != null) {
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/source/IoTDBSource.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/source/IoTDBSource.java
index 6640fde7f4a..91a149c9f66 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/source/IoTDBSource.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/source/IoTDBSource.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.commons.pipe.source;
+import org.apache.iotdb.commons.audit.AuditLogOperation;
import org.apache.iotdb.commons.audit.UserEntity;
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta;
import org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant;
@@ -195,6 +196,7 @@ public abstract class IoTDBSource implements PipeExtractor {
PipeSourceConstant.EXTRACTOR_IOTDB_CLI_HOSTNAME,
PipeSourceConstant.SOURCE_IOTDB_CLI_HOSTNAME);
userEntity = new UserEntity(Long.parseLong(userId), userName, cliHostname);
+ userEntity.setAuditLogOperation(AuditLogOperation.QUERY);
skipIfNoPrivileges = getSkipIfNoPrivileges(parameters);
}