You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2022/07/07 23:01:21 UTC
[impala] branch master updated (5f2e8ddd9 -> 607dc1f17)
This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
from 5f2e8ddd9 IMPALA-11344: Missing slots in all cases should be allowed to be read
new 5a57050d1 IMPALA-11412: CodegenFnPtr<FuncType>::store() has a compile time error when instantiated
new 607dc1f17 IMPALA-10122 (Part 2): Allow accessing views created by non-superusers
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
be/src/codegen/codegen-fn-ptr.h | 2 +-
be/src/codegen/llvm-codegen-test.cc | 20 +++
.../java/org/apache/impala/analysis/Analyzer.java | 12 +-
.../impala/analysis/DropTableOrViewStmt.java | 11 +-
.../org/apache/impala/analysis/InlineViewRef.java | 30 +++--
.../apache/impala/analysis/ResetMetadataStmt.java | 13 +-
.../impala/authorization/AuthorizableFactory.java | 9 +-
.../impala/authorization/AuthorizableTable.java | 11 +-
.../authorization/BaseAuthorizationChecker.java | 12 --
.../authorization/DefaultAuthorizableFactory.java | 5 +-
.../authorization/PrivilegeRequestBuilder.java | 50 ++-----
.../java/org/apache/impala/service/Frontend.java | 15 ---
tests/authorization/test_ranger.py | 147 +++++++++++++++++++++
13 files changed, 208 insertions(+), 129 deletions(-)
[impala] 01/02: IMPALA-11412: CodegenFnPtr::store() has a compile time error when instantiated
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 5a57050d1740f90a3eef5f43c578521c05f8b033
Author: Daniel Becker <da...@cloudera.com>
AuthorDate: Mon Jul 4 11:27:34 2022 +0200
IMPALA-11412: CodegenFnPtr<FuncType>::store() has a compile time error
when instantiated
The function template 'CodegenFnPtr<FuncType>::store()' tries to
implicitly cast a function pointer to 'void*', which is a compile time
error. The reason this hasn't come up in the builds is that this
function template is currently not used anywhere, and the function
pointers are stored through the parent class, using
'CodegenFnPtrBase::store()', which takes a 'void*'.
This commit adds the correct explicit cast from function pointer to
'void*' in 'CodegenFnPtr<FuncType>::store()' and adds tests which
instantiate (and test) this function template.
Testing:
- Added tests in llvm-codegen-test.cc that assert that
'CodegenFnPtr<FuncType>::load()' gives back the same function pointer
that we store in the object. One test stores the function pointer as
a 'void*' through 'CodegenFnPtrBase' and the other as a typed
function pointer through 'CodegenFnPtr<FuncType>'.
Change-Id: I86c78b6237630403db6ca14a3d3e1cffe0e477db
Reviewed-on: http://gerrit.cloudera.org:8080/18698
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/codegen/codegen-fn-ptr.h | 2 +-
be/src/codegen/llvm-codegen-test.cc | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/be/src/codegen/codegen-fn-ptr.h b/be/src/codegen/codegen-fn-ptr.h
index 519912be9..341d01589 100644
--- a/be/src/codegen/codegen-fn-ptr.h
+++ b/be/src/codegen/codegen-fn-ptr.h
@@ -55,7 +55,7 @@ class CodegenFnPtr : public CodegenFnPtrBase {
}
void store(FuncType value) {
- CodegenFnPtrBase::store(value);
+ CodegenFnPtrBase::store(reinterpret_cast<void*>(value));
}
};
diff --git a/be/src/codegen/llvm-codegen-test.cc b/be/src/codegen/llvm-codegen-test.cc
index c9699c337..e1704506a 100644
--- a/be/src/codegen/llvm-codegen-test.cc
+++ b/be/src/codegen/llvm-codegen-test.cc
@@ -42,6 +42,26 @@ using std::unique_ptr;
namespace impala {
+class CodegenFnPtrTest : public testing:: Test {
+ protected:
+ typedef int (*FnPtr)(int);
+ static int int_identity(int a) { return a; }
+ CodegenFnPtr<FnPtr> codegen_fn_ptr;
+};
+
+TEST_F(CodegenFnPtrTest, StoreVoidPtrAndLoad) {
+ void* fn_ptr = reinterpret_cast<void*>(int_identity);
+ codegen_fn_ptr.CodegenFnPtrBase::store(fn_ptr);
+ FnPtr loaded_fn_ptr = codegen_fn_ptr.load();
+ ASSERT_TRUE(loaded_fn_ptr == int_identity);
+}
+
+TEST_F(CodegenFnPtrTest, StoreNonVoidPtrAndLoad) {
+ codegen_fn_ptr.store(int_identity);
+ FnPtr loaded_fn_ptr = codegen_fn_ptr.load();
+ ASSERT_TRUE(loaded_fn_ptr == int_identity);
+}
+
class LlvmCodeGenTest : public testing:: Test {
protected:
scoped_ptr<TestEnv> test_env_;
[impala] 02/02: IMPALA-10122 (Part 2): Allow accessing views created by non-superusers
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 607dc1f170fb8cc013d8ec33fccee59ac4352fe4
Author: Fang-Yu Rao <fa...@cloudera.com>
AuthorDate: Fri Jun 24 15:04:54 2022 -0700
IMPALA-10122 (Part 2): Allow accessing views created by non-superusers
This patch allows Impala users to access views created by non-superusers
in HiveMetaStore, i.e., views with the table property of 'Authorized'
set to false.
Recall that a user is considered as a non-superuser by HiveMetaStore if
the IP address of the user is not on the list specified by the Hadoop
configuration of 'hadoop.proxyuser.<username>.hosts', where <username>
denotes the short name corresponding to the Kerberos principal name of
the user. For a view created by a non-superuser, HiveMetaStore adds to
the view the table property of 'Authorized' and sets the value of this
property to false after HIVE-24026.
We prevented any Impala user from accessing such views in part 1 of this
JIRA. To enable an Impala user to access such views, this patch enforces
the privilege checks for the underlying tables of a view additionally if
the given view was created by a non-superuser in HiveMetaStore.
Testing:
- Added an E2E test to verify the necessary privileges on the
underlying tables are required in order to access a view created by
a non-superuser.
Change-Id: I50a50931c6eeb0feec28c30531b09269622e6aad
Reviewed-on: http://gerrit.cloudera.org:8080/18684
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Reviewed-by: Quanlong Huang <hu...@gmail.com>
Tested-by: Quanlong Huang <hu...@gmail.com>
---
.../java/org/apache/impala/analysis/Analyzer.java | 12 +-
.../impala/analysis/DropTableOrViewStmt.java | 11 +-
.../org/apache/impala/analysis/InlineViewRef.java | 30 +++--
.../apache/impala/analysis/ResetMetadataStmt.java | 13 +-
.../impala/authorization/AuthorizableFactory.java | 9 +-
.../impala/authorization/AuthorizableTable.java | 11 +-
.../authorization/BaseAuthorizationChecker.java | 12 --
.../authorization/DefaultAuthorizableFactory.java | 5 +-
.../authorization/PrivilegeRequestBuilder.java | 50 ++-----
.../java/org/apache/impala/service/Frontend.java | 15 ---
tests/authorization/test_ranger.py | 147 +++++++++++++++++++++
11 files changed, 187 insertions(+), 128 deletions(-)
diff --git a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
index 5b5976ab1..8ee46c20a 100644
--- a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
+++ b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
@@ -3456,14 +3456,6 @@ public class Analyzer {
// without registering privileges.
FeTable table = getTableNoThrow(fqTableName.getDb(), fqTableName.getTbl());
final String tableOwner = table == null ? null : table.getOwnerUser();
- // Notice that in isViewCreatedWithoutAuthz() we assume that 'table' is not a view
- // whose creation was not authorized if we cannot find it currently cached in the
- // local Catalog, i.e., when 'table' is null.
- // TODO(IMPALA-10122): Remove the need for computing 'isViewCreatedWithoutAuthz' once
- // we can properly process a PrivilegeRequest for a view whose creation was not
- // authorized.
- boolean isViewCreatedWithoutAuthz =
- PrivilegeRequestBuilder.isViewCreatedWithoutAuthz(table);
for (Privilege priv : privilege) {
if (priv == Privilege.ANY || addColumnPrivilege) {
registerPrivReq(builder ->
@@ -3473,8 +3465,8 @@ public class Analyzer {
} else {
registerPrivReq(builder ->
builder.allOf(priv)
- .onTable(fqTableName.getDb(), fqTableName.getTbl(), tableOwner,
- isViewCreatedWithoutAuthz).build());
+ .onTable(fqTableName.getDb(), fqTableName.getTbl(), tableOwner)
+ .build());
}
}
// Propagate the AnalysisException if the table/db does not exist.
diff --git a/fe/src/main/java/org/apache/impala/analysis/DropTableOrViewStmt.java b/fe/src/main/java/org/apache/impala/analysis/DropTableOrViewStmt.java
index b7183042c..f2348976f 100644
--- a/fe/src/main/java/org/apache/impala/analysis/DropTableOrViewStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/DropTableOrViewStmt.java
@@ -20,7 +20,6 @@ package org.apache.impala.analysis;
import java.util.List;
import org.apache.impala.authorization.Privilege;
-import org.apache.impala.authorization.PrivilegeRequestBuilder;
import org.apache.impala.catalog.FeTable;
import org.apache.impala.catalog.FeView;
import org.apache.impala.catalog.TableLoadingException;
@@ -111,20 +110,12 @@ public class DropTableOrViewStmt extends StatementBase {
// Fetch the table owner information, without registering any privileges.
FeTable table = analyzer.getTableNoThrow(dbName_, tableName_.getTbl());
String tblOwnerUser = table == null ? null : table.getOwnerUser();
- // Notice that in isViewCreatedWithoutAuthz() we assume that 'table' is not a view
- // whose creation was not authorized if we cannot find it currently cached in the
- // local Catalog, i.e., when 'table' is null.
- // TODO(IMPALA-10122): Remove the need for computing 'isViewCreatedWithoutAuthz'
- // once we can properly process a PrivilegeRequest for a view whose creation was
- // not authorized.
- boolean isViewCreatedWithoutAuthz =
- PrivilegeRequestBuilder.isViewCreatedWithoutAuthz(table);
if (ifExists_) {
// Start with ANY privilege in case of IF EXISTS, and register DROP privilege
// later only if the table exists. See IMPALA-8851 for more explanation.
analyzer.registerPrivReq(builder ->
builder.allOf(Privilege.ANY)
- .onTable(dbName_, getTbl(), tblOwnerUser, isViewCreatedWithoutAuthz)
+ .onTable(dbName_, getTbl(), tblOwnerUser)
.build());
if (table == null) return;
}
diff --git a/fe/src/main/java/org/apache/impala/analysis/InlineViewRef.java b/fe/src/main/java/org/apache/impala/analysis/InlineViewRef.java
index 8d7ef97b4..fb65f2a26 100644
--- a/fe/src/main/java/org/apache/impala/analysis/InlineViewRef.java
+++ b/fe/src/main/java/org/apache/impala/analysis/InlineViewRef.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Set;
import org.apache.impala.authorization.AuthorizationContext;
+import org.apache.impala.authorization.PrivilegeRequestBuilder;
import org.apache.impala.authorization.TableMask;
import org.apache.impala.catalog.Column;
import org.apache.impala.catalog.ColumnStats;
@@ -214,18 +215,23 @@ public class InlineViewRef extends TableRef {
// Catalog views refs require special analysis settings for authorization.
if (isCatalogView()) {
analyzer.registerAuthAndAuditEvent(view_, priv_, requireGrantOption_);
- if (inlineViewAnalyzer_.isExplain()) {
- // If the user does not have privileges on the view's definition
- // then we report a masked authorization error so as not to reveal
- // privileged information (e.g., the existence of a table).
- inlineViewAnalyzer_.setMaskPrivChecks(
- String.format("User '%s' does not have privileges to " +
- "EXPLAIN this statement.", analyzer.getUser().getName()));
- } else {
- // If this is not an EXPLAIN statement, auth checks for the view
- // definition are still performed in order to determine if the user has access
- // to the runtime profile but don't trigger authorization errors.
- inlineViewAnalyzer_.setMaskPrivChecks(null);
+ // For a view created by a non-superuser, i.e., a view with its table property of
+ // 'Authorized' set to false, we do not set 'maskPrivChecks_' to true so as to
+ // enforce the privilege checks for the underlying tables additionally.
+ if (!PrivilegeRequestBuilder.isViewCreatedByNonSuperuser(view_)) {
+ if (inlineViewAnalyzer_.isExplain()) {
+ // If the user does not have privileges on the view's definition
+ // then we report a masked authorization error so as not to reveal
+ // privileged information (e.g., the existence of a table).
+ inlineViewAnalyzer_.setMaskPrivChecks(
+ String.format("User '%s' does not have privileges to " +
+ "EXPLAIN this statement.", analyzer.getUser().getName()));
+ } else {
+ // If this is not an EXPLAIN statement, auth checks for the view
+ // definition are still performed in order to determine if the user has access
+ // to the runtime profile but don't trigger authorization errors.
+ inlineViewAnalyzer_.setMaskPrivChecks(null);
+ }
}
}
diff --git a/fe/src/main/java/org/apache/impala/analysis/ResetMetadataStmt.java b/fe/src/main/java/org/apache/impala/analysis/ResetMetadataStmt.java
index c892a2e65..92d9f005d 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ResetMetadataStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ResetMetadataStmt.java
@@ -21,7 +21,6 @@ import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import org.apache.impala.authorization.Privilege;
-import org.apache.impala.authorization.PrivilegeRequestBuilder;
import org.apache.impala.authorization.User;
import org.apache.impala.catalog.FeDb;
import org.apache.impala.catalog.FeTable;
@@ -178,19 +177,9 @@ public class ResetMetadataStmt extends StatementBase {
builder.onTableUnknownOwner(
dbName, tableName_.getTbl()).allOf(Privilege.REFRESH).build());
} else {
- // Notice that in isViewCreatedWithoutAuthz() we assume that 'tbl' is not a
- // view whose creation was not authorized if we cannot find it currently
- // cached in the local Catalog, i.e., when 'tbl' is null.
- // TODO(IMPALA-10122): Remove the need for computing
- // 'isViewCreatedWithoutAuthz' once we can properly process a
- // PrivilegeRequest for a view whose creation was not authorized.
- boolean isViewCreatedWithoutAuthz =
- PrivilegeRequestBuilder.isViewCreatedWithoutAuthz(tbl);
analyzer.registerPrivReq(
builder -> builder.onTable(dbName, tableName_.getTbl(),
- tbl.getOwnerUser(), isViewCreatedWithoutAuthz)
- .allOf(Privilege.REFRESH)
- .build());
+ tbl.getOwnerUser()).allOf(Privilege.REFRESH).build());
}
}
break;
diff --git a/fe/src/main/java/org/apache/impala/authorization/AuthorizableFactory.java b/fe/src/main/java/org/apache/impala/authorization/AuthorizableFactory.java
index 3b24bd1db..1a27663b4 100644
--- a/fe/src/main/java/org/apache/impala/authorization/AuthorizableFactory.java
+++ b/fe/src/main/java/org/apache/impala/authorization/AuthorizableFactory.java
@@ -38,14 +38,9 @@ public interface AuthorizableFactory {
/**
* Creates a new instance of table {@link Authorizable} for a given database and a
- * table name owned by a given user. The additional argument of
- * 'viewCreatedWithoutAuthz' indicates whether this table corresponds to a view whose
- * creation was not authorized.
- * TODO(IMPALA-10122): Remove the argument of 'viewCreatedWithoutAuthz' once we can
- * properly process a PrivilegeRequest for a view whose creation was not authorized.
+ * table name owned by a given user.
*/
- Authorizable newTable(String dbName, String tableName, @Nullable String ownerUser,
- boolean viewCreatedWithoutAuthz);
+ Authorizable newTable(String dbName, String tableName, @Nullable String ownerUser);
/**
* Creates a new instance of column {@link Authorizable} for a given database name and
diff --git a/fe/src/main/java/org/apache/impala/authorization/AuthorizableTable.java b/fe/src/main/java/org/apache/impala/authorization/AuthorizableTable.java
index 31d818e16..b670438af 100644
--- a/fe/src/main/java/org/apache/impala/authorization/AuthorizableTable.java
+++ b/fe/src/main/java/org/apache/impala/authorization/AuthorizableTable.java
@@ -33,19 +33,14 @@ public class AuthorizableTable extends Authorizable {
private final String tableName_;
@Nullable // Is null if the owner is not set.
private final String ownerUser_;
- // TODO(IMPALA-10122): Remove the following field once we can properly process a
- // PrivilegeRequest for a view whose creation was not authorized.
- private final boolean viewCreatedWithoutAuthz_;
private final List<String> columns_ = new ArrayList<>();
- public AuthorizableTable(String dbName, String tableName, @Nullable String ownerUser,
- boolean viewCreatedWithoutAuthz) {
+ public AuthorizableTable(String dbName, String tableName, @Nullable String ownerUser) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(dbName));
Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName));
dbName_ = dbName;
tableName_ = tableName;
ownerUser_ = ownerUser;
- viewCreatedWithoutAuthz_ = viewCreatedWithoutAuthz;
}
@Override
@@ -66,10 +61,6 @@ public class AuthorizableTable extends Authorizable {
@Override
public String getOwnerUser() { return ownerUser_; }
- // TODO(IMPALA-10122): Remove the following method once we can properly process a
- // PrivilegeRequest for a view whose creation was not authorized.
- public boolean isViewCreatedWithoutAuthz() { return viewCreatedWithoutAuthz_; }
-
public void setColumns(List<String> columns) {
columns_.clear();
columns_.addAll(columns);
diff --git a/fe/src/main/java/org/apache/impala/authorization/BaseAuthorizationChecker.java b/fe/src/main/java/org/apache/impala/authorization/BaseAuthorizationChecker.java
index a8c732237..698332972 100644
--- a/fe/src/main/java/org/apache/impala/authorization/BaseAuthorizationChecker.java
+++ b/fe/src/main/java/org/apache/impala/authorization/BaseAuthorizationChecker.java
@@ -255,18 +255,6 @@ public abstract class BaseAuthorizationChecker implements AuthorizationChecker {
boolean hasColumnSelectPriv = false;
for (PrivilegeRequest request: requests) {
if (request.getAuthorizable().getType() == Authorizable.Type.TABLE) {
- // Recall that this method will still be called even if authorization is not
- // enabled. In this regard, we only deny access to a view not authorized at
- // the creation time when authorization is enabled, i.e.,
- // when config_.isEnabled() is true.
- // TODO(IMPALA-10122): Remove the following if-then statement once we can
- // properly process a PrivilegeRequest for a view whose creation was not
- // authorized.
- if (config_.isEnabled() && ((AuthorizableTable) request.getAuthorizable())
- .isViewCreatedWithoutAuthz()) {
- hasTableSelectPriv = false;
- break;
- }
try {
authorizePrivilegeRequest(authzCtx, analysisResult, catalog, request);
} catch (AuthorizationException e) {
diff --git a/fe/src/main/java/org/apache/impala/authorization/DefaultAuthorizableFactory.java b/fe/src/main/java/org/apache/impala/authorization/DefaultAuthorizableFactory.java
index 378cbde80..94afaccab 100644
--- a/fe/src/main/java/org/apache/impala/authorization/DefaultAuthorizableFactory.java
+++ b/fe/src/main/java/org/apache/impala/authorization/DefaultAuthorizableFactory.java
@@ -37,11 +37,10 @@ public class DefaultAuthorizableFactory implements AuthorizableFactory {
}
@Override
- public Authorizable newTable(String dbName, String tableName, String ownerUser,
- boolean viewCreatedWithoutAuthz) {
+ public Authorizable newTable(String dbName, String tableName, String ownerUser) {
Preconditions.checkNotNull(dbName);
Preconditions.checkNotNull(tableName);
- return new AuthorizableTable(dbName, tableName, ownerUser, viewCreatedWithoutAuthz);
+ return new AuthorizableTable(dbName, tableName, ownerUser);
}
@Override
diff --git a/fe/src/main/java/org/apache/impala/authorization/PrivilegeRequestBuilder.java b/fe/src/main/java/org/apache/impala/authorization/PrivilegeRequestBuilder.java
index f672c6f69..6fc55e2a0 100644
--- a/fe/src/main/java/org/apache/impala/authorization/PrivilegeRequestBuilder.java
+++ b/fe/src/main/java/org/apache/impala/authorization/PrivilegeRequestBuilder.java
@@ -26,6 +26,7 @@ import com.google.common.collect.Sets;
import org.apache.impala.catalog.FeDb;
import org.apache.impala.catalog.FeTable;
import org.apache.impala.catalog.View;
+import org.apache.impala.catalog.local.LocalView;
import org.apache.impala.common.RuntimeEnv;
/**
@@ -67,10 +68,10 @@ public class PrivilegeRequestBuilder {
}
/**
- * Determines whether the given FeTable corresponds to a view whose creation was not
- * authorized.
+ * Determines whether the given FeTable corresponds to a view that was created by a
+ * non-superuser in HiveMetaStore.
*/
- public static boolean isViewCreatedWithoutAuthz(FeTable table) {
+ public static boolean isViewCreatedByNonSuperuser(FeTable table) {
// In the FE test environment, there is no metastore.api.Table object created and
// thus 'view' would be null. To prevent a NullPointerException from being thrown
// due to the call to getParameters(), we only check the value of the key
@@ -80,7 +81,11 @@ public class PrivilegeRequestBuilder {
// to a view not authorized at the creation time. 'table' could be null if it is
// returned from a method call to Analyzer#getTableNoThrow() and the corresponding
// FeTable is not currently cached in the local Catalog.
- if (!(table instanceof View) || RuntimeEnv.INSTANCE.isTestEnv()) {
+ // Note that we need to consider LocalView as well because a view stored in the
+ // catalog daemon would be instantiated as a LocalView if coordinator's local catalog
+ // is enabled.
+ if (!(table instanceof View || table instanceof LocalView) ||
+ RuntimeEnv.INSTANCE.isTestEnv()) {
return false;
}
org.apache.hadoop.hive.metastore.api.Table view = table.getMetaStoreTable();
@@ -97,37 +102,21 @@ public class PrivilegeRequestBuilder {
Preconditions.checkNotNull(table);
String dbName = Preconditions.checkNotNull(table.getTableName().getDb());
String tblName = Preconditions.checkNotNull(table.getTableName().getTbl());
-
- // TODO(IMPALA-10122): Remove the need for computing 'isViewCreatedWithoutAuthz' once
- // we can properly process a PrivilegeRequest for a view whose creation was not
- // authorized.
- boolean isViewCreatedWithoutAuthz = isViewCreatedWithoutAuthz(table);
- return onTable(dbName, tblName, table.getOwnerUser(), isViewCreatedWithoutAuthz);
- }
-
- /**
- * Sets the authorizable object to be a table.
- */
- public PrivilegeRequestBuilder onTable(
- String dbName, String tableName, String ownerUser) {
- return onTable(dbName, tableName, ownerUser, false);
+ return onTable(dbName, tblName, table.getOwnerUser());
}
/**
* Sets the authorizable object to be a table. This method is only called by
* onTable(FeTable table) when 'table' corresponds to a view whose creation was not
* authorized.
- * TODO(IMPALA-10122): Remove the argument of 'viewCreatedWithoutAuthz' once we can
- * properly process a PrivilegeRequest for a view whose creation was not authorized.
*/
public PrivilegeRequestBuilder onTable(
- String dbName, String tableName, String ownerUser,
- boolean viewCreatedWithoutAuthz) {
+ String dbName, String tableName, String ownerUser) {
Preconditions.checkState(authorizable_ == null);
// Convert 'dbName' and 'tableName' to lowercase to avoid duplicate audit log entries
// for the PrivilegeRequest of ALTER.
authorizable_ = authzFactory_.newTable(dbName.toLowerCase(), tableName.toLowerCase(),
- ownerUser, viewCreatedWithoutAuthz);
+ ownerUser);
return this;
}
@@ -136,20 +125,7 @@ public class PrivilegeRequestBuilder {
// This call path is specifically meant for cases that try to mask the
// TableNotFound AnalysisExceptions and instead propagate that as an
// AuthorizationException.
- return onTableUnknownOwner(dbName, tableName, false);
- }
-
- /**
- * TODO(IMPALA-10122): Remove the argument of 'viewCreatedWithoutAuthz' once we can
- * properly process a PrivilegeRequest for a view whose creation was not authorized.
- */
- public PrivilegeRequestBuilder onTableUnknownOwner(String dbName, String tableName,
- boolean viewCreatedWithoutAuthz) {
- // Useful when owner cannot be determined because the table does not exist.
- // This call path is specifically meant for cases that try to mask the
- // TableNotFound AnalysisExceptions and instead propagate that as an
- // AuthorizationException.
- return onTable(dbName, tableName, null, viewCreatedWithoutAuthz);
+ return onTable(dbName, tableName, null);
}
/**
diff --git a/fe/src/main/java/org/apache/impala/service/Frontend.java b/fe/src/main/java/org/apache/impala/service/Frontend.java
index 9d5b12f86..992df9b5e 100644
--- a/fe/src/main/java/org/apache/impala/service/Frontend.java
+++ b/fe/src/main/java/org/apache/impala/service/Frontend.java
@@ -80,11 +80,8 @@ import org.apache.impala.analysis.StmtMetadataLoader.StmtTableCache;
import org.apache.impala.analysis.TableName;
import org.apache.impala.analysis.TruncateStmt;
import org.apache.impala.authentication.saml.ImpalaSamlClient;
-import org.apache.impala.authorization.Authorizable;
-import org.apache.impala.authorization.AuthorizableTable;
import org.apache.impala.authorization.AuthorizationChecker;
import org.apache.impala.authorization.AuthorizationConfig;
-import org.apache.impala.authorization.AuthorizationException;
import org.apache.impala.authorization.AuthorizationManager;
import org.apache.impala.authorization.AuthorizationFactory;
import org.apache.impala.authorization.ImpalaInternalAdminUser;
@@ -1538,18 +1535,6 @@ public class Frontend {
PrivilegeRequest privilegeRequest = new PrivilegeRequestBuilder(
authzFactory_.getAuthorizableFactory())
.allOf(Privilege.VIEW_METADATA).onTable(table).build();
- // TODO(IMPALA-10122): Remove the following if-then statement once we can
- // properly process a PrivilegeRequest for a view whose creation was not
- // authorized.
- if (privilegeRequest.getAuthorizable().getType() == Authorizable.Type.TABLE) {
- if (((AuthorizableTable) privilegeRequest.getAuthorizable())
- .isViewCreatedWithoutAuthz()) {
- throw new AuthorizationException(String.format("User '%s' does not have " +
- "privileges to execute '%s' on: %s", user.getName(),
- privilegeRequest.getPrivilege().toString(),
- privilegeRequest.getAuthorizable().getFullTableName()));
- }
- }
if (!authzChecker_.get().hasAccess(user, privilegeRequest)) {
// Filter out columns that the user is not authorized to see.
filteredColumns = new ArrayList<Column>();
diff --git a/tests/authorization/test_ranger.py b/tests/authorization/test_ranger.py
index e34f7b21b..9bca4aa50 100644
--- a/tests/authorization/test_ranger.py
+++ b/tests/authorization/test_ranger.py
@@ -781,6 +781,49 @@ class TestRanger(CustomClusterTestSuite):
.format(db, table, items))
return json.loads(r.content)["id"]
+ @staticmethod
+ def _add_deny_policy(policy_name, user, db, table, column):
+ """ Adds a deny policy and returns the policy id"""
+ data = {
+ "name": policy_name,
+ "policyType": 0,
+ "serviceType": "hive",
+ "service": "test_impala",
+ "resources": {
+ "database": {
+ "values": [db],
+ "isExcludes": False,
+ "isRecursive": False
+ },
+ "table": {
+ "values": [table],
+ "isExcludes": False,
+ "isRecursive": False
+ },
+ "column": {
+ "values": [column],
+ "isExcludes": False,
+ "isRecursive": False
+ }
+ },
+ "policyItems": [],
+ "denyPolicyItems": [
+ {
+ "accesses": [
+ {
+ "type": "select",
+ "isAllowed": True
+ }
+ ],
+ "users": [user],
+ }
+ ]
+ }
+ r = requests.post("{0}/service/public/v2/api/policy".format(RANGER_HOST),
+ auth=RANGER_AUTH, json=data, headers=REST_HEADERS)
+ assert 300 > r.status_code >= 200, r.content
+ return json.loads(r.content)["id"]
+
@staticmethod
def _remove_policy(policy_name):
r = requests.delete(
@@ -1528,6 +1571,110 @@ class TestRanger(CustomClusterTestSuite):
# drop a role.
pass
+ @pytest.mark.execute_serially
+ @CustomClusterTestSuite.with_args(
+ impalad_args=IMPALAD_ARGS, catalogd_args=CATALOGD_ARGS)
+ def test_select_view_created_by_non_superuser_with_catalog_v1(self, unique_name):
+ self._test_select_view_created_by_non_superuser(unique_name)
+
+ @pytest.mark.execute_serially
+ @CustomClusterTestSuite.with_args(
+ impalad_args=LOCAL_CATALOG_IMPALAD_ARGS,
+ catalogd_args=LOCAL_CATALOG_CATALOGD_ARGS)
+ def test_select_view_created_by_non_superuser_with_local_catalog(self, unique_name):
+ self._test_select_view_created_by_non_superuser(unique_name)
+
+ def _test_select_view_created_by_non_superuser(self, unique_name):
+ """Test that except for the necessary privileges on the view, the requesting user
+ has to be granted the necessary privileges on the underlying tables as well in order
+ to access a view with its table property of 'Authorized' set to false."""
+ admin_client = self.create_impala_client()
+ non_owner_client = self.create_impala_client()
+ unique_database = unique_name + "_db"
+ test_tbl_1 = unique_name + "_tbl_1"
+ test_tbl_2 = unique_name + "_tbl_2"
+ test_view = unique_name + "_view"
+ grantee_user = "non_owner"
+
+ try:
+ # Set up temp database, tables, and the view.
+ admin_client.execute("drop database if exists {0} cascade"
+ .format(unique_database), user=ADMIN)
+ admin_client.execute("create database {0}".format(unique_database), user=ADMIN)
+ admin_client.execute("create table {0}.{1} (id int, bigint_col bigint)"
+ .format(unique_database, test_tbl_1), user=ADMIN)
+ admin_client.execute("create table {0}.{1} (id int, string_col string)"
+ .format(unique_database, test_tbl_2), user=ADMIN)
+ admin_client.execute("create view {0}.{1} (abc, xyz) as "
+ "select count(a.bigint_col), b.string_col "
+ "from {0}.{2} a inner join {0}.{3} b on a.id = b.id "
+ "group by b.string_col having count(a.bigint_col) > 1"
+ .format(unique_database, test_view, test_tbl_1, test_tbl_2), user=ADMIN)
+ # Add this table property to simulate a view created by a non-superuser.
+ self.run_stmt_in_hive("alter view {0}.{1} "
+ "set tblproperties ('Authorized' = 'false')"
+ .format(unique_database, test_view))
+
+ admin_client.execute("grant select(abc) on table {0}.{1} to user {2}"
+ .format(unique_database, test_view, grantee_user), user=ADMIN)
+ admin_client.execute("grant select(xyz) on table {0}.{1} to user {2}"
+ .format(unique_database, test_view, grantee_user), user=ADMIN)
+ admin_client.execute("grant select on table {0}.{1} to user {2}"
+ .format(unique_database, test_tbl_2, grantee_user), user=ADMIN)
+ admin_client.execute("refresh authorization")
+
+ result = self.execute_query_expect_failure(non_owner_client,
+ "select * from {0}.{1}".format(unique_database, test_view), user=grantee_user)
+ assert "User '{0}' does not have privileges to execute 'SELECT' on: " \
+ "{1}.{2}".format(grantee_user, unique_database, test_tbl_1) in str(result)
+
+ admin_client.execute("grant select(id) on table {0}.{1} to user {2}"
+ .format(unique_database, test_tbl_1, grantee_user), user=ADMIN)
+ admin_client.execute("refresh authorization")
+ # The query is not authorized since the SELECT privilege on the column 'bigint_col'
+ # in the table 'test_tbl_1' is also required.
+ result = self.execute_query_expect_failure(non_owner_client,
+ "select * from {0}.{1}".format(unique_database, test_view), user=grantee_user)
+ assert "User '{0}' does not have privileges to execute 'SELECT' on: " \
+ "{1}.{2}".format(grantee_user, unique_database, test_tbl_1) in str(result)
+
+ admin_client.execute("grant select(bigint_col) on table {0}.{1} to user {2}"
+ .format(unique_database, test_tbl_1, grantee_user), user=ADMIN)
+ admin_client.execute("refresh authorization")
+
+ # The query is authorized successfully once sufficient privileges are granted.
+ self.execute_query_expect_success(non_owner_client,
+ "select * from {0}.{1}".format(unique_database, test_view), user=grantee_user)
+
+ # Add a deny policy to prevent 'grantee_user' from accessing the column 'id' in
+ # the table 'test_tbl_2', on which 'grantee_user' had been granted the SELECT
+ # privilege.
+ TestRanger._add_deny_policy(unique_name, grantee_user, unique_database, test_tbl_2,
+ "id")
+ admin_client.execute("refresh authorization")
+
+ # The query is not authorized since the SELECT privilege on the column 'id' in the
+ # table 'test_tbl_2' has been denied in the policy above.
+ result = self.execute_query_expect_failure(non_owner_client,
+ "select * from {0}.{1}".format(unique_database, test_view), user=grantee_user)
+ assert "User '{0}' does not have privileges to execute 'SELECT' on: " \
+ "{1}.{2}".format(grantee_user, unique_database, test_tbl_2) in str(result)
+ finally:
+ admin_client.execute("revoke select(abc) on table {0}.{1} from user {2}"
+ .format(unique_database, test_view, grantee_user), user=ADMIN)
+ admin_client.execute("revoke select(xyz) on table {0}.{1} from user {2}"
+ .format(unique_database, test_view, grantee_user), user=ADMIN)
+ admin_client.execute("revoke select(id) on table {0}.{1} from user {2}"
+ .format(unique_database, test_tbl_1, grantee_user), user=ADMIN)
+ admin_client.execute("revoke select(bigint_col) on table {0}.{1} from user {2}"
+ .format(unique_database, test_tbl_1, grantee_user), user=ADMIN)
+ admin_client.execute("revoke select on table {0}.{1} from user {2}"
+ .format(unique_database, test_tbl_2, grantee_user), user=ADMIN)
+ admin_client.execute("drop database if exists {0} cascade"
+ .format(unique_database), user=ADMIN)
+ TestRanger._remove_policy(unique_name)
+
+
class TestRangerColumnMaskingTpchNested(CustomClusterTestSuite):
"""
Tests for Apache Ranger column masking policies on tpch nested tables.