You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2023/01/06 13:52:39 UTC
[kyuubi] branch master updated: [KYUUBI #4114] [Authz] [Bug] Correct `getRangerConf` for Ranger 2.0 and below
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 79a3ff12e [KYUUBI #4114] [Authz] [Bug] Correct `getRangerConf` for Ranger 2.0 and below
79a3ff12e is described below
commit 79a3ff12e1654882d2eb1deed98b9afb2d6cf91a
Author: liangbowen <li...@gf.com.cn>
AuthorDate: Fri Jan 6 21:52:27 2023 +0800
[KYUUBI #4114] [Authz] [Bug] Correct `getRangerConf` for Ranger 2.0 and below
### _Why are the changes needed?_
- To fix `RuntimeException` when executing `getRangerConf` with Ranger 2.0 and below. Previously `getRangerConf` method tries to get config in Ranger 2.1+ way via `invoke` first and relies on the `NoSuchMethodException` to turn to Ranger 2.0 way , but `invoke` of `AuthzUtils` actually throws `RuntimeException` instead of `NoSuchMethodException` which makes `getRangerConf` miss the back-up Ranger 2.0 way.
- change getRangerConf to use added `isRanger21orGreater` in AuthZUtils to determine the way of getting config from the ranger plugin
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #4114 from bowenliang123/fix-ranger-getconf.
Closes #4114
d04918b1 [liangbowen] change getRangerConf to use added `isRanger21orGreater` in AuthZUtils to determine the way of getting config from ranger plugin
Authored-by: liangbowen <li...@gf.com.cn>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../kyuubi/plugin/spark/authz/util/AuthZUtils.scala | 18 ++++++++++++++++++
.../plugin/spark/authz/util/RangerConfigProvider.scala | 14 ++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/AuthZUtils.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/AuthZUtils.scala
index d3cf9a0ba..5773e1c93 100644
--- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/AuthZUtils.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/AuthZUtils.scala
@@ -27,6 +27,7 @@ import scala.util.{Failure, Success, Try}
import org.apache.commons.lang3.StringUtils
import org.apache.hadoop.security.UserGroupInformation
+import org.apache.ranger.plugin.service.RangerBasePlugin
import org.apache.spark.{SPARK_VERSION, SparkContext}
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, View}
@@ -86,6 +87,13 @@ private[authz] object AuthZUtils {
method.invoke(obj, values: _*)
}
+ def invokeStaticAs[T](
+ obj: Class[_],
+ methodName: String,
+ args: (Class[_], AnyRef)*): T = {
+ invokeStatic(obj, methodName, args: _*).asInstanceOf[T]
+ }
+
/**
* Get the active session user
* @param spark spark context instance
@@ -117,6 +125,16 @@ private[authz] object AuthZUtils {
}
}
+ lazy val isRanger21orGreater: Boolean = {
+ try {
+ classOf[RangerBasePlugin].getConstructor(classOf[String], classOf[String], classOf[String])
+ true
+ } catch {
+ case _: NoSuchMethodException =>
+ false
+ }
+ }
+
def isSparkVersionAtMost(targetVersionString: String): Boolean = {
SemanticVersion(SPARK_VERSION).isVersionAtMost(targetVersionString)
}
diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/RangerConfigProvider.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/RangerConfigProvider.scala
index 5919dde31..83fe048e6 100644
--- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/RangerConfigProvider.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/util/RangerConfigProvider.scala
@@ -34,16 +34,14 @@ trait RangerConfigProvider {
* for Ranger 2.0 and below
*/
def getRangerConf: Configuration = {
- try {
+ if (isRanger21orGreater) {
// for Ranger 2.1+
invokeAs[Configuration](this, "getConfig")
- } catch {
- case _: NoSuchMethodException =>
- // for Ranger 2.0 and below
- invokeStatic(
- Class.forName("org.apache.ranger.authorization.hadoop.config.RangerConfiguration"),
- "getInstance")
- .asInstanceOf[Configuration]
+ } else {
+ // for Ranger 2.0 and below
+ invokeStaticAs[Configuration](
+ Class.forName("org.apache.ranger.authorization.hadoop.config.RangerConfiguration"),
+ "getInstance")
}
}
}