Ranger源码修改(2) -- 修改hive plugin中h

2021-08-19  本文已影响0人  _Kantin

背景

Caused by: org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException: Permission denied: user [hive] does not have [ALL] privilege on [hdfs://xxxxxxxxxx/xxxxxxxxxx/xxxxxxxxxx/xxxxxxxxxx/xxxxxxxxxx]
        at org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizer.checkPrivileges(RangerHiveAuthorizer.java:274) ~[?:?]
        at org.apache.hadoop.hive.ql.Driver.doAuthorizationV2(Driver.java:974) ~[hive-exec-2.3.3.jar:2.3.3]
        at org.apache.hadoop.hive.ql.Driver.doAuthorization(Driver.java:761) ~[hive-exec-2.3.3.jar:2.3.3]
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:550) ~[hive-exec-2.3.3.jar:2.3.3]

代码修改

if(hiveObjType == HiveObjectType.URI && isPathInFSScheme(path)) {
    FsAction permission = getURIAccessType(hiveOpType);
    boolean isURIAccessAllowed = Boolean.FALSE;
    try {
        //只针对创建表和创建表by select的操作
        if(hiveOpType == HiveOperationType.CREATETABLE || hiveOpType == HiveOperationType.CREATETABLE_AS_SELECT){
            Path       filePath   = new Path(path);
            FileSystem fs         = FileSystem.get(filePath.toUri(), getHiveConf());
            FileStatus fileStatus = fs.getFileStatus(filePath);
            LOG.info("Login user is "+user+",hdfs file owner is "+fileStatus.getOwner());
            //如果登陆用户==文件属主的话则通过
            if (user.equals(fileStatus.getOwner())){
                isURIAccessAllowed = Boolean.TRUE;
            }
        }else{
            //其它的非CREATE相关的操作还是走原来的鉴权方式
            isURIAccessAllowed = isURIAccessAllowed(user, permission, path, getHiveConf());
        }
    }catch (IOException e){
        LOG.error("Falied to verify user URL permissions,Caused by: "+ e);
    }
    if(!isURIAccessAllowed) {
        throw new HiveAccessControlException(String.format("Permission denied: user [%s] does not have [%s] privilege on [%s]", user, permission.name(), path));
    }
    continue;
}
上一篇 下一篇

猜你喜欢

热点阅读