parthchandra commented on code in PR #57285:
URL: https://github.com/apache/spark/pull/57285#discussion_r3634446175
##########
core/src/main/scala/org/apache/spark/deploy/security/HadoopDelegationTokenManager.scala:
##########
@@ -226,24 +249,41 @@ private[spark] class HadoopDelegationTokenManager(
*
* @return Credentials containing the new tokens.
*/
- private def obtainTokensAndScheduleRenewal(ugi: UserGroupInformation):
Credentials = {
- ugi.doAs(new PrivilegedExceptionAction[Credentials]() {
- override def run(): Credentials = {
- val (creds, nextRenewal) = obtainDelegationTokens()
-
- // Calculate the time when new credentials should be created, based on
the configured
- // ratio.
- val now = System.currentTimeMillis
- val ratio = sparkConf.get(CREDENTIALS_RENEWAL_INTERVAL_RATIO)
- val delay = (ratio * (nextRenewal - now)).toLong
- logInfo(log"Calculated delay on renewal is ${MDC(LogKeys.DELAY,
delay)}," +
- log" based on next renewal ${MDC(LogKeys.NEXT_RENEWAL_TIME,
nextRenewal)}" +
- log" and the ratio ${MDC(LogKeys.CREDENTIALS_RENEWAL_INTERVAL_RATIO,
ratio)}," +
- log" and current time ${MDC(LogKeys.CURRENT_TIME, now)}")
- scheduleRenewal(delay)
- creds
+ private def obtainTokensAndScheduleRenewal(): Credentials = {
+ val hasKerberosConfig = sparkConf.get(KERBEROS_RENEWAL_CREDENTIALS) match {
Review Comment:
done
##########
core/src/main/scala/org/apache/spark/internal/config/package.scala:
##########
@@ -1679,6 +1679,18 @@ package object config {
.timeConf(TimeUnit.SECONDS)
.createWithDefaultString("1h")
+ private[spark] val CREDENTIALS_DIRECT_PROVIDERS_ENABLED =
+ ConfigBuilder("spark.security.credentials.directProviders.enabled")
+ .doc(
+ "When true, enables delegation token collection and renewal without
Kerberos. " +
+ "Providers are called directly (without doLogin/doAs) and participate
in the " +
+ "same renewal and distribution lifecycle as Kerberos delegation token
providers. " +
+ "Providers that require Kerberos self-gate via
delegationTokensRequired.")
+ .version("5.0.0")
Review Comment:
I was originally planning this only for 5.0.0. However, if you think we
should also backport it (seems reasonable) then I will do so and change the
config to 4.3.0
##########
core/src/main/scala/org/apache/spark/deploy/security/HadoopDelegationTokenManager.scala:
##########
@@ -76,17 +77,33 @@ private[spark] class HadoopDelegationTokenManager(
require((principal == null) == (keytab == null),
"Both principal and keytab must be defined, or neither.")
+ if (sparkConf.get(CREDENTIALS_DIRECT_PROVIDERS_ENABLED)) {
+ require(sparkConf.get(NETWORK_CRYPTO_ENABLED),
Review Comment:
Added the check. (It was easier to just read the raw conf)
##########
core/src/test/scala/org/apache/spark/deploy/security/NonKerberosCredentialsSuite.scala:
##########
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy.security
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.io.Text
+import org.apache.hadoop.security.Credentials
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.internal.config._
+import org.apache.spark.internal.config.Network.NETWORK_CRYPTO_ENABLED
+import org.apache.spark.security.HadoopDelegationTokenProvider
+
+private class TestNonKerberosTokenProvider extends
HadoopDelegationTokenProvider {
+ override def serviceName: String = "test-direct"
+
+ override def delegationTokensRequired(
+ sparkConf: SparkConf, hadoopConf: Configuration): Boolean = true
+
+ override def obtainDelegationTokens(
+ hadoopConf: Configuration,
+ sparkConf: SparkConf,
+ creds: Credentials): Option[Long] = {
+ creds.addSecretKey(new Text("test.direct.credential"),
"test-token".getBytes)
+ Some(System.currentTimeMillis() + 3600000L)
+ }
+}
+
+private class TestDisabledProvider extends HadoopDelegationTokenProvider {
+ override def serviceName: String = "test-disabled"
+
+ override def delegationTokensRequired(
+ sparkConf: SparkConf, hadoopConf: Configuration): Boolean = false
+
+ override def obtainDelegationTokens(
+ hadoopConf: Configuration,
+ sparkConf: SparkConf,
+ creds: Credentials): Option[Long] = {
+ // scalastyle:off throwerror
+ throw new AssertionError("Should not be called when
delegationTokensRequired is false")
+ // scalastyle:on throwerror
+ }
+}
+
+private class TestFailingProvider extends HadoopDelegationTokenProvider {
+ override def serviceName: String = "test-failing"
+
+ override def delegationTokensRequired(
+ sparkConf: SparkConf, hadoopConf: Configuration): Boolean = true
+
+ override def obtainDelegationTokens(
+ hadoopConf: Configuration,
+ sparkConf: SparkConf,
+ creds: Credentials): Option[Long] = {
+ throw new RuntimeException("Simulated provider failure")
+ }
+}
+
+class NonKerberosCredentialsSuite extends SparkFunSuite {
Review Comment:
added a new test that calls `start()` with a mock `RpcEndpointRef`, then
verifies `UpdateDelegationTokens` was sent with the expected credentials
##########
core/src/main/scala/org/apache/spark/deploy/security/HadoopDelegationTokenManager.scala:
##########
@@ -166,7 +184,14 @@ private[spark] class HadoopDelegationTokenManager(
val creds = new Credentials()
val nextRenewal = delegationTokenProviders.values.flatMap { provider =>
if (provider.delegationTokensRequired(sparkConf, hadoopConf)) {
- provider.obtainDelegationTokens(hadoopConf, sparkConf, creds)
+ try {
Review Comment:
Scoped the try/catch on the `isolateFailures` parameter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]