Skip to content

Commit bd37509

Browse files
tgravescspwendell
authored andcommitted
Spark 1490 Add kerberos support to the HistoryServer
Here I've added the ability for the History server to login from a kerberos keytab file so that the history server can be run as a super user and stay up for along period of time while reading the history files from HDFS. Author: Thomas Graves <[email protected]> Closes #513 from tgravescs/SPARK-1490 and squashes the following commits: e204a99 [Thomas Graves] remove extra logging 5418daa [Thomas Graves] fix typo in config 0076b99 [Thomas Graves] Update docs 4d76545 [Thomas Graves] SPARK-1490 Add kerberos support to the HistoryServer
1 parent 78a49b2 commit bd37509

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class SparkHadoopUtil {
7575

7676
def getSecretKeyFromUserCredentials(key: String): Array[Byte] = { null }
7777

78+
def loginUserFromKeytab(principalName: String, keytabFilename: String) {
79+
UserGroupInformation.loginUserFromKeytab(principalName, keytabFilename)
80+
}
81+
7882
}
7983

8084
object SparkHadoopUtil {

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import scala.collection.mutable
2222
import org.apache.hadoop.fs.{FileStatus, Path}
2323

2424
import org.apache.spark.{Logging, SecurityManager, SparkConf}
25+
import org.apache.spark.deploy.SparkHadoopUtil
2526
import org.apache.spark.scheduler._
2627
import org.apache.spark.ui.{WebUI, SparkUI}
2728
import org.apache.spark.ui.JettyUtils._
@@ -257,6 +258,7 @@ object HistoryServer {
257258
val STATIC_RESOURCE_DIR = SparkUI.STATIC_RESOURCE_DIR
258259

259260
def main(argStrings: Array[String]) {
261+
initSecurity()
260262
val args = new HistoryServerArguments(argStrings)
261263
val securityManager = new SecurityManager(conf)
262264
val server = new HistoryServer(args.logDir, securityManager, conf)
@@ -266,6 +268,20 @@ object HistoryServer {
266268
while(true) { Thread.sleep(Int.MaxValue) }
267269
server.stop()
268270
}
271+
272+
def initSecurity() {
273+
// If we are accessing HDFS and it has security enabled (Kerberos), we have to login
274+
// from a keytab file so that we can access HDFS beyond the kerberos ticket expiration.
275+
// As long as it is using Hadoop rpc (hdfs://), a relogin will automatically
276+
// occur from the keytab.
277+
if (conf.getBoolean("spark.history.kerberos.enabled", false)) {
278+
// if you have enabled kerberos the following 2 params must be set
279+
val principalName = conf.get("spark.history.kerberos.principal")
280+
val keytabFilename = conf.get("spark.history.kerberos.keytab")
281+
SparkHadoopUtil.get.loginUserFromKeytab(principalName, keytabFilename)
282+
}
283+
}
284+
269285
}
270286

271287

docs/monitoring.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ represents an application's event logs. This creates a web interface at
9191
The port to which the web interface of the history server binds.
9292
</td>
9393
</tr>
94+
<tr>
95+
<td>spark.history.kerberos.enabled</td>
96+
<td>false</td>
97+
<td>
98+
Indicates whether the history server should use kerberos to login. This is useful
99+
if the history server is accessing HDFS files on a secure Hadoop cluster. If this is
100+
true it looks uses the configs <code>spark.history.kerberos.principal</code> and
101+
<code>spark.history.kerberos.keytab</code>.
102+
</td>
103+
</tr>
104+
<tr>
105+
<td>spark.history.kerberos.principal</td>
106+
<td>(none)</td>
107+
<td>
108+
Kerberos principal name for the History Server.
109+
</td>
110+
</tr>
111+
<tr>
112+
<td>spark.history.kerberos.keytab</td>
113+
<td>(none)</td>
114+
<td>
115+
Location of the kerberos keytab file for the History Server.
116+
</td>
117+
</tr>
94118
</table>
95119

96120
Note that in all of these UIs, the tables are sortable by clicking their headers,

0 commit comments

Comments
 (0)