Skip to content

Commit

Permalink
Disable spark script transformation in Authz
Browse files Browse the repository at this point in the history
  • Loading branch information
zml1206 committed Nov 29, 2023
1 parent 5761e83 commit cfea484
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.kyuubi.plugin.spark.authz.ranger

import org.apache.spark.sql.SparkSessionExtensions

import org.apache.kyuubi.plugin.spark.authz.rule.{RuleEliminateMarker, RuleEliminatePermanentViewMarker, RuleEliminateTypeOf}
import org.apache.kyuubi.plugin.spark.authz.rule.{AuthzUnsupportedOperationsCheck, RuleEliminateMarker, RuleEliminatePermanentViewMarker, RuleEliminateTypeOf}
import org.apache.kyuubi.plugin.spark.authz.rule.config.AuthzConfigurationChecker
import org.apache.kyuubi.plugin.spark.authz.rule.datamasking.{RuleApplyDataMaskingStage0, RuleApplyDataMaskingStage1}
import org.apache.kyuubi.plugin.spark.authz.rule.expression.RuleApplyTypeOfMarker
Expand All @@ -45,6 +45,7 @@ class RangerSparkExtension extends (SparkSessionExtensions => Unit) {

override def apply(v1: SparkSessionExtensions): Unit = {
v1.injectCheckRule(AuthzConfigurationChecker)
v1.injectCheckRule(_ => new AuthzUnsupportedOperationsCheck)
v1.injectResolutionRule(_ => new RuleReplaceShowObjectCommands())
v1.injectResolutionRule(_ => new RuleApplyPermanentViewMarker())
v1.injectResolutionRule(_ => new RuleApplyTypeOfMarker())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.rule

import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, ScriptTransformation}

import org.apache.kyuubi.plugin.spark.authz.AccessControlException

class AuthzUnsupportedOperationsCheck extends (LogicalPlan => Unit) {
override def apply(plan: LogicalPlan): Unit = plan foreach {
case _: ScriptTransformation =>
throw new AccessControlException("Script transformation is not allowed")
case _ =>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.rule

import org.scalatest.BeforeAndAfterAll
// scalastyle:off
import org.scalatest.funsuite.AnyFunSuite

import org.apache.kyuubi.plugin.spark.authz.{AccessControlException, SparkSessionProvider}

class AuthzUnsupportedOperationsCheckSuite extends AnyFunSuite with SparkSessionProvider
with BeforeAndAfterAll {
// scalastyle:on

override protected val catalogImpl: String = "in-memory"
override def afterAll(): Unit = {
spark.stop()
super.afterAll()
}

test("disable script transformation") {
val extension = new AuthzUnsupportedOperationsCheck
val p1 = sql("SELECT TRANSFORM('') USING 'ls /'").queryExecution.analyzed
intercept[AccessControlException](extension.apply(p1))
}
}

0 comments on commit cfea484

Please sign in to comment.