Github user mgummelt commented on a diff in the pull request:
https://github.com/apache/spark/pull/17665#discussion_r112015085
--- Diff:
resource-managers/mesos/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSecurityManager.scala
---
@@ -0,0 +1,66 @@
+/*
+ * 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.scheduler.cluster.mesos
+
+import javax.xml.bind.DatatypeConverter
+
+import org.apache.hadoop.security.{Credentials, UserGroupInformation}
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.SparkHadoopUtil
+import org.apache.spark.deploy.mesos.config
+import org.apache.spark.deploy.security.ConfigurableCredentialManager
+import org.apache.spark.internal.Logging
+
+
+private[mesos] class MesosSecurityManager extends Logging {
+ def isSecurityEnabled(): Boolean = {
+ UserGroupInformation.isSecurityEnabled
+ }
+
+ /** Writes delegation tokens to spark.mesos.kerberos.ugiTokens */
+ def setUGITokens(conf: SparkConf): Unit = {
+ val userCreds = getDelegationTokens(conf)
+
+ val byteStream = new java.io.ByteArrayOutputStream(1024 * 1024)
+ val dataStream = new java.io.DataOutputStream(byteStream)
+ userCreds.writeTokenStorageToStream(dataStream)
+ val credsBytes = byteStream.toByteArray
+
+ logInfo(s"Writing ${credsBytes.length} bytes to
${config.USER_CREDENTIALS.key}.")
+
+ val creds64 = DatatypeConverter.printBase64Binary(credsBytes)
+ conf.set(config.USER_CREDENTIALS, creds64)
+ }
+
+ /**
+ * Returns the user's credentials, with new delegation tokens added for
all configured
+ * services.
+ */
+ private def getDelegationTokens(conf: SparkConf): Credentials = {
+ val userCreds = UserGroupInformation.getCurrentUser.getCredentials
+ val numTokensBefore = userCreds.numberOfTokens
+ val hadoopConf = SparkHadoopUtil.get.newConfiguration(conf)
+ val credentialManager = new ConfigurableCredentialManager(conf,
hadoopConf)
+ credentialManager.obtainCredentials(hadoopConf, userCreds)
--- End diff --
Fetching tokens multiple times isn't supported yet. That will come in the
renewal PR.
When you say it will fail, do you mean it will throw an exception, or just
fail to fetch a token? Looking at the code, I don't see how either would
happen:
https://github.com/mesosphere/spark/blob/SPARK-16742-kerberos/core/src/main/scala/org/apache/spark/deploy/security/HBaseCredentialProvider.scala#L46
It looks like it fetches a token indepedent of the current credentials, then
overwrites any current HBase token via `creds.addToken`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]