-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-10181][SQL] Do kerberos login for credentials during hive client initialization #9272
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
59253b3
SPARK-10181 UserGroupInformation class needs to be shared for login c…
yolandagao 3e79e94
Merge remote branch 'upstream/master'
yolandagao 9efa819
Revert "SPARK-10181 UserGroupInformation class needs to be shared for…
yolandagao 7934585
Merge remote branch 'upstream/master'
yolandagao 30a7d05
SPARK-10181 Do kerberos login for credentials in hive client initiali…
yolandagao 836bb8b
Merge remote branch 'upstream/master'
yolandagao 7ec246f
Merge remote branch 'upstream/master'
yolandagao 1fe7593
SPARK-10181 Do kerberos login for credentials during hive client init…
yolandagao 3f0fee9
Merge remote branch 'upstream/master'
yolandagao 06ee550
Merge remote branch 'upstream/master'
yolandagao 906b3cb
SPARK-10181 Do kerberos login for credentials during hive client init…
yolandagao ef927e7
Merge remote branch 'upstream/master'
yolandagao 7d09f5d
SPARK-10181 Do kerberos login for credentials during hive client init…
yolandagao 36d5ef8
Merge remote-tracking branch 'upstream/master'
cdb3aa5
Merge remote-tracking branch 'upstream/master'
1fbc372
SPARK-10181 Add comments explaining the keytab principal confs propag…
yolandagao caf51a7
SPARK-10181 Add more comments for clarification
yolandagao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,10 @@ import org.apache.hadoop.hive.ql.processors._ | |
| import org.apache.hadoop.hive.ql.session.SessionState | ||
| import org.apache.hadoop.hive.ql.{Driver, metadata} | ||
| import org.apache.hadoop.hive.shims.{HadoopShims, ShimLoader} | ||
| import org.apache.hadoop.security.UserGroupInformation | ||
| import org.apache.hadoop.util.VersionInfo | ||
|
|
||
| import org.apache.spark.Logging | ||
| import org.apache.spark.{SparkConf, SparkException, Logging} | ||
| import org.apache.spark.sql.catalyst.expressions.Expression | ||
| import org.apache.spark.sql.execution.QueryExecutionException | ||
| import org.apache.spark.util.{CircularBuffer, Utils} | ||
|
|
@@ -149,6 +150,27 @@ private[hive] class ClientWrapper( | |
| val original = Thread.currentThread().getContextClassLoader | ||
| // Switch to the initClassLoader. | ||
| Thread.currentThread().setContextClassLoader(initClassLoader) | ||
|
|
||
| // Set up kerberos credentials for UserGroupInformation.loginUser within | ||
| // current class loader | ||
| // Instead of using the spark conf of the current spark context, a new | ||
| // instance of SparkConf is needed for the original value of spark.yarn.keytab | ||
| // and spark.yarn.principal set in SparkSubmit, as yarn.Client resets the | ||
| // keytab configuration for the link name in distributed cache | ||
| val sparkConf = new SparkConf | ||
| if (sparkConf.contains("spark.yarn.principal") && sparkConf.contains("spark.yarn.keytab")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make it clear that we set these two settings in SparkSubmit. |
||
| val principalName = sparkConf.get("spark.yarn.principal") | ||
| val keytabFileName = sparkConf.get("spark.yarn.keytab") | ||
| if (!new File(keytabFileName).exists()) { | ||
| throw new SparkException(s"Keytab file: ${keytabFileName}" + | ||
| " specified in spark.yarn.keytab does not exist") | ||
| } else { | ||
| logInfo("Attempting to login to Kerberos" + | ||
| s" using principal: ${principalName} and keytab: ${keytabFileName}") | ||
| UserGroupInformation.loginUserFromKeytab(principalName, keytabFileName) | ||
| } | ||
| } | ||
|
|
||
| val ret = try { | ||
| val initialConf = new HiveConf(classOf[SessionState]) | ||
| // HiveConf is a Hadoop Configuration, which has a field of classLoader and | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating a new Spark Conf, can we use
SparkEnv.get.confto get the spark conf associated with the current spark context?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yhuai Sorry for the late response. I did the testing after changing to SparkEnv.get.conf but it didn't work. The reason is that Yarn Client.scala resets property spark.yarn.keytab by appending some random strings to keytab file name during setupCredentials, which will be used as the link name in distributed cache. I think the one for the link name should be actually separated from the original keytab setting, e.g. using different property names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yolandagao Thanks for the explanation. Can you add comments to your code (including why we need to put those confs to sysProps and why we need to create a new SparkConf at here)? Basically, we need to document the flow of how these confs get propagated. Otherwise, it is not obvious why we need to do this change. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yhuai Sure. I should have done this earlier, to make everything clearer:) Added some comments there, and please help review. Thank you!