-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29082][CORE] Skip delegation token generation if no credentials are available #25901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,17 @@ | |
|
|
||
| package org.apache.spark.deploy.security | ||
|
|
||
| import java.security.PrivilegedExceptionAction | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.security.Credentials | ||
| import org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION | ||
| import org.apache.hadoop.minikdc.MiniKdc | ||
| import org.apache.hadoop.security.{Credentials, UserGroupInformation} | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.SparkHadoopUtil | ||
| import org.apache.spark.security.HadoopDelegationTokenProvider | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| private class ExceptionThrowingDelegationTokenProvider extends HadoopDelegationTokenProvider { | ||
| ExceptionThrowingDelegationTokenProvider.constructed = true | ||
|
|
@@ -69,4 +75,48 @@ class HadoopDelegationTokenManagerSuite extends SparkFunSuite { | |
| assert(!manager.isProviderLoaded("hadoopfs")) | ||
| assert(manager.isProviderLoaded("hbase")) | ||
| } | ||
|
|
||
| test("SPARK-29082: do not fail if current user does not have credentials") { | ||
| // SparkHadoopUtil overrides the UGI configuration during initialization. That normally | ||
| // happens early in the Spark application, but here it may affect the test depending on | ||
| // how it's run, so force its initialization. | ||
| SparkHadoopUtil.get | ||
|
|
||
| var kdc: MiniKdc = null | ||
| try { | ||
| // UserGroupInformation.setConfiguration needs default kerberos realm which can be set in | ||
| // krb5.conf. MiniKdc sets "java.security.krb5.conf" in start and removes it when stop called. | ||
| val kdcDir = Utils.createTempDir() | ||
| val kdcConf = MiniKdc.createConf() | ||
| kdc = new MiniKdc(kdcConf, kdcDir) | ||
|
Contributor
Author
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. Change1: I've added |
||
| kdc.start() | ||
|
|
||
| val krbConf = new Configuration() | ||
| krbConf.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos") | ||
|
|
||
| UserGroupInformation.setConfiguration(krbConf) | ||
|
Contributor
Author
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. Change2: I've pulled |
||
| val manager = new HadoopDelegationTokenManager(new SparkConf(false), krbConf, null) | ||
| val testImpl = new PrivilegedExceptionAction[Unit] { | ||
| override def run(): Unit = { | ||
| assert(UserGroupInformation.isSecurityEnabled()) | ||
| val creds = new Credentials() | ||
| manager.obtainDelegationTokens(creds) | ||
| assert(creds.numberOfTokens() === 0) | ||
| assert(creds.numberOfSecretKeys() === 0) | ||
| } | ||
| } | ||
|
|
||
| val realUser = UserGroupInformation.createUserForTesting("realUser", Array.empty) | ||
| realUser.doAs(testImpl) | ||
|
|
||
| val proxyUser = UserGroupInformation.createProxyUserForTesting("proxyUser", realUser, | ||
| Array.empty) | ||
| proxyUser.doAs(testImpl) | ||
| } finally { | ||
| if (kdc != null) { | ||
|
Contributor
Author
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. Change3: Stop |
||
| kdc.stop() | ||
| } | ||
| UserGroupInformation.reset() | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.