Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPALA-12291] - impala checks hdfs ranger policy #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions fe/src/main/java/org/apache/impala/catalog/HdfsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.hive.common.ValidTxnList;
import org.apache.hadoop.hive.common.ValidWriteIdList;
Expand Down Expand Up @@ -833,16 +835,23 @@ private static TAccessLevel getAvailableAccessLevel(String tableName,
Preconditions.checkNotNull(location);
FileSystem fs = location.getFileSystem(CONF);

String hdfsAuthClass = CONF.get("dfs.namenode.inode.attributes.provider.class");
boolean hdfsRangerEnabled = false;

if (hdfsAuthClass != null && hdfsAuthClass.equals("org.apache.ranger.authorization.hadoop.RangerHdfsAuthorizer")) {
hdfsRangerEnabled = true;
}

if (assumeReadWriteAccess(fs)) return TAccessLevel.READ_WRITE;

while (location != null) {
try {
FsPermissionChecker.Permissions perms = permCache.getPermissions(location);
if (perms.canReadAndWrite()) {
if (hdfsRangerEnabled ? checkAccess(location, fs, FsAction.getFsAction("rw-")) : perms.canReadAndWrite()) {
return TAccessLevel.READ_WRITE;
} else if (perms.canRead()) {
} else if (hdfsRangerEnabled ? checkAccess(location, fs, FsAction.getFsAction("r--")) : perms.canRead()) {
return TAccessLevel.READ_ONLY;
} else if (perms.canWrite()) {
} else if (hdfsRangerEnabled ? checkAccess(location, fs, FsAction.getFsAction("-w-")) : perms.canWrite()) {
return TAccessLevel.WRITE_ONLY;
}
return TAccessLevel.NONE;
Expand Down Expand Up @@ -3158,4 +3167,14 @@ public boolean isParquetTable() {
}
return true;
}

public static boolean checkAccess(Path path, FileSystem fs, FsAction action) throws IOException {
try {
fs.access(path, action);
} catch (AccessControlException e) {
return false;
}
return true;
}

}
7 changes: 6 additions & 1 deletion fe/src/main/java/org/apache/impala/service/Frontend.java
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,7 @@ private TExecRequest getTExecRequest(PlanCtx planCtx, EventSequence timeline)
+ planCtx.compilationState_.getAvailableCoresPerNode() + " cores per node.");

String retryMsg = "";
String errorMsg = "";
while (true) {
try {
req = doCreateExecRequest(planCtx, timeline);
Expand All @@ -2103,7 +2104,11 @@ private TExecRequest getTExecRequest(PlanCtx planCtx, EventSequence timeline)
LOG.warn("Retrying plan of query {}: {} (retry #{} of {})",
queryCtx.client_request.stmt, retryMsg, attempt,
INCONSISTENT_METADATA_NUM_RETRIES);
}
} catch (AnalysisException e) {
errorMsg = e.getMessage();
LOG.warn("Analysis Exception query {}: {}",
queryCtx.client_request.stmt, errorMsg);
throw e;
}

// Counters about this group set.
Expand Down