You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2022/06/06 08:47:37 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #2469] Support RangerDefaultAuditHandler for AuthZ module

This is an automated email from the ASF dual-hosted git repository.

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new c56a13afb [KYUUBI #2469] Support RangerDefaultAuditHandler for AuthZ module
c56a13afb is described below

commit c56a13afb77c01501336a05004c0605a6469f350
Author: jason <ji...@163.com>
AuthorDate: Mon Jun 6 16:47:28 2022 +0800

    [KYUUBI #2469] Support RangerDefaultAuditHandler for AuthZ module
    
    ### _Why are the changes needed?_
    
    Add Ranger Audit to record audit information about database access.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [x] Add screenshots for manual tests if appropriate
    ![1653881561(1)](https://user-images.githubusercontent.com/19518068/170912366-1b59eabc-4754-4445-836b-d9344b5fbee7.png)
    
    - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #2778 from MLikeWater/Kyuubi-2469-AddRangerAudit.
    
    Closes #2469
    
    7e06ae1f [jason] [Improvement] Support RangerDefaultAuditHandler for AuthZ module
    
    Authored-by: jason <ji...@163.com>
    Signed-off-by: Kent Yao <ya...@apache.org>
---
 .../spark/authz/ranger/RuleAuthorization.scala     |  9 ++++----
 .../authz/ranger/SparkRangerAuditHandler.scala     | 26 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RuleAuthorization.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RuleAuthorization.scala
index 4ed1fadc3..0449a5034 100644
--- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RuleAuthorization.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RuleAuthorization.scala
@@ -37,6 +37,7 @@ class RuleAuthorization(spark: SparkSession) extends Rule[LogicalPlan] {
 object RuleAuthorization {
 
   def checkPrivileges(spark: SparkSession, plan: LogicalPlan): Unit = {
+    val auditHandler = new SparkRangerAuditHandler
     val ugi = getAuthzUgi(spark.sparkContext)
     val opType = OperationType(plan.nodeName)
     val (inputs, outputs) = PrivilegesBuilder.build(plan)
@@ -67,15 +68,15 @@ object RuleAuthorization {
           resource.getColumns.foreach { col =>
             val cr = AccessResource(COLUMN, resource.getDatabase, resource.getTable, col)
             val req = AccessRequest(cr, ugi, opType, request.accessType)
-            verify(req)
+            verify(req, auditHandler)
           }
-        case _ => verify(request)
+        case _ => verify(request, auditHandler)
       }
     }
   }
 
-  private def verify(req: AccessRequest): Unit = {
-    val ret = SparkRangerAdminPlugin.isAccessAllowed(req, null)
+  private def verify(req: AccessRequest, auditHandler: SparkRangerAuditHandler): Unit = {
+    val ret = SparkRangerAdminPlugin.isAccessAllowed(req, auditHandler)
     if (ret != null && !ret.getIsAllowed) {
       throw new RuntimeException(
         s"Permission denied: user [${req.getUser}] does not have [${req.getAccessType}] privilege" +
diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/SparkRangerAuditHandler.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/SparkRangerAuditHandler.scala
new file mode 100644
index 000000000..5eaae8527
--- /dev/null
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/SparkRangerAuditHandler.scala
@@ -0,0 +1,26 @@
+/*
+ * 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.kyuubi.plugin.spark.authz.ranger
+
+import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler
+
+class SparkRangerAuditHandler extends RangerDefaultAuditHandler {
+
+  // Implementing meaningfully audit functions
+
+}