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 2026/10/16 05:56:23 UTC
(kyuubi) branch master updated: [KYUUBI #7774][AUTHZ] Resolve the table owner for v1 (Hive) tables
This is an automated email from the ASF dual-hosted git repository.
pan3793 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 e130c3e288 [KYUUBI #7774][AUTHZ] Resolve the table owner for v1 (Hive) tables
e130c3e288 is described below
commit e130c3e2889c900afa512aa52768bdc4ac5fef08
Author: Attila Zsolt Piros <pi...@gmail.com>
AuthorDate: Fri Oct 16 13:56:13 2026 +0800
[KYUUBI #7774][AUTHZ] Resolve the table owner for v1 (Hive) tables
### Why are the changes needed?
Granting ownership privileges needs the table owner on the privilege object, but it came back empty for Hive tables.
`TableExtractor.getOwner` assumed its argument wraps a connector `Table` in a `table` member. `V1Table`, which `V2SessionCatalog.loadTable` returns for a session-catalog (Hive) table, carries the properties itself and has no `table` accessor, so the lookup threw, was swallowed by the surrounding `catch`, and the owner was lost.
`DROP TABLE` on a Hive table reaches exactly this path. With `spark.sql.legacy.useV1Command` at its default of `false` the plan is not downgraded to `DropTableCommand`; it stays as the v2 `DropTable(ResolvedIdentifier(...))`, whose first table descriptor resolves the owner through `loadTable`.
- `getOwner` picks the properties holder -- `V1Table` itself, or the wrapped table otherwise -- and then reads the owner once, instead of duplicating the lookup.
- Empty owners are filtered out. `V1Table.addV2TableProperties` sets `PROP_OWNER` unconditionally, so a table with no owner yielded `Some("")`. The other owner lookups in this file already filter on `nonEmpty`.
- A debug line when the catalog lookup fails, so a genuinely absent owner can be told apart from a failed load.
`V1Table` is `private[sql]`, so it is matched by class name; it cannot be referenced as a type from this package.
### How was this patch tested?
A new test in `HiveCatalogRangerSparkExtensionSuite` asserts the owner on the privilege object built for `DROP TABLE`. It fails without this change: the owner is `None`, because `getOwner` throws on a `V1Table`. The test asserts the owner value rather than `isDefined` -- since `PROP_OWNER` is always set, `isDefined` would also hold for an empty owner.
### Was this patch assisted by generative AI tooling?
Assisted-by: Claude Opus 5
Closes #7775 from attilapiros/7774.
Closes #7774
304aafdfd [attilapiros] renaming ConnectorTable to V2Table
86d9108b3 [attilapiros] Applying review comments
389b555c0 [attilapiros] [KYUUBI #7774][AUTHZ] Resolve the table owner for v1 (Hive) tables
Authored-by: Attila Zsolt Piros <pi...@gmail.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../plugin/spark/authz/serde/tableExtractors.scala | 21 +++++++++++++++------
.../authz/ranger/RangerSparkExtensionSuite.scala | 14 ++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala
index 3ef2172d67..dd3230758e 100644
--- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala
@@ -26,10 +26,11 @@ import org.apache.spark.sql.catalyst.{InternalRow, TableIdentifier}
import org.apache.spark.sql.catalyst.catalog.CatalogTable
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias}
-import org.apache.spark.sql.connector.catalog.Identifier
+import org.apache.spark.sql.connector.catalog.{Identifier, Table => V2Table}
import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation
import org.apache.spark.sql.types.DataType
import org.apache.spark.unsafe.types.UTF8String
+import org.slf4j.LoggerFactory
import org.apache.kyuubi.plugin.spark.authz.util.AuthZUtils._
import org.apache.kyuubi.plugin.spark.authz.util.PathIdentifier._
@@ -42,6 +43,8 @@ import org.apache.kyuubi.util.reflect.ReflectUtils._
trait TableExtractor extends ((SparkSession, AnyRef) => Option[Table]) with Extractor
object TableExtractor {
+ final private val LOG = LoggerFactory.getLogger(getClass)
+
val tableExtractors: Map[String, TableExtractor] = {
loadExtractorsToMap[TableExtractor]
}
@@ -52,10 +55,14 @@ object TableExtractor {
* @return owner
*/
def getOwner(v: AnyRef): Option[String] = {
- // org.apache.spark.sql.connector.catalog.Table
- val table = invokeAs[AnyRef](v, "table")
- val properties = invokeAs[JMap[String, String]](table, "properties").asScala
- properties.get("owner")
+ val maybeTable = v match {
+ // It holds the properties itself, rather than wrapping another table.
+ case _: V2Table => v
+ case _ => invokeAs[AnyRef](v, "table")
+ }
+ val properties = invokeAs[JMap[String, String]](maybeTable, "properties").asScala
+ // V1Table always sets the owner property, using "" when the table has no owner
+ properties.get("owner").filter(_.nonEmpty)
}
def getOwner(spark: SparkSession, catalogName: String, tableIdent: AnyRef): Option[String] = {
@@ -69,7 +76,9 @@ object TableExtractor {
getOwner(table)
} catch {
// Exception may occur due to invalid reflection or table not found
- case _: Exception => None
+ case e: Exception =>
+ LOG.debug("Failed to resolve the owner of {}.{}", catalogName, tableIdent, e)
+ None
}
}
diff --git a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
index 4c04cd6843..debef4e458 100644
--- a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
@@ -37,6 +37,7 @@ import org.apache.kyuubi.plugin.lineage.Lineage
import org.apache.kyuubi.plugin.lineage.helper.SparkSQLLineageParseHelper
import org.apache.kyuubi.plugin.spark.authz.{AccessControlException, SparkSessionProvider}
import org.apache.kyuubi.plugin.spark.authz.MysqlContainerEnv
+import org.apache.kyuubi.plugin.spark.authz.PrivilegesBuilder
import org.apache.kyuubi.plugin.spark.authz.RangerTestNamespace._
import org.apache.kyuubi.plugin.spark.authz.RangerTestUsers._
import org.apache.kyuubi.plugin.spark.authz.rule.Authorization.KYUUBI_AUTHZ_TAG
@@ -551,6 +552,19 @@ class HiveCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
override protected val extraSparkConf: SparkConf = new SparkConf()
.set("spark.kyuubi.authz.udf.enabled", "true")
+ test("resource owner must be set for DropTable on v1 (Hive) tables") {
+ val table = "DropTable"
+ withCleanTmpResources(Seq((table, "table"))) {
+ doAs(admin, sql(s"CREATE TABLE $table (i int)"))
+ val parsed = spark.sessionState.sqlParser.parsePlan(s"DROP TABLE $table")
+ val plan = spark.sessionState.executePlan(parsed).analyzed
+ val (_, outputs, _) = PrivilegesBuilder.build(plan, spark)
+ assert(outputs.size === 1)
+ val po = outputs.head
+ assert(po.owner === Some(defaultTableOwner))
+ }
+ }
+
test("table stats must be specified") {
val table = "hive_src"
withCleanTmpResources(Seq((table, "table"))) {