Skip to content

Commit e70c475

Browse files
d-popkovekrivokonmapr
authored andcommitted
MapR [SPARK-1075] Ranger hive authorizer should not be copied from hive's hive-site.xml to spark's one (apache#1029)
1 parent 55017f5 commit e70c475

File tree

4 files changed

+202
-7
lines changed

4 files changed

+202
-7
lines changed

bin/configure.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,7 @@ EOF
316316
cp $SPARK_HOME/conf/hive-site.xml.security.template $SPARK_HOME/conf/hive-site.xml
317317
else
318318
if ! grep -q \>hive.server2.thrift.sasl.qop\< "$SPARK_HOME/conf/hive-site.xml"; then
319-
CONF="</configuration>"
320-
PROPERTIES="<property>\n<name>hive.server2.thrift.sasl.qop</name>\n<value>auth-conf</value>\n</property>\n</configuration>"
321-
sed -i "s~$CONF~$PROPERTIES~g" $SPARK_HOME/conf/hive-site.xml
319+
java -cp $SPARK_HOME'/jars/*' org.apache.spark.editor.HiveSiteEditor create hive.server2.thrift.sasl.qop=auth-conf
322320
fi
323321
fi
324322

@@ -354,9 +352,7 @@ function configureOnHive() {
354352
fi
355353
fi
356354
if [ -f $SPARK_HOME/conf/hive-site.xml ] ; then
357-
TEZ_PROP_VALUE="<value>tez</value>"
358-
MR_PROP_VALUE="<value>mr</value>"
359-
sed -i "s~$TEZ_PROP_VALUE~$MR_PROP_VALUE~g" $SPARK_HOME/conf/hive-site.xml
355+
java -cp $SPARK_HOME'/jars/*' org.apache.spark.editor.HiveSiteEditor replace hive.security.authorization.manager=org.apache.hadoop.hive.ql.security.authorization.plugin.fallback.FallbackHiveAuthorizerFactory hive.execution.engine=mr
360356
fi
361357
}
362358

common/hive-site-editor/pom.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.spark</groupId>
24+
<artifactId>spark-parent_2.12</artifactId>
25+
<version>3.3.0.0-eep-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>hive-site-editor_2.12</artifactId>
30+
<packaging>jar</packaging>
31+
<name>Hive Site Editor</name>
32+
<url>http://spark.apache.org/</url>
33+
<properties>
34+
<sbt.project.name>hive-site-editor</sbt.project.name>
35+
</properties>
36+
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.scala-lang</groupId>
41+
<artifactId>scala-library</artifactId>
42+
<version>${scala.version}</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.scala-lang.modules</groupId>
47+
<artifactId>scala-xml_${scala.binary.version}</artifactId>
48+
<version>${scala.xml.version}</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.apache.commons</groupId>
53+
<artifactId>commons-lang3</artifactId>
54+
<version>${commons-lang3.version}</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
</dependencies>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-dependency-plugin</artifactId>
64+
<executions>
65+
<!-- When using SPARK_PREPEND_CLASSES Spark classes compiled locally don't use
66+
shaded deps. So here we store jars in their original form which are added
67+
when the classpath is computed. -->
68+
<execution>
69+
<id>copy-dependencies</id>
70+
<phase>package</phase>
71+
<goals>
72+
<goal>copy-dependencies</goal>
73+
</goals>
74+
<configuration>
75+
<outputDirectory>${project.build.directory}</outputDirectory>
76+
<overWriteReleases>false</overWriteReleases>
77+
<overWriteSnapshots>false</overWriteSnapshots>
78+
<overWriteIfNewer>true</overWriteIfNewer>
79+
<useSubDirectoryPerType>true</useSubDirectoryPerType>
80+
<includeArtifactIds>
81+
commons-lang3
82+
scala-xml_2.12
83+
</includeArtifactIds>
84+
<silent>true</silent>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
</project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.editor
19+
20+
import org.apache.commons.lang3.StringUtils
21+
22+
import java.io.{File, FileOutputStream}
23+
import scala.xml._
24+
25+
26+
object HiveSiteEditor {
27+
private val hiveSitePath: String = {
28+
val sparkVersionSource = scala.io.Source.fromFile("/opt/mapr/spark/sparkversion")
29+
val sparkVersion = sparkVersionSource.getLines().mkString
30+
sparkVersionSource.close()
31+
s"/opt/mapr/spark/spark-${sparkVersion}/conf/hive-site.xml"
32+
}
33+
34+
private val xml: Elem = XML.loadFile(hiveSitePath)
35+
private val property: NodeSeq = xml \ "property"
36+
private val properties = property.map(toProperty)
37+
private val xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?><configuration>\n"
38+
39+
case class Property(name: String, value: String, description: String)
40+
41+
def main(args: Array[String]): Unit = {
42+
if (args(0).equals("delete")) save(delete(args))
43+
else if (args(0).equals("create")) save(create(args))
44+
else if (args(0).equals("replace")) save(replace(args))
45+
else throw new IllegalArgumentException("Need to set operation name as firs argument: create | replace | delete")
46+
}
47+
48+
// create name=value name1=value1 ...
49+
def create(args: Array[String]): Seq[Property] = {
50+
val inputProps = parsePropertiesFromArgs(args, "create")
51+
val replacedProps = properties.map(p => {
52+
val i = inputProps.indexWhere(_.name.equals(p.name))
53+
if (i >= 0) Property(name = inputProps(i).name, value = inputProps(i).value, description = p.description) else p
54+
})
55+
val create = inputProps.map(np => {
56+
val i = replacedProps.indexWhere(_.name.equals(np.name))
57+
if (i == -1) Property(name = np.name, value = np.value, description = "") else Property("", "", "")
58+
}).filterNot(_.name.equals(""))
59+
replacedProps ++ create
60+
}
61+
62+
// replace name=value name1=value1 ...
63+
def replace(args: Array[String]): Seq[Property] = {
64+
val inputProps = parsePropertiesFromArgs(args, "replace")
65+
properties.map(p => {
66+
val i = inputProps.indexWhere(_.name.equals(p.name))
67+
if (i >= 0) Property(name = inputProps(i).name, value = inputProps(i).value, description = p.description) else p
68+
})
69+
}
70+
71+
// delete name name1 ...
72+
def delete(args: Array[String]): Seq[Property] = {
73+
property.filterNot(p => StringUtils.equalsAnyIgnoreCase((p \ "name").text, args: _*))
74+
.map(toProperty)
75+
}
76+
77+
def save(properties: Seq[Property]): Unit = {
78+
val fos = new FileOutputStream(new File(hiveSitePath))
79+
Console.withOut(fos) {
80+
println(xmlHeader)
81+
properties.map(toXml).foreach(println)
82+
println("</configuration>")
83+
}
84+
}
85+
86+
def parsePropertiesFromArgs(args: Array[String], methodName: String): Seq[Property] = {
87+
val argsMap = args.filterNot(_.equals(methodName)).map(_.split("="))
88+
.map(arr => arr(0) -> arr(1)).toMap
89+
argsMap.map(x => Property(x._1, x._2, "")).toSeq
90+
}
91+
92+
def toProperty(node: Node): Property = {
93+
val name = (node \ "name").text
94+
val value = (node \ "value").text
95+
val description = (node \ "description").text
96+
Property(name, value, description)
97+
}
98+
99+
def toXml(p: Property): Node = {
100+
<property>
101+
<name>{p.name}</name>
102+
<value>{p.value}</value>
103+
<description>{p.description}</description>
104+
</property>
105+
}
106+
107+
}

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<commons.collections.version>3.2.2</commons.collections.version>
160160
<commons.collections4.version>4.4</commons.collections4.version>
161161
<scala.version>2.12.15</scala.version>
162+
<scala.xml.version>1.2.0</scala.xml.version>
162163
<scala.binary.version>2.12</scala.binary.version>
163164
<scalatest-maven-plugin.version>2.0.2</scalatest-maven-plugin.version>
164165
<!--
@@ -1074,7 +1075,7 @@
10741075
<dependency>
10751076
<groupId>org.scala-lang.modules</groupId>
10761077
<artifactId>scala-xml_${scala.binary.version}</artifactId>
1077-
<version>1.2.0</version>
1078+
<version>${scala.xml.version}</version>
10781079
</dependency>
10791080
<dependency>
10801081
<groupId>org.scala-lang</groupId>

0 commit comments

Comments
 (0)