Skip to content

Commit 448f91f

Browse files
committed
Changes to create SPNego principal
1 parent 7f9ec19 commit 448f91f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import scala.collection.JavaConverters._
2525

2626
import org.apache.commons.logging.Log
2727
import org.apache.hadoop.hive.conf.HiveConf
28+
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
2829
import org.apache.hadoop.hive.shims.Utils
2930
import org.apache.hadoop.security.UserGroupInformation
3031
import org.apache.hive.service.{AbstractService, Service, ServiceException}
@@ -47,6 +48,7 @@ private[hive] class SparkSQLCLIService(hiveServer: HiveServer2, sqlContext: SQLC
4748
setSuperField(this, "sessionManager", sparkSqlSessionManager)
4849
addService(sparkSqlSessionManager)
4950
var sparkServiceUGI: UserGroupInformation = null
51+
var httpUGI: UserGroupInformation = null
5052

5153
if (UserGroupInformation.isSecurityEnabled) {
5254
try {
@@ -57,7 +59,24 @@ private[hive] class SparkSQLCLIService(hiveServer: HiveServer2, sqlContext: SQLC
5759
case e @ (_: IOException | _: LoginException) =>
5860
throw new ServiceException("Unable to login to kerberos with given principal/keytab", e)
5961
}
60-
}
62+
63+
// Also try creating a UGI object for the SPNego principal
64+
val principal = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_PRINCIPAL)
65+
val keyTabFile = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_KEYTAB)
66+
if (principal.isEmpty() || keyTabFile.isEmpty()) {
67+
getAncestorField[Log](this, 3, "LOG").info(
68+
s"SPNego httpUGI not created, spNegoPrincipal: $principal , ketabFile: $keyTabFile")
69+
} else {
70+
try {
71+
httpUGI = HiveAuthFactory.loginFromSpnegoKeytabAndReturnUGI(hiveConf)
72+
setSuperField(this, "httpUGI", httpUGI)
73+
getAncestorField[Log](this, 3, "LOG").info("SPNego httpUGI successfully created.")
74+
} catch {
75+
case e : IOException =>
76+
getAncestorField[Log](this, 3, "LOG").warn(s"SPNego httpUGI creation failed: $e")
77+
}
78+
}
79+
}
6180

6281
initCompositeService(hiveConf)
6382
}

0 commit comments

Comments
 (0)