Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5630][Authz] Support path check of LoadDataCommand #5632

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,12 @@
} ],
"opType" : "LOAD",
"queryDescs" : [ ],
"uriDescs" : [ ]
"uriDescs" : [ {
"fieldName" : "path",
"fieldExtractor" : "StringURIExtractor",
"actionTypeDesc" : null,
"isInput" : true
} ]
}, {
"classname" : "org.apache.spark.sql.execution.command.RefreshTableCommand",
"tableDescs" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,17 +1430,24 @@ class HiveCatalogPrivilegeBuilderSuite extends PrivilegesBuilderSuite {
.queryExecution.analyzed
val (in, out, operationType) = PrivilegesBuilder.build(plan, spark)
assert(operationType === LOAD)
assert(in.isEmpty)

assert(out.size === 1)
val po0 = out.head
assert(po0.actionType === PrivilegeObjectActionType.INSERT_OVERWRITE)
assert(po0.privilegeObjectType === PrivilegeObjectType.TABLE_OR_VIEW)
assertEqualsIgnoreCase(reusedDb)(po0.dbname)
assert(po0.objectName equalsIgnoreCase tableName.split("\\.").last)
assert(in.size === 1)
val po0 = in.head
assert(po0.actionType === PrivilegeObjectActionType.OTHER)
assert(po0.privilegeObjectType === PrivilegeObjectType.DFS_URL)
assert(po0.dbname === dataPath)
assert(po0.objectName === null)
assert(po0.columns.isEmpty)
checkTableOwner(po0)
val accessType0 = ranger.AccessType(po0, operationType, isInput = false)

assert(out.size === 1)
val po1 = out.head
assert(po1.actionType === PrivilegeObjectActionType.INSERT_OVERWRITE)
assert(po1.privilegeObjectType === PrivilegeObjectType.TABLE_OR_VIEW)
assertEqualsIgnoreCase(reusedDb)(po1.dbname)
assert(po1.objectName equalsIgnoreCase tableName.split("\\.").last)
assert(po1.columns.isEmpty)
checkTableOwner(po1)
val accessType0 = ranger.AccessType(po1, operationType, isInput = false)
assert(accessType0 === AccessType.UPDATE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ object TableCommands extends CommandSpecs[TableCommandSpec] {
fieldName = "table",
columnDesc = Some(columnDesc),
actionTypeDesc = Some(actionTypeDesc))
TableCommandSpec(cmd, Seq(tableDesc), "LOAD")
val uriDesc = UriDesc("path", classOf[StringURIExtractor], isInput = true)
TableCommandSpec(cmd, Seq(tableDesc), LOAD, uriDescs = Seq(uriDesc))
}

val RefreshTable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,4 +1133,26 @@ class HiveCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
}
}
}

test("LoadDataCommand") {
val db1 = defaultDb
val table1 = "table1"
withSingleCallEnabled {
withTempDir { path =>
withCleanTmpResources(Seq((s"$db1.$table1", "table"))) {
doAs(admin, sql(s"CREATE TABLE IF NOT EXISTS $db1.$table1 (id int, scope int)"))
val loadDataSql =
s"""
|LOAD DATA LOCAL INPATH '$path'
|OVERWRITE INTO TABLE $db1.$table1
|""".stripMargin
doAs(admin, sql(loadDataSql).explain(true))
interceptContains[AccessControlException](
doAs(someone, sql(loadDataSql).explain(true)))(
s"does not have [select] privilege on " +
s"[[$path, $path/]]")
}
}
}
}
}
Loading