You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "saihemanth-cloudera (via GitHub)" <gi...@apache.org> on 2026/10/19 23:41:13 UTC

[PR] Restrict JDBC METASTORE database type to SYS tables. [hive]

saihemanth-cloudera opened a new pull request, #6899:
URL: https://github.com/apache/hive/pull/6899

   (no comment)


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29883: Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "saihemanth-cloudera (via GitHub)" <gi...@apache.org>.
saihemanth-cloudera commented on code in PR #6899:
URL: https://github.com/apache/hive/pull/6899#discussion_r4340890536


##########
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:
   Putting a shared constant in common/Constants crosses module boundaries (ql vs jdbc-handler). Duplicating one user-facing message is normal in Hive unless you already have a shared JDBC security constants home.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29883: Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "saihemanth-cloudera (via GitHub)" <gi...@apache.org>.
saihemanth-cloudera commented on code in PR #6899:
URL: https://github.com/apache/hive/pull/6899#discussion_r4340873570


##########
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:
   Optional hardening (trim + case-insensitive prefix) is fine but not required for security. The real control is DDL + JdbcStorageConfigManager.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29883: Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6899:
URL: https://github.com/apache/hive/pull/6899#issuecomment-6284206722

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29883: Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6899:
URL: https://github.com/apache/hive/pull/6899#issuecomment-6348828000

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [32 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.8% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29883: Restrict JDBC METASTORE database type to SYS tables. [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6899:
URL: https://github.com/apache/hive/pull/6899#issuecomment-6430134742

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6899&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6899&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6899&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6899)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org