@@ -89,6 +89,7 @@ private[spark] class SecurityManager(
8989 setViewAclsGroups(sparkConf.get(" spark.ui.view.acls.groups" , " " ));
9090 setModifyAclsGroups(sparkConf.get(" spark.modify.acls.groups" , " " ));
9191
92+ private var secretKey : String = _
9293 logInfo(" SecurityManager: authentication " + (if (authOn) " enabled" else " disabled" ) +
9394 " ; ui acls " + (if (aclsOn) " enabled" else " disabled" ) +
9495 " ; users with view permissions: " + viewAcls.toString() +
@@ -321,6 +322,12 @@ private[spark] class SecurityManager(
321322 val creds = UserGroupInformation .getCurrentUser().getCredentials()
322323 Option (creds.getSecretKey(SECRET_LOOKUP_KEY ))
323324 .map { bytes => new String (bytes, UTF_8 ) }
325+ // Secret key may not be found in current UGI's credentials.
326+ // This happens when UGI is refreshed in the driver side by UGI's loginFromKeytab but not
327+ // copy secret key from original UGI to the new one. This exists in ThriftServer's Hive
328+ // logic. So as a workaround, storing secret key in a local variable to make it visible
329+ // in different context.
330+ .orElse(Option (secretKey))
324331 .orElse(Option (sparkConf.getenv(ENV_AUTH_SECRET )))
325332 .orElse(sparkConf.getOption(SPARK_AUTH_SECRET_CONF ))
326333 .getOrElse {
@@ -364,8 +371,8 @@ private[spark] class SecurityManager(
364371 rnd.nextBytes(secretBytes)
365372
366373 val creds = new Credentials ()
367- val secretStr = HashCodes .fromBytes(secretBytes).toString()
368- creds.addSecretKey(SECRET_LOOKUP_KEY , secretStr .getBytes(UTF_8 ))
374+ secretKey = HashCodes .fromBytes(secretBytes).toString()
375+ creds.addSecretKey(SECRET_LOOKUP_KEY , secretKey .getBytes(UTF_8 ))
369376 UserGroupInformation .getCurrentUser().addCredentials(creds)
370377 }
371378
0 commit comments