[
https://issues.apache.org/jira/browse/SPARK-6373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14372003#comment-14372003
]
Jeffrey Turpin commented on SPARK-6373:
---------------------------------------
Here are some comments about my implementation...
*Configuration:*
I added a new SSLOptions member variable to SecurityManager.scala, specifically
for configuring SSL for the Block Transfer Service:
{code:title=SecurityManager.scala|linenumbers=false|language=scala}
val btsSSLOptions = SSLOptions.parse(sparkConf, "spark.ssl.bts",
Some(defaultSSLOptions))
{code}
I expanded the SSLOptions case class to capture additional SSL related
parameters:
{code:title=SecurityManager.scala|linenumbers=false|language=scala}
private[spark] case class SSLOptions(
enabled: Boolean = false,
keyStore: Option[File] = None,
keyStorePassword: Option[String] = None,
privateKey: Option[File] = None,
keyPassword: Option[String] = None,
certChain: Option[File] = None,
trustStore: Option[File] = None,
trustStorePassword: Option[String] = None,
trustStoreReloadingEnabled: Boolean = false,
trustStoreReloadInterval: Int = 10000,
openSslEnabled: Boolean = false,
protocol: Option[String] = None,
enabledAlgorithms: Set[String] = Set.empty)
{code}
This can change, but for now I added the ability to provide a standard java
keystore and truststore, as was possible with the existing file server and akka
SSL configurations available in SecurityManager.scala. For this configuration I
added the ability to enable truststore reloading (hadoop encrypted shuffle
allows for this). In addition, I added the ability to specify an X.509
certificate chain in PEM format and a PKCS#8 private key file in PEM format. If
all four parameters are provided (keyStore, trustStore, privateKey, certChain)
then the privateKey and certChain parameters will be used.
In TransportConf.java I added two addition configuration parameters:
{code:title=TransportConf.java|linenumbers=false|language=java}
public int sslShuffleChunkSize() {
return conf.getInt("spark.shuffle.io.ssl.chunkSize", 60 * 1024);
}
public boolean sslShuffleEnabled() {
return conf.getBoolean("spark.ssl.bts.enabled", false);
}
{code}
For the _"spark.shuffle.io.ssl.chunkSize"_ config param I set the default to
the same size used in Hadoop's encrypted shuffle implementation.
*Implementation:*
For this prototype, I opted to disrupt as little code as possible, meaning I
wanted to avoid any major refactorings... So here is some of what I did...
I essentially overloaded two methods in TransportContext.java which take a new
class I created, SSLFactory. SSLFactory basically encapsulates all the
Keystore/Certificate stuff that needs to happen.
{code:title=TransportContext.java|linenumbers=false|language=java}
public TransportClientFactory createClientFactory(
List<TransportClientBootstrap> bootstraps, SSLFactory sslFactory) {
return new TransportClientFactory(this, bootstraps, sslFactory);
}
...
public TransportServer createSecureServer(SSLFactory sslFactory) {
return new TransportServer(this, 0, sslFactory);
}
public TransportServer createSecureServer(SSLFactory sslFactory, int port) {
return new TransportServer(this, port, sslFactory);
}
{code}
These new methods all the user to create a secure TransportServer or secure
TransportClientFactory instance. Obviously I had to add the appropriate
constructors to both the TransportClientFactory and TransportServer classes....
Now in the _createClient_ method of TransportClientFactory, it will essentially
check if the _sslFactory_ member variable is null, and if not, will initialize
the Netty pipeline and add a Netty SslHandler...
{code:title=TransportClientFactory.java|linenumbers=false|language=java}
private void initHandler(
final Bootstrap bootstrap,
final AtomicReference<TransportClient> clientRef) {
if (sslFactory != null) {
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Add SSL handler first to encrypt and decrypt everything.
pipeline.addLast(new SslHandler(sslFactory.createSSLEngine()));
TransportChannelHandler clientHandler =
context.initializePipeline(ch);
clientRef.set(clientHandler.getClient());
}
});
} else {
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
TransportChannelHandler clientHandler =
context.initializePipeline(ch);
clientRef.set(clientHandler.getClient());
}
});
}
}
{code}
In addition, the _createClient_ method will block and wait for the SSL
handshake to complete before returning a TransportClient instance...
The TransportServer implementation is a bit different but is similar in spirit.
I essentially added an _initHandler_ method that initialized the Netty pipeline
appropriately, the main difference being that I have to add a
ChunkedWriteHandler just before our MessageDecoder as zero copy will not work
with HTTPS:
{code:title=TransportServer.java|linenumbers=false|language=java}
private void initHandler() {
if (sslFactory != null) {
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// Add SSL handler first to encrypt and decrypt everything.
ch.pipeline().addLast(new SslHandler(sslFactory.createSSLEngine()));
context.initializePipeline(ch);
// Cannot use zero-copy with HTTPS, so we add in our
ChunkedWriteHandler just before our MessageDecoder
ch.pipeline().addBefore("decoder", "chunkedWriter", new
ChunkedWriteHandler());
}
});
} else {
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
context.initializePipeline(ch);
}
});
}
}
{code}
So given all that, only a minor change was needed in the _init_ method of
NettyBlockTransferService to create the _transportContext_ and
_transportClientFactory_ appropriately.
{code:title=NettyBlockTransferService.scala|linenumbers=false|language=scala}
clientFactory = securityManager.btsSSLOptions
.createSSLFactory(true)
.fold(transportContext.createClientFactory(bootstrap.toList)) {
factory =>
transportContext.createClientFactory(bootstrap.toList, factory)
}
...
server = securityManager.btsSSLOptions
.createSSLFactory(false)
.fold(transportContext.createServer(port)) {
factory =>
transportContext.createSecureServer(factory, port)
}
{code}
Anyways, those are just some initial comments about the implementation.
Definitely looking for feedback... If someone has a better alternative I am all
for it, just wanted to get something working to start a design conversation
going... Thanks!
Jeff
> Add SSL/TLS for the Netty based BlockTransferService
> -----------------------------------------------------
>
> Key: SPARK-6373
> URL: https://issues.apache.org/jira/browse/SPARK-6373
> Project: Spark
> Issue Type: New Feature
> Components: Block Manager, Shuffle
> Affects Versions: 1.2.1
> Reporter: Jeffrey Turpin
>
> Add the ability to allow for secure communications (SSL/TLS) for the Netty
> based BlockTransferService and the ExternalShuffleClient. This ticket will
> hopefully start the conversation around potential designs... Below is a
> reference to a WIP prototype which implements this functionality
> (prototype)... I have attempted to disrupt as little code as possible and
> tried to follow the current code structure (for the most part) in the areas I
> modified. I also studied how Hadoop achieves encrypted shuffle
> (http://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/EncryptedShuffle.html)
> https://github.com/turp1twin/spark/commit/024b559f27945eb63068d1badf7f82e4e7c3621c
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]