[ https://issues.apache.org/jira/browse/HIVE-24705?focusedWorklogId=585329&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-585329 ]
ASF GitHub Bot logged work on HIVE-24705: ----------------------------------------- Author: ASF GitHub Bot Created on: 19/Apr/21 19:09 Start Date: 19/Apr/21 19:09 Worklog Time Spent: 10m Work Description: nrg4878 commented on a change in pull request #1960: URL: https://github.com/apache/hive/pull/1960#discussion_r610056943 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ########## @@ -13707,14 +13709,27 @@ ASTNode analyzeCreateTable( /** Adds entities for create table/create view. */ private void addDbAndTabToOutputs(String[] qualifiedTabName, TableType type, - boolean isTemporary, Map<String, String> tblProps) throws SemanticException { + boolean isTemporary, Map<String, String> tblProps, StorageFormat storageFormat) throws SemanticException { Database database = getDatabase(qualifiedTabName[0]); outputs.add(new WriteEntity(database, WriteEntity.WriteType.DDL_SHARED)); Table t = new Table(qualifiedTabName[0], qualifiedTabName[1]); t.setParameters(tblProps); t.setTableType(type); t.setTemporary(isTemporary); + HiveStorageHandler storageHandler = null; + if(storageFormat.getStorageHandler() != null) { + try { + storageHandler = (HiveStorageHandler) ReflectionUtils.newInstance( + conf.getClassByName(storageFormat.getStorageHandler()), SessionState.get().getConf()); + } catch (ClassNotFoundException ex) { + System.out.println("Class not found. Storage handler will be set to null: " + ex); Review comment: Please remove System.out.println and use a log handler instead. or throw an exception if we should not continue. ########## File path: ql/src/java/org/apache/hadoop/hive/ql/security/authorization/command/CommandAuthorizerV2.java ########## @@ -185,6 +191,33 @@ private static void addHivePrivObject(Entity privObject, Map<String, List<String tableName2Cols.get(Table.getCompleteName(table.getDbName(), table.getTableName())); hivePrivObject = new HivePrivilegeObject(privObjType, table.getDbName(), table.getTableName(), null, columns, actionType, null, null, table.getOwner(), table.getOwnerType()); + if(table.getStorageHandler() != null){ + //TODO: add hive privilege object for storage based handlers for create and alter table commands. + if(hiveOpType == HiveOperationType.CREATETABLE || + hiveOpType == HiveOperationType.ALTERTABLE_PROPERTIES || + hiveOpType == HiveOperationType.CREATETABLE_AS_SELECT){ + String storageuri = null; + Map<String, String> tableProperties = new HashMap<>(); + Configuration conf = new Configuration(); + tableProperties.putAll(table.getSd().getSerdeInfo().getParameters()); + tableProperties.putAll(table.getParameters()); + try { + if(table.getStorageHandler() instanceof HiveStorageAuthorizationHandler){ + HiveStorageAuthorizationHandler authorizationHandler = (HiveStorageAuthorizationHandler) ReflectionUtils.newInstance( + conf.getClassByName(table.getStorageHandler().getClass().getName()), SessionState.get().getConf()); + storageuri = authorizationHandler.getURIForAuth(tableProperties).toString(); + }else{ + //Custom storage handler that has not implemented the HiveStorageAuthorizationHandler + storageuri = table.getStorageHandler().getClass().getName()+"://"+ + HiveCustomStorageHandlerUtils.getTablePropsForCustomStorageHandler(tableProperties); + } + }catch(Exception ex){ + ex.printStackTrace(); Review comment: can you either log this exception to the log file if this is concerning to the user or ignore it if it not an issue, with a comment instead of printStackTrace() ? This goes to STDOUT and not to the server log. ########## File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveStorageAuthorizationHandler.java ########## @@ -0,0 +1,49 @@ +/* + * 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.metadata; + +import org.apache.hadoop.hive.common.classification.InterfaceAudience; +import org.apache.hadoop.hive.common.classification.InterfaceStability; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + +/** + * HiveStorageAuthorizationHandler defines a pluggable interface for + * authorization of storage based tables in Hive. A Storage authorization + * handler consists of a bundle of the following: + * + *<ul> + *<li>getURI + *</ul> + * + * Storage authorization handler classes are plugged in using the STORED BY 'classname' + * clause in CREATE TABLE. + */ +@InterfaceAudience.Public +@InterfaceStability.Stable +public interface HiveStorageAuthorizationHandler{ Review comment: Thats ok then. Thank you -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 585329) Time Spent: 1h 10m (was: 1h) > Create/Alter/Drop tables based on storage handlers in HS2 should be > authorized by Ranger/Sentry > ----------------------------------------------------------------------------------------------- > > Key: HIVE-24705 > URL: https://issues.apache.org/jira/browse/HIVE-24705 > Project: Hive > Issue Type: Improvement > Reporter: Sai Hemanth Gantasala > Assignee: Sai Hemanth Gantasala > Priority: Major > Labels: pull-request-available > Time Spent: 1h 10m > Remaining Estimate: 0h > > With doAs=false in Hive3.x, whenever a user is trying to create a table based > on storage handlers on external storage for ex: HBase table, the end user we > are seeing is hive so we cannot really enforce the condition in Apache > Ranger/Sentry on the end-user. So, we need to enforce this condition in the > hive in the event of create/alter/drop tables based on storage handlers. > Built-in hive storage handlers like HbaseStorageHandler, KafkaStorageHandler > e.t.c should implement a method getURIForAuthentication() which returns a URI > that is formed from table properties. This URI can be sent for authorization > to Ranger/Sentry. -- This message was sent by Atlassian Jira (v8.3.4#803005)