You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/04/28 17:24:39 UTC
[impala] 02/03: IMPALA-8309: add user authorization_provider flag
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 42e326244857b3b03a659b34fd038f9036dddbe3
Author: Radford Nguyen <ra...@cloudera.com>
AuthorDate: Thu Mar 28 02:49:38 2019 -0700
IMPALA-8309: add user authorization_provider flag
This commit adds a `authorization_provider` user-facing flag
in order to provide a more human-readable alternative to the
`authorization_factory_class` for internally-provided
authorization strategies.
The `authorization_factory_class` flag is retained, but no
longer takes a default value if not specified. The default
for `authorization_provider` is "sentry" in order to retain
backwards-compatibility.
If specified, `authorization_factory_class` will take
precedence.
Testing:
- Manually started minicluster with each of following flags
and verified correct authorization strategy chosen:
- provider='' factory='' => sentry
- provider=sentry factory='' => sentry
- provider=ranger factory='' => ranger
- provider='' factory=sentry => sentry
- provider='' factory=ranger => ranger
- provider=sentry factory=sentry => sentry
- provider=ranger factory=sentry => sentry
- provider=sentry factory=ranger => ranger
- provider=ranger factory=ranger => ranger
- Wrote unit tests to capture above assertions
- Ran fe unit and e2e tests
- Wrote e2e test to verify new flag behavior
Change-Id: I001c20505ba4f0562b60fdef73d15308e8500c19
Reviewed-on: http://gerrit.cloudera.org:8080/12901
Reviewed-by: Fredy Wijaya <fw...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/service/frontend.cc | 9 +-
be/src/util/backend-gflag-util.cc | 2 +
common/thrift/BackendGflags.thrift | 2 +
.../impala/authorization/AuthorizationConfig.java | 4 +-
.../authorization/AuthorizationProvider.java | 28 +++++-
.../authorization/NoopAuthorizationFactory.java | 2 +-
.../ranger/RangerAuthorizationConfig.java | 2 +-
.../sentry/SentryAuthorizationConfig.java | 2 +-
.../org/apache/impala/service/BackendConfig.java | 13 ++-
.../java/org/apache/impala/service/JniCatalog.java | 31 ++-----
.../org/apache/impala/service/JniFrontend.java | 24 +----
.../org/apache/impala/util/AuthorizationUtil.java | 101 +++++++++++++++++++++
.../org/apache/impala/common/FrontendTestBase.java | 5 +-
.../apache/impala/util/AuthorizationUtilTest.java | 94 +++++++++++++++++++
tests/authorization/test_provider.py | 77 ++++++++++++++++
tests/authorization/test_ranger.py | 6 +-
16 files changed, 340 insertions(+), 62 deletions(-)
diff --git a/be/src/service/frontend.cc b/be/src/service/frontend.cc
index 4a8b421..098758e 100644
--- a/be/src/service/frontend.cc
+++ b/be/src/service/frontend.cc
@@ -37,9 +37,14 @@ using namespace impala;
// Authorization related flags. Must be set to valid values to properly configure
// authorization.
+DEFINE_string(authorization_provider,
+ "sentry",
+ "Specifies the type of internally-provided authorization provider to use. "
+ "['ranger', 'sentry' (default)]");
DEFINE_string(authorization_factory_class,
- "org.apache.impala.authorization.sentry.SentryAuthorizationFactory",
- "Specifies the class name that implements the authorization provider.");
+ "",
+ "Specifies the class name that implements the authorization provider. "
+ "This will override the authorization_provider flag if both are specified.");
DEFINE_string(ranger_service_type, "hive", "Specifies the Ranger service type.");
DEFINE_string(ranger_app_id, "",
"Specifies the Ranger application ID. Ranger application ID is an ID to "
diff --git a/be/src/util/backend-gflag-util.cc b/be/src/util/backend-gflag-util.cc
index 13cad2d..9623fa4 100644
--- a/be/src/util/backend-gflag-util.cc
+++ b/be/src/util/backend-gflag-util.cc
@@ -75,6 +75,7 @@ DECLARE_string(authorization_factory_class);
DECLARE_bool(unlock_mt_dop);
DECLARE_string(ranger_service_type);
DECLARE_string(ranger_app_id);
+DECLARE_string(authorization_provider);
namespace impala {
@@ -149,6 +150,7 @@ Status GetThriftBackendGflags(JNIEnv* jni_env, jbyteArray* cfg_bytes) {
cfg.__set_unlock_mt_dop(FLAGS_unlock_mt_dop);
cfg.__set_ranger_service_type(FLAGS_ranger_service_type);
cfg.__set_ranger_app_id(FLAGS_ranger_app_id);
+ cfg.__set_authorization_provider(FLAGS_authorization_provider);
RETURN_IF_ERROR(SerializeThriftMsg(jni_env, &cfg, cfg_bytes));
return Status::OK();
}
diff --git a/common/thrift/BackendGflags.thrift b/common/thrift/BackendGflags.thrift
index 925816b..52561f4 100644
--- a/common/thrift/BackendGflags.thrift
+++ b/common/thrift/BackendGflags.thrift
@@ -125,4 +125,6 @@ struct TBackendGflags {
49: required string ranger_service_type
50: required string ranger_app_id
+
+ 51: required string authorization_provider
}
diff --git a/fe/src/main/java/org/apache/impala/authorization/AuthorizationConfig.java b/fe/src/main/java/org/apache/impala/authorization/AuthorizationConfig.java
index 6ab651a..338cc29 100644
--- a/fe/src/main/java/org/apache/impala/authorization/AuthorizationConfig.java
+++ b/fe/src/main/java/org/apache/impala/authorization/AuthorizationConfig.java
@@ -27,9 +27,9 @@ public interface AuthorizationConfig {
boolean isEnabled();
/**
- * Returns the authorization provider type.
+ * Returns the authorization provider name.
*/
- AuthorizationProvider getProvider();
+ String getProviderName();
/**
* The server name to secure.
diff --git a/fe/src/main/java/org/apache/impala/authorization/AuthorizationProvider.java b/fe/src/main/java/org/apache/impala/authorization/AuthorizationProvider.java
index 8e21689..b42e6c5 100644
--- a/fe/src/main/java/org/apache/impala/authorization/AuthorizationProvider.java
+++ b/fe/src/main/java/org/apache/impala/authorization/AuthorizationProvider.java
@@ -18,11 +18,33 @@
package org.apache.impala.authorization;
+import org.apache.impala.authorization.ranger.RangerAuthorizationFactory;
+import org.apache.impala.authorization.sentry.SentryAuthorizationFactory;
+
/**
* This enum contains the list of authorization providers supported in Impala.
+ *
+ * Associated with each enum value is an {@link AuthorizationFactory} implementation
+ * used to create the correct authorization classes.
*/
public enum AuthorizationProvider {
- SENTRY,
- RANGER,
- NOOP
+ SENTRY(SentryAuthorizationFactory.class.getCanonicalName()),
+ RANGER(RangerAuthorizationFactory.class.getCanonicalName()),
+ NOOP(NoopAuthorizationFactory.class.getCanonicalName());
+
+ private final String factoryClassName_;
+
+ AuthorizationProvider(String factoryClassName) {
+ this.factoryClassName_ = factoryClassName;
+ }
+
+ /**
+ * Returns the canonical name of the {@link AuthorizationFactory} implementation
+ * associated with this provider.
+ *
+ * @return the canonical name of the {@link AuthorizationFactory} impl for `this`
+ */
+ public String getAuthorizationFactoryClassName() {
+ return factoryClassName_;
+ }
}
diff --git a/fe/src/main/java/org/apache/impala/authorization/NoopAuthorizationFactory.java b/fe/src/main/java/org/apache/impala/authorization/NoopAuthorizationFactory.java
index 5a509f2..7284947 100644
--- a/fe/src/main/java/org/apache/impala/authorization/NoopAuthorizationFactory.java
+++ b/fe/src/main/java/org/apache/impala/authorization/NoopAuthorizationFactory.java
@@ -65,7 +65,7 @@ public class NoopAuthorizationFactory implements AuthorizationFactory {
@Override
public boolean isEnabled() { return false; }
@Override
- public AuthorizationProvider getProvider() { return AuthorizationProvider.NOOP; }
+ public String getProviderName() { return "noop"; }
@Override
public String getServerName() { return null; }
};
diff --git a/fe/src/main/java/org/apache/impala/authorization/ranger/RangerAuthorizationConfig.java b/fe/src/main/java/org/apache/impala/authorization/ranger/RangerAuthorizationConfig.java
index bab6dc5..86df80b 100644
--- a/fe/src/main/java/org/apache/impala/authorization/ranger/RangerAuthorizationConfig.java
+++ b/fe/src/main/java/org/apache/impala/authorization/ranger/RangerAuthorizationConfig.java
@@ -42,7 +42,7 @@ public class RangerAuthorizationConfig implements AuthorizationConfig {
public boolean isEnabled() { return true; }
@Override
- public AuthorizationProvider getProvider() { return AuthorizationProvider.RANGER; }
+ public String getProviderName() { return "ranger"; }
@Override
public String getServerName() { return serverName_; }
diff --git a/fe/src/main/java/org/apache/impala/authorization/sentry/SentryAuthorizationConfig.java b/fe/src/main/java/org/apache/impala/authorization/sentry/SentryAuthorizationConfig.java
index 9601774..20959e8 100644
--- a/fe/src/main/java/org/apache/impala/authorization/sentry/SentryAuthorizationConfig.java
+++ b/fe/src/main/java/org/apache/impala/authorization/sentry/SentryAuthorizationConfig.java
@@ -127,7 +127,7 @@ public class SentryAuthorizationConfig implements AuthorizationConfig {
}
@Override
- public AuthorizationProvider getProvider() { return AuthorizationProvider.SENTRY; }
+ public String getProviderName() { return "sentry"; }
/**
* The server name to secure.
diff --git a/fe/src/main/java/org/apache/impala/service/BackendConfig.java b/fe/src/main/java/org/apache/impala/service/BackendConfig.java
index c05e375..527f9f6 100644
--- a/fe/src/main/java/org/apache/impala/service/BackendConfig.java
+++ b/fe/src/main/java/org/apache/impala/service/BackendConfig.java
@@ -130,8 +130,15 @@ public class BackendConfig {
return backendCfg_.enable_orc_scanner;
}
+ /**
+ * Returns the value of the `authorization_factory_class` flag or `null` if
+ * the flag was not specified.
+ *
+ * @return value of the `authorization_factory_class` flag or `null` if not specified
+ */
public String getAuthorizationFactoryClass() {
- return backendCfg_.getAuthorization_factory_class();
+ final String val = backendCfg_.getAuthorization_factory_class();
+ return "".equals(val) ? null : val;
}
public boolean isMtDopUnlocked() {
@@ -146,6 +153,10 @@ public class BackendConfig {
return backendCfg_.getRanger_app_id();
}
+ public String getAuthorizationProvider() {
+ return backendCfg_.getAuthorization_provider();
+ }
+
// Inits the auth_to_local configuration in the static KerberosName class.
private static void initAuthToLocal() {
// If auth_to_local is enabled, we read the configuration hadoop.security.auth_to_local
diff --git a/fe/src/main/java/org/apache/impala/service/JniCatalog.java b/fe/src/main/java/org/apache/impala/service/JniCatalog.java
index 6d2700c..39ce348 100644
--- a/fe/src/main/java/org/apache/impala/service/JniCatalog.java
+++ b/fe/src/main/java/org/apache/impala/service/JniCatalog.java
@@ -28,7 +28,6 @@ import java.util.UUID;
import org.apache.impala.authorization.AuthorizationConfig;
import org.apache.impala.authorization.AuthorizationFactory;
import org.apache.impala.authorization.AuthorizationManager;
-import org.apache.impala.authorization.NoopAuthorizationFactory;
import org.apache.impala.authorization.User;
import org.apache.impala.authorization.sentry.SentryCatalogdAuthorizationManager;
import org.apache.impala.catalog.CatalogException;
@@ -67,6 +66,7 @@ import org.apache.impala.thrift.TUniqueId;
import org.apache.impala.thrift.TUpdateCatalogRequest;
import org.apache.impala.thrift.TBackendGflags;
import org.apache.impala.thrift.TUpdateTableUsageRequest;
+import org.apache.impala.util.AuthorizationUtil;
import org.apache.impala.util.GlogAppender;
import org.apache.impala.util.PatternMatcher;
import org.apache.thrift.TException;
@@ -111,30 +111,15 @@ public class JniCatalog {
GlogAppender.Install(TLogLevel.values()[cfg.impala_log_lvl],
TLogLevel.values()[cfg.non_impala_java_vlog]);
- AuthorizationFactory authzFactory;
- try {
- authzFactory = (AuthorizationFactory) Class.forName(
- BackendConfig.INSTANCE.getAuthorizationFactoryClass())
- .getConstructor(BackendConfig.class).newInstance(BackendConfig.INSTANCE);
- } catch (Exception e) {
- String msg = String.format("Unable to instantiate authorization provider: %s",
- BackendConfig.INSTANCE.getAuthorizationFactoryClass());
- LOG.error(msg);
- throw new InternalException(msg, e);
- }
- AuthorizationConfig authzConfig = authzFactory.getAuthorizationConfig();
- if (!authzConfig.isEnabled()) {
- // For backward compatibility to keep the existing behavior, when authorization
- // is not enabled, we need to use a dummy authorization config.
- authzFactory = new NoopAuthorizationFactory(BackendConfig.INSTANCE);
- authzConfig = authzFactory.getAuthorizationConfig();
- LOG.info("Authorization is 'DISABLED'.");
- } else {
- LOG.info(String.format("Authorization is 'ENABLED' using %s.",
- authzConfig.getProvider()));
- }
+ // create the appropriate auth factory from backend config
+ // this logic is shared with JniFrontend
+ final AuthorizationFactory authzFactory
+ = AuthorizationUtil.authzFactoryFrom(BackendConfig.INSTANCE);
+
LOG.info(JniUtil.getJavaVersion());
+ final AuthorizationConfig authzConfig = authzFactory.getAuthorizationConfig();
+
catalog_ = new CatalogServiceCatalog(cfg.load_catalog_in_background,
cfg.num_metadata_loading_threads, cfg.initial_hms_cnxn_timeout_s, getServiceId(),
cfg.local_library_path);
diff --git a/fe/src/main/java/org/apache/impala/service/JniFrontend.java b/fe/src/main/java/org/apache/impala/service/JniFrontend.java
index ad12103..a798bba 100644
--- a/fe/src/main/java/org/apache/impala/service/JniFrontend.java
+++ b/fe/src/main/java/org/apache/impala/service/JniFrontend.java
@@ -45,6 +45,7 @@ import org.apache.impala.analysis.DescriptorTable;
import org.apache.impala.analysis.ToSqlUtils;
import org.apache.impala.authorization.AuthorizationConfig;
import org.apache.impala.authorization.AuthorizationFactory;
+import org.apache.impala.authorization.AuthorizationProvider;
import org.apache.impala.authorization.ImpalaInternalAdminUser;
import org.apache.impala.authorization.NoopAuthorizationFactory;
import org.apache.impala.authorization.User;
@@ -97,6 +98,7 @@ import org.apache.impala.thrift.TShowStatsParams;
import org.apache.impala.thrift.TTableName;
import org.apache.impala.thrift.TUpdateCatalogCacheRequest;
import org.apache.impala.thrift.TUpdateExecutorMembershipRequest;
+import org.apache.impala.util.AuthorizationUtil;
import org.apache.impala.util.GlogAppender;
import org.apache.impala.util.PatternMatcher;
import org.apache.impala.util.TSessionStateUtil;
@@ -134,26 +136,8 @@ public class JniFrontend {
GlogAppender.Install(TLogLevel.values()[cfg.impala_log_lvl],
TLogLevel.values()[cfg.non_impala_java_vlog]);
- AuthorizationFactory authzFactory;
- try {
- authzFactory = (AuthorizationFactory) Class.forName(
- BackendConfig.INSTANCE.getAuthorizationFactoryClass())
- .getConstructor(BackendConfig.class).newInstance(BackendConfig.INSTANCE);
- } catch (Exception e) {
- String msg = String.format("Unable to instantiate authorization provider: %s",
- BackendConfig.INSTANCE.getAuthorizationFactoryClass());
- throw new InternalException(msg,e);
- }
- AuthorizationConfig authzConfig = authzFactory.getAuthorizationConfig();
- if (!authzConfig.isEnabled()) {
- // For backward compatibility to keep the existing behavior, when authorization
- // is not enabled, we need to use a dummy authorization config.
- authzFactory = new NoopAuthorizationFactory(BackendConfig.INSTANCE);
- LOG.info("Authorization is 'DISABLED'.");
- } else {
- LOG.info(String.format("Authorization is 'ENABLED' using %s.",
- authzConfig.getProvider()));
- }
+ final AuthorizationFactory authzFactory =
+ AuthorizationUtil.authzFactoryFrom(BackendConfig.INSTANCE);
LOG.info(JniUtil.getJavaVersion());
frontend_ = new Frontend(authzFactory);
}
diff --git a/fe/src/main/java/org/apache/impala/util/AuthorizationUtil.java b/fe/src/main/java/org/apache/impala/util/AuthorizationUtil.java
new file mode 100644
index 0000000..1857cc3
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/util/AuthorizationUtil.java
@@ -0,0 +1,101 @@
+// 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.impala.util;
+
+import org.apache.impala.authorization.AuthorizationConfig;
+import org.apache.impala.authorization.AuthorizationFactory;
+import org.apache.impala.authorization.AuthorizationProvider;
+import org.apache.impala.authorization.NoopAuthorizationFactory;
+import org.apache.impala.common.InternalException;
+import org.apache.impala.service.BackendConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuthorizationUtil {
+ private final static Logger LOG = LoggerFactory.getLogger(AuthorizationUtil.class);
+
+ private AuthorizationUtil() {}
+
+ /**
+ * Returns the {@link AuthorizationFactory} class name specified by
+ * the given {@link BackendConfig}
+ *
+ * @param beCfg
+ * @return the AuthorizationFactory class name for the given BackendConfig
+ * @throws InternalException if the class name could not be determined from
+ * the given backend config values
+ */
+ public static String authzFactoryClassNameFrom(BackendConfig beCfg)
+ throws InternalException {
+ final String authzFactoryClassOption = beCfg.getAuthorizationFactoryClass();
+ final String authzFactoryClassName;
+ if (authzFactoryClassOption != null) {
+ // authorization_factory_class takes precedence
+ authzFactoryClassName = authzFactoryClassOption;
+ } else {
+ // use authorization_provider flag
+ final String authzProvider = beCfg.getAuthorizationProvider();
+ try {
+ final AuthorizationProvider provider = AuthorizationProvider.valueOf(
+ authzProvider.toUpperCase().trim());
+ authzFactoryClassName = provider.getAuthorizationFactoryClassName();
+ } catch (Exception e) {
+ throw new InternalException(
+ "Could not parse authorization_provider flag: " + authzProvider);
+ }
+ }
+ return authzFactoryClassName;
+ }
+
+ /**
+ * Creates the appropriate {@link AuthorizationFactory} based on the
+ * given {@link BackendConfig}.
+ *
+ * @param beCfg the BackendConfig
+ * @return the correctly-chosen AuthorizationFactory
+ *
+ * @throws InternalException if the correct factory could not be determined
+ * e.g. if config flags are invalid
+ */
+ public static AuthorizationFactory authzFactoryFrom(BackendConfig beCfg)
+ throws InternalException {
+ final AuthorizationFactory authzFactory;
+ final String authzFactoryClassName = authzFactoryClassNameFrom(beCfg);
+ try {
+ authzFactory = (AuthorizationFactory)
+ Class.forName(authzFactoryClassName)
+ .getConstructor(BackendConfig.class)
+ .newInstance(beCfg);
+ } catch (Exception e) {
+ throw new InternalException(
+ "Unable to instantiate authorization provider: " + authzFactoryClassName, e);
+ }
+ final AuthorizationConfig authzConfig = authzFactory.getAuthorizationConfig();
+
+ if (!authzConfig.isEnabled()) {
+ // For backward compatibility to keep the existing behavior, when authorization
+ // is not enabled, we need to use a dummy authorization config.
+ LOG.info("Authorization is 'DISABLED'.");
+ return new NoopAuthorizationFactory(beCfg);
+ }
+
+ LOG.info(String.format("Authorization is 'ENABLED' using %s.",
+ authzConfig.getProviderName()));
+ return authzFactory;
+ }
+}
diff --git a/fe/src/test/java/org/apache/impala/common/FrontendTestBase.java b/fe/src/test/java/org/apache/impala/common/FrontendTestBase.java
index 029ddf8..59cd604 100644
--- a/fe/src/test/java/org/apache/impala/common/FrontendTestBase.java
+++ b/fe/src/test/java/org/apache/impala/common/FrontendTestBase.java
@@ -40,7 +40,6 @@ import org.apache.impala.authorization.AuthorizationException;
import org.apache.impala.authorization.AuthorizationFactory;
import org.apache.impala.authorization.AuthorizationManager;
import org.apache.impala.authorization.AuthorizationPolicy;
-import org.apache.impala.authorization.AuthorizationProvider;
import org.apache.impala.authorization.NoopAuthorizationFactory.NoopAuthorizationManager;
import org.apache.impala.authorization.PrivilegeRequest;
import org.apache.impala.authorization.User;
@@ -324,9 +323,7 @@ public class FrontendTestBase extends AbstractFrontendTest {
@Override
public boolean isEnabled() { return true; }
@Override
- public AuthorizationProvider getProvider() {
- return AuthorizationProvider.NOOP;
- }
+ public String getProviderName() { return "noop"; }
@Override
public String getServerName() { return "server1"; }
};
diff --git a/fe/src/test/java/org/apache/impala/util/AuthorizationUtilTest.java b/fe/src/test/java/org/apache/impala/util/AuthorizationUtilTest.java
new file mode 100644
index 0000000..1669a63
--- /dev/null
+++ b/fe/src/test/java/org/apache/impala/util/AuthorizationUtilTest.java
@@ -0,0 +1,94 @@
+// 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.impala.util;
+
+import org.apache.impala.authorization.AuthorizationFactory;
+import org.apache.impala.authorization.ranger.RangerAuthorizationFactory;
+import org.apache.impala.authorization.sentry.SentryAuthorizationFactory;
+import org.apache.impala.service.BackendConfig;
+import org.apache.impala.thrift.TBackendGflags;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class AuthorizationUtilTest {
+ private static TBackendGflags origFlags;
+
+ @BeforeClass
+ public static void setup() {
+ // since some test cases will need to modify the (static)
+ // be flags, we need to save the original values so they
+ // can be restored and not break other tests
+ if (BackendConfig.INSTANCE == null) {
+ BackendConfig.create(new TBackendGflags());
+ }
+ origFlags = BackendConfig.INSTANCE.getBackendCfg();
+ }
+
+ @AfterClass
+ public static void teardown() {
+ BackendConfig.create(origFlags);
+ }
+
+ private static BackendConfig authCfg(String authorization_factory_class,
+ String authorization_provider) {
+ final TBackendGflags stubCfg = new TBackendGflags();
+
+ stubCfg.setAuthorization_factory_class(authorization_factory_class);
+ stubCfg.setAuthorization_provider(authorization_provider);
+ BackendConfig.create(stubCfg);
+ return BackendConfig.INSTANCE;
+ }
+
+ private static BackendConfig authCfg(
+ Class<? extends AuthorizationFactory> authorization_factory_class,
+ String authorization_provider) {
+ return authCfg(authorization_factory_class.getCanonicalName(),
+ authorization_provider);
+ }
+
+ @Test
+ public void testAuthorizationProviderFlag()
+ throws Exception {
+ // Test policy factory selection based on provider
+ assertEquals(SentryAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(authCfg("", "sentry")));
+
+ assertEquals(RangerAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(authCfg("", "ranger")));
+
+ // Policy selection factory takes precedence over provider name
+ assertEquals(SentryAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(
+ authCfg(SentryAuthorizationFactory.class, "ranger")));
+
+ assertEquals(RangerAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(
+ authCfg(RangerAuthorizationFactory.class, "sentry")));
+
+ assertEquals(SentryAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(
+ authCfg(SentryAuthorizationFactory.class, "sentry")));
+
+ assertEquals(RangerAuthorizationFactory.class.getCanonicalName(),
+ AuthorizationUtil.authzFactoryClassNameFrom(
+ authCfg(RangerAuthorizationFactory.class, "ranger")));
+ }
+}
diff --git a/tests/authorization/test_provider.py b/tests/authorization/test_provider.py
new file mode 100644
index 0000000..2e2e7a9
--- /dev/null
+++ b/tests/authorization/test_provider.py
@@ -0,0 +1,77 @@
+# 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.
+#
+# Client tests for SQL statement authorization
+
+import pytest
+import os
+import tempfile
+
+from tests.common.file_utils import assert_file_in_dir_contains
+from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
+
+
+class TestAuthorizationProvider(CustomClusterTestSuite):
+ """
+ Tests for failed authorization_provider flag.
+
+ All test cases in this testsuite
+ are expected to fail cluster startup and will swallow exceptions thrown during
+ setup_method().
+ """
+
+ BAD_FLAG = "foobar"
+ LOG_DIR = tempfile.mkdtemp(prefix="test_provider_", dir=os.getenv("LOG_DIR"))
+ MINIDUMP_PATH = tempfile.mkdtemp()
+
+ @pytest.mark.execute_serially
+ @CustomClusterTestSuite.with_args(
+ impala_log_dir=LOG_DIR,
+ impalad_args="--minidump_path={0}"
+ "--server-name=server1 "
+ "--ranger_service_type=hive "
+ "--ranger_app_id=impala "
+ "--authorization_provider={1}".format(MINIDUMP_PATH, BAD_FLAG),
+ catalogd_args="--minidump_path={0}"
+ "--server-name=server1 "
+ "--ranger_service_type=hive "
+ "--ranger_app_id=impala "
+ "--authorization_provider={1}".format(MINIDUMP_PATH, BAD_FLAG))
+ def test_invalid_provider_flag(self, unique_name):
+ # parse log file for expected exception
+ assert_file_in_dir_contains(TestAuthorizationProvider.LOG_DIR,
+ "InternalException: Could not parse "
+ "authorization_provider flag: {}"
+ .format(TestAuthorizationProvider.BAD_FLAG))
+
+ def setup_method(self, method):
+ # Explicitly override CustomClusterTestSuite.setup_method() to
+ # allow it to exception, since this testsuite is for cases where
+ # startup fails
+ try:
+ super(TestAuthorizationProvider, self).setup_method(method)
+ except Exception:
+ pass
+
+ def teardown_method(self, method):
+ # Explicitly override CustomClusterTestSuite.teardown_method() to
+ # allow it to exception, since it relies on setup_method() having
+ # completed successfully
+ try:
+ super(TestAuthorizationProvider, self).teardown_method(method)
+ except Exception:
+ pass
diff --git a/tests/authorization/test_ranger.py b/tests/authorization/test_ranger.py
index dc33c30..7e14a76 100644
--- a/tests/authorization/test_ranger.py
+++ b/tests/authorization/test_ranger.py
@@ -29,11 +29,9 @@ from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
RANGER_AUTH = ("admin", "admin")
RANGER_HOST = "http://localhost:6080"
IMPALAD_ARGS = "--server-name=server1 --ranger_service_type=hive " \
- "--ranger_app_id=impala --authorization_factory_class=" \
- "org.apache.impala.authorization.ranger.RangerAuthorizationFactory"
+ "--ranger_app_id=impala --authorization_provider=ranger"
CATALOGD_ARGS = "--server-name=server1 --ranger_service_type=hive " \
- "--ranger_app_id=impala --authorization_factory_class=" \
- "org.apache.impala.authorization.ranger.RangerAuthorizationFactory"
+ "--ranger_app_id=impala --authorization_provider=ranger"
class TestRanger(CustomClusterTestSuite):