Caideyipi commented on code in PR #19017: URL: https://github.com/apache/iotdb/pull/19017#discussion_r4375698405
########## iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/InternalDatabaseUtils.java: ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.commons.schema; + +import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.commons.schema.table.Audit; + +public final class InternalDatabaseUtils { + + private InternalDatabaseUtils() {} + + /** Whether the given database (or one of its descendants) is an internal database. */ + public static boolean isInternalDatabase(final String databaseName) { + return isSystemDatabase(databaseName) || Audit.isAuditDatabase(databaseName); + } + + /** Whether the given database (or one of its descendants) is {@code root.__system}. */ + public static boolean isSystemDatabase(final String databaseName) { + return isDatabaseOrDescendant(databaseName, SchemaConstant.SYSTEM_DATABASE); + } + + /** Whether the device or measurement path belongs to {@code root.__system}. */ + public static boolean isSystemDatabasePath(final PartialPath path) { + return path != null && isSystemDatabase(path.getFullPath()); + } + + // Internal database names are matched case-insensitively: root.__System is also internal. + private static boolean isDatabaseOrDescendant( + final String databaseName, final String internalDatabase) { + return databaseName != null + && databaseName.regionMatches(true, 0, internalDatabase, 0, internalDatabase.length()) Review Comment: [P2] Match the case-sensitive reservation described by this PR. `regionMatches(true, ...)` still marks `root.__System` as internal, so normal inserts and `CREATE DATABASE root.__System` are rejected; the test added in this PR asserts that same behavior. Please use case-sensitive matching here and update the test so only exact `root.__system` (and its descendants) is reserved. ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java: ########## @@ -1116,6 +1204,14 @@ public TSStatus visitDeleteDatabase( context .setAuditLogOperation(AuditLogOperation.DDL) .setDatabase(statement.getPrefixPath().toString()); + if (!context.isInternal() + && SchemaConstant.SYSTEM_DATABASE.equals(String.join(".", statement.getPrefixPath()))) { Review Comment: [P2] Apply the descendant-aware system-database check to `DROP DATABASE`. This condition only matches exact `root.__system`, while the new helper defines descendants such as `root.__system.child` as internal. A user with `MANAGE_DATABASE` can therefore drop a child database under the protected system database. Please guard this with `InternalDatabaseUtils.isSystemDatabase(...)` and retain the internal-caller exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
