Copilot commented on code in PR #6899: URL: https://github.com/apache/hive/pull/6899#discussion_r4332984451
########## ql/src/java/org/apache/hadoop/hive/ql/ddl/JdbcStorageHandlerDdlUtils.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.hadoop.hive.ql.ddl; + +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hive.conf.Constants; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.parse.SemanticException; + +/** + * DDL-time checks for JDBC storage-handler table properties. + */ +public final class JdbcStorageHandlerDdlUtils { + + private static final String JDBC_STORAGE_HANDLER = + "org.apache.hive.storage.jdbc.JdbcStorageHandler"; + private static final String METASTORE_DATABASE_TYPE = "METASTORE"; + private static final String SYS_DATABASE_NAME = "sys"; + + private JdbcStorageHandlerDdlUtils() { + } + + public static void validateMetastoreDatabaseTypeProperty(HiveConf conf, String storageHandler, + String databaseName, Map<String, String> tblProps) throws SemanticException { + if (!JDBC_STORAGE_HANDLER.equals(storageHandler) || tblProps == null) { + return; + } + String dbType = tblProps.get(Constants.JDBC_DATABASE_TYPE); + if (!METASTORE_DATABASE_TYPE.equalsIgnoreCase(dbType)) { + return; + } + if (StringUtils.isNotBlank(databaseName) + && SYS_DATABASE_NAME.equalsIgnoreCase(databaseName.trim())) { + return; + } + if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_STORAGE_JDBC_ALLOW_METASTORE_DATABASE_TYPE)) { + return; + } + throw new SemanticException( + "hive.sql.database.type=METASTORE is only permitted for tables in the SYS database"); Review Comment: This exact error message string is duplicated in multiple places (also in `JdbcStorageConfigManager.assertMetastoreDatabaseTypeAllowed`). To prevent future drift/inconsistent messaging (and to make tests less brittle), define a single shared constant for the message (and ideally the `SYS` database name) and reference it from both code paths. ########## ql/src/java/org/apache/hadoop/hive/ql/ddl/JdbcStorageHandlerDdlUtils.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.hadoop.hive.ql.ddl; + +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hive.conf.Constants; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.parse.SemanticException; + +/** + * DDL-time checks for JDBC storage-handler table properties. + */ +public final class JdbcStorageHandlerDdlUtils { + + private static final String JDBC_STORAGE_HANDLER = + "org.apache.hive.storage.jdbc.JdbcStorageHandler"; + private static final String METASTORE_DATABASE_TYPE = "METASTORE"; + private static final String SYS_DATABASE_NAME = "sys"; + + private JdbcStorageHandlerDdlUtils() { + } + + public static void validateMetastoreDatabaseTypeProperty(HiveConf conf, String storageHandler, + String databaseName, Map<String, String> tblProps) throws SemanticException { + if (!JDBC_STORAGE_HANDLER.equals(storageHandler) || tblProps == null) { + return; + } + String dbType = tblProps.get(Constants.JDBC_DATABASE_TYPE); + if (!METASTORE_DATABASE_TYPE.equalsIgnoreCase(dbType)) { + return; + } + if (StringUtils.isNotBlank(databaseName) + && SYS_DATABASE_NAME.equalsIgnoreCase(databaseName.trim())) { + return; + } + if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_STORAGE_JDBC_ALLOW_METASTORE_DATABASE_TYPE)) { + return; + } Review Comment: The override branch guarded by `HIVE_STORAGE_JDBC_ALLOW_METASTORE_DATABASE_TYPE` is newly introduced but isn’t covered by the new `TestJdbcStorageHandlerDdlUtils` tests. Add a test that sets this conf var to `true` and verifies that `validateMetastoreDatabaseTypeProperty(...)` allows METASTORE type outside `sys`, so the intended escape-hatch behavior is protected against regressions. ########## ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/SQLStdHiveAuthorizationValidator.java: ########## @@ -165,6 +175,10 @@ public List<HivePrivilegeObject> filterListCmdObjects(List<HivePrivilegeObject> return listObjs; } + private static boolean isMetastoreJdbcStorageUri(String uri) { + return uri != null && uri.startsWith("jdbc:metastore://"); + } Review Comment: `startsWith("jdbc:metastore://")` is case-sensitive and does not trim, so a trivial casing/whitespace variation (e.g., `JDBC:metastore://...`, or leading spaces) could bypass this check. Consider normalizing first (e.g., `trim()` + case-insensitive prefix check) to ensure the authorization restriction is reliably applied. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
