forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPARK-3883: SSL support for HttpServer and Akka
- Introduced SSLOptions object - SSLOptions is created by SecurityManager - SSLOptions configures Akka and Jetty to use SSL - Provided utility methods to determine the proper Akka protocol for Akka requests and to configure SSL socket factory for URL connections - Added tests cases for AkkaUtils, FileServer, SSLOptions and SecurityManager - Added a way to use node local SSL configuration by executors and driver - Make CoarseGrainedExecutorBackend not overwrite the settings which are executor startup configuration - they are passed anyway from Worker
- Loading branch information
1 parent
63dfe21
commit 93050f4
Showing
35 changed files
with
852 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* 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 | ||
|
||
import java.io.File | ||
|
||
import com.typesafe.config.{Config, ConfigFactory, ConfigValueFactory} | ||
import org.eclipse.jetty.util.ssl.SslContextFactory | ||
|
||
private[spark] case class SSLOptions( | ||
enabled: Boolean = false, | ||
keyStore: Option[File] = None, | ||
keyStorePassword: Option[String] = None, | ||
keyPassword: Option[String] = None, | ||
trustStore: Option[File] = None, | ||
trustStorePassword: Option[String] = None, | ||
protocol: Option[String] = None, | ||
enabledAlgorithms: Set[String] = Set.empty) { | ||
|
||
/** | ||
* Creates a Jetty SSL context factory according to the SSL settings represented by this object. | ||
*/ | ||
def createJettySslContextFactory(): Option[SslContextFactory] = { | ||
if (enabled) { | ||
val sslContextFactory = new SslContextFactory() | ||
|
||
keyStore.foreach(file => sslContextFactory.setKeyStorePath(file.getAbsolutePath)) | ||
trustStore.foreach(file => sslContextFactory.setTrustStore(file.getAbsolutePath)) | ||
keyStorePassword.foreach(sslContextFactory.setKeyStorePassword) | ||
trustStorePassword.foreach(sslContextFactory.setTrustStorePassword) | ||
keyPassword.foreach(sslContextFactory.setKeyManagerPassword) | ||
protocol.foreach(sslContextFactory.setProtocol) | ||
sslContextFactory.setIncludeCipherSuites(enabledAlgorithms.toSeq: _*) | ||
|
||
Some(sslContextFactory) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/** | ||
* Creates an Akka configuration object which contains all the SSL settings represented by this | ||
* object. It can be used then to compose the ultimate Akka configuration. | ||
*/ | ||
def createAkkaConfig: Option[Config] = { | ||
import scala.collection.JavaConversions._ | ||
if (enabled) { | ||
Some(ConfigFactory.empty() | ||
.withValue("akka.remote.netty.tcp.security.key-store", | ||
ConfigValueFactory.fromAnyRef(keyStore.map(_.getAbsolutePath).getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.key-store-password", | ||
ConfigValueFactory.fromAnyRef(keyStorePassword.getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.trust-store", | ||
ConfigValueFactory.fromAnyRef(trustStore.map(_.getAbsolutePath).getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.trust-store-password", | ||
ConfigValueFactory.fromAnyRef(trustStorePassword.getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.key-password", | ||
ConfigValueFactory.fromAnyRef(keyPassword.getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.random-number-generator", | ||
ConfigValueFactory.fromAnyRef("")) | ||
.withValue("akka.remote.netty.tcp.security.protocol", | ||
ConfigValueFactory.fromAnyRef(protocol.getOrElse(""))) | ||
.withValue("akka.remote.netty.tcp.security.enabled-algorithms", | ||
ConfigValueFactory.fromIterable(enabledAlgorithms.toSeq)) | ||
.withValue("akka.remote.netty.tcp.enable-ssl", | ||
ConfigValueFactory.fromAnyRef(true))) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
override def toString: String = s"SSLOptions{enabled=$enabled, " + | ||
s"keyStore=$keyStore, keyStorePassword=${keyStorePassword.map(_ => "xxx")}, " + | ||
s"trustStore=$trustStore, trustStorePassword=${trustStorePassword.map(_ => "xxx")}, " + | ||
s"protocol=$protocol, enabledAlgorithms=$enabledAlgorithms}" | ||
|
||
} | ||
|
||
private[spark] object SSLOptions extends Logging { | ||
|
||
/** | ||
* Resolves SSLOptions settings from a given Spark configuration object at a given namespace. | ||
* The parent directory of that location is used as a base directory to resolve relative paths | ||
* to keystore and truststore. | ||
*/ | ||
def parse(conf: SparkConf, ns: String): SSLOptions = { | ||
val enabled = conf.getBoolean(s"$ns.enabled", defaultValue = false) | ||
val keyStore = conf.getOption(s"$ns.keyStore").map(new File(_)) | ||
val keyStorePassword = conf.getOption(s"$ns.keyStorePassword") | ||
val keyPassword = conf.getOption(s"$ns.keyPassword") | ||
val trustStore = conf.getOption(s"$ns.trustStore").map(new File(_)) | ||
val trustStorePassword = conf.getOption(s"$ns.trustStorePassword") | ||
val protocol = conf.getOption(s"$ns.protocol") | ||
val enabledAlgorithms = conf.get(s"$ns.enabledAlgorithms", defaultValue = "") | ||
.split(",").map(_.trim).filter(_.nonEmpty).toSet | ||
|
||
new SSLOptions( | ||
enabled, | ||
keyStore, | ||
keyStorePassword, | ||
keyPassword, | ||
trustStore, | ||
trustStorePassword, | ||
protocol, | ||
enabledAlgorithms) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.