Skip to content

Commit aafa1fa

Browse files
authored
mesos security configurable (apache#141)
* mesos security configurable * principal secret order bug * getoption * [skip ci] update CHANGELOG.md
1 parent 19b7e71 commit aafa1fa

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Removed mesos security from History Server and unified environment variable VAULT_HOSTS
99
* Secret folder path configurable
1010
* Changed log format according to Stratio standards
11+
* Mesos Role no longer obtain mesos pricipal and mesos secret from vault in Spark jobs
1112

1213
## 2.2.0.4 (January 11, 2018)
1314

core/src/main/scala/org/apache/spark/security/ConfigSecurity.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ object ConfigSecurity extends Logging {
138138
SSLConfig.prepareEnvironment(SSLConfig.sslTypeDataStore, options)
139139
case ("db", options) =>
140140
DBConfig.prepareEnvironment(options)
141+
case ("mesos", options) =>
142+
MesosConfig.prepareEnvironment(options)
141143
case _ => Map.empty[String, String]
142144
}
143145
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.spark.security
18+
19+
object MesosConfig {
20+
def prepareEnvironment(options: Map[String, String]): Map[String, String] = {
21+
options.filter(_._1.endsWith("MESOS_VAULT_PATH")).flatMap{case (_, path) =>
22+
val (pass, user) = VaultHelper.getPassPrincipalFromVault(path)
23+
Seq(("spark.mesos.principal", user), ("spark.mesos.secret", pass))
24+
}
25+
}
26+
}

core/src/main/scala/org/apache/spark/security/VaultHelper.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package org.apache.spark.security
1818

1919
import org.apache.spark.internal.Logging
2020

21-
import scala.util.Try
22-
2321
object VaultHelper extends Logging {
2422

2523

@@ -78,11 +76,6 @@ object VaultHelper extends Logging {
7876
(keytab64, principal)
7977
}
8078

81-
// TODO refactor these two functions into one
82-
def getMesosPrincipalAndSecret(instanceName: String): (String, String) = {
83-
getPassPrincipalFromVault(s"/v1/userland/passwords/$instanceName/mesos")
84-
}
85-
8679
def getPassPrincipalFromVault(vaultPath: String): (String, String) = {
8780
val requestUrl = s"${ConfigSecurity.vaultURI.get}/$vaultPath"
8881
logDebug(s"Requesting user and pass: $requestUrl")

resource-managers/mesos/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSchedulerUtils.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,15 @@ trait MesosSchedulerUtils extends Logging {
7979
fwInfoBuilder.setHostname(Option(conf.getenv("SPARK_PUBLIC_DNS")).getOrElse(
8080
conf.get(DRIVER_HOST_ADDRESS)))
8181

82-
if(ConfigSecurity.vaultURI.isDefined && conf.getOption("spark.mesos.role").isDefined) {
82+
if(ConfigSecurity.vaultURI.isDefined &&
83+
conf.getOption("spark.mesos.principal").isDefined &&
84+
conf.getOption("spark.mesos.secret").isDefined) {
8385

84-
val(mSecret, mPrincipal) =
85-
VaultHelper.getMesosPrincipalAndSecret(conf.getOption("spark.mesos.role").get)
86+
val(mPrincipal, mSecret) = (conf.get("spark.mesos.principal"), conf.get("spark.mesos.secret"))
8687

87-
conf.set("spark.mesos.principal", mPrincipal)
8888
fwInfoBuilder.setPrincipal(mPrincipal)
8989
credBuilder.setPrincipal(mPrincipal)
9090

91-
conf.set("spark.mesos.secret", mSecret)
9291
credBuilder.setSecret(mSecret)
9392

9493
}

0 commit comments

Comments
 (0)