Skip to content

Commit

Permalink
[KYUUBI apache#5503][AUTHZ] Auth check should not check Subquery sinc…
Browse files Browse the repository at this point in the history
…e passed subquery from OptimizeSubqueries
  • Loading branch information
AngersZhuuuu committed Oct 23, 2023
1 parent 1224b0d commit abbbc10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scala.collection.mutable.ArrayBuffer

import org.apache.ranger.plugin.policyengine.RangerAccessRequest
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Subquery}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.catalyst.trees.TreeNodeTag

Expand All @@ -33,6 +33,7 @@ import org.apache.kyuubi.plugin.spark.authz.util.AuthZUtils._
class RuleAuthorization(spark: SparkSession) extends Rule[LogicalPlan] {
override def apply(plan: LogicalPlan): LogicalPlan = {
plan match {
case subquery: Subquery => subquery
case plan if isAuthChecked(plan) => plan // do nothing if checked privileges already.
case p => checkPrivileges(spark, p)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,33 @@ class HiveCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
}
}
}

test("[KYUUBI #5503][AUTHZ] Auth check should not check Subquery") {
val db1 = defaultDb
val table1 = "table1"
val table2 = "table2"
val view1 = "view1"
withSingleCallEnabled {
withCleanTmpResources(
Seq((s"$db1.$table1", "table"), (s"$db1.$table2", "table"), (s"$db1.$view1", "view"))) {
doAs(admin, sql(s"CREATE TABLE IF NOT EXISTS $db1.$table1 (id int, scope int)"))
doAs(admin, sql(s"CREATE TABLE IF NOT EXISTS $db1.$table2 (id int, age int)"))
interceptContains[AccessControlException](
doAs(
someone,
sql(
s"""
|SELECT t1.id, age
|FROM $db1.$table1 t1,
|LATERAL (
| SELECT *
| FROM $db1.$table2 t2
| WHERE t1.id = t2.id
|)
|""".stripMargin).show()))(
s"does not have [select] privilege on " +
s"[$db1/$table1/id,$db1/$table2/age,$db1/$table2/id]")
}
}
}
}

0 comments on commit abbbc10

Please sign in to comment.