Github user mridulm commented on a diff in the pull request:
https://github.com/apache/spark/pull/17665#discussion_r112043800
--- 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 --
@mgummelt It might be a bit involved, and has to do with how hbase issues
tokens at its side (not in client library, but at the server) - if it sees a
token in the incoming request, it will not issue new tokens.
@jerryshao is the right person to detail it if required, but bottomline is,
if we add acquired tokens to ugi.currentUser, then subsequently we cannot use
ugi.currentUser to acquire tokens for hbase. This actually comes from semantics
of token, and might be applicable to other token providers as well (hbase is
one case I know where it does this for sure).
---
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]