This repository was archived by the owner on Jan 9, 2020. It is now read-only.
forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 117
Support SSL on the file staging server #221
Merged
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
71b825a
Staging server for receiving application dependencies.
mccheah e005213
Merge remote-tracking branch 'apache-spark-on-k8s/branch-2.1-kubernet…
mccheah 929d880
Move packages around to split between v1 work and v2 work
mccheah 6e40c4c
Add unit test for file writing
mccheah e4daf56
Merge branch 'submission-v2-file-server' into branch-packages
mccheah 89c295e
Remove unnecessary main
mccheah 4b96668
Allow the file staging server to be secured with TLS.
mccheah 876bb4a
Add back license header
mccheah 7d00f07
Minor fixes
mccheah c4f2e64
Merge branch 'submission-v2-file-server' into branch-packages
mccheah 1d6f3f6
Merge branch 'branch-packages' into ssl-submission-v2-file-server
mccheah 0597b4c
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah ea76823
Merge branch 'branch-2.1-kubernetes' into submission-v2-file-server
mccheah ac0b841
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah b7c1ea5
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah baf10aa
Fix integration test with renamed package for client. Fix scalastyle.
mccheah 757b3dc
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah d041648
Remove unused import
mccheah d20537d
Force json serialization to consider the different package.
mccheah 2ca73a3
Revert extraneous log
mccheah ffe8c6c
Fix scalastyle
mccheah 6e5e3a8
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah 3dd3504
Remove getting credentials from the API
mccheah 3cbcadf
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah c62910d
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah c1a359a
Fix build
mccheah fbbad73
Randomize name and namespace in test to prevent collisions
mccheah 9bfb085
Merge branch 'branch-2.1-kubernetes' into submission-v2-file-server
ash211 df8e0c8
Generalize to resource staging server outside of Spark
mccheah 24452ec
Update code documentation
mccheah f597171
Val instead of var
mccheah c20e461
Merge remote-tracking branch 'apache-spark-on-k8s/submission-v2-file-…
mccheah 47704f1
Merge remote-tracking branch 'apache-spark-on-k8s/submission-v2-file-…
mccheah a6e0856
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah ff0b7cf
Fix unit tests.
mccheah 2e6fe07
Fix build
mccheah 2c1b068
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah e5f26aa
Fix naming, remove unused import
mccheah a09d935
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah ddd51cc
Merge remote-tracking branch 'apache-spark-on-k8s/split-v1-and-v2-sub…
mccheah c408ff9
Move suites from integration test package to core
mccheah 928f3a5
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah 1f23745
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah 539abf5
Fix unit test
mccheah a527847
Merge branch 'branch-2.1-kubernetes' into submission-v2-file-server
mccheah 0f2f847
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah d969d0b
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah 64eddc1
Use TrieMap instead of locks
mccheah 8f79802
Address comments
mccheah 31fd3b6
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah 35baecb
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah 04099d6
Fix imports
mccheah cac485c
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah 3c331f2
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah b16eafb
Address comments
mccheah 7fb0584
Change main object name
mccheah f0036f2
Change config variable names
mccheah d713c27
Change paths, use POST instead of PUT
mccheah 91df628
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah 60c1422
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah 720c38d
Use a resource identifier as well as a resource secret
mccheah 89b032e
Merge branch 'submission-v2-file-server' into split-v1-and-v2-submiss…
mccheah 86f809f
Merge branch 'split-v1-and-v2-submission-packages' into ssl-submissio…
mccheah c0711ff
Merge branch 'branch-2.1-kubernetes' into ssl-submission-v2-file-server
ash211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
.../org/apache/spark/deploy/rest/kubernetes/v2/ResourceStagingServerSslOptionsProvider.scala
This file contains hidden or 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,133 @@ | ||
| /* | ||
| * 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.deploy.rest.kubernetes.v2 | ||
|
|
||
| import java.io.File | ||
|
|
||
| import com.google.common.base.Charsets | ||
| import com.google.common.io.Files | ||
|
|
||
| import org.apache.spark.{SecurityManager => SparkSecurityManager, SparkConf, SparkException, SSLOptions} | ||
| import org.apache.spark.deploy.kubernetes.config._ | ||
| import org.apache.spark.deploy.rest.kubernetes.v1.PemsToKeyStoreConverter | ||
| import org.apache.spark.internal.Logging | ||
|
|
||
| private[spark] trait ResourceStagingServerSslOptionsProvider { | ||
| def getSslOptions: SSLOptions | ||
| } | ||
|
|
||
| private[spark] class ResourceStagingServerSslOptionsProviderImpl(sparkConf: SparkConf) | ||
| extends ResourceStagingServerSslOptionsProvider with Logging { | ||
| def getSslOptions: SSLOptions = { | ||
| val baseSslOptions = new SparkSecurityManager(sparkConf) | ||
| .getSSLOptions("kubernetes.resourceStagingServer") | ||
| val maybeKeyPem = sparkConf.get(RESOURCE_STAGING_SERVER_KEY_PEM) | ||
| val maybeCertPem = sparkConf.get(RESOURCE_STAGING_SERVER_CERT_PEM) | ||
| val maybeKeyStorePasswordFile = sparkConf.get(RESOURCE_STAGING_SERVER_KEYSTORE_PASSWORD_FILE) | ||
| val maybeKeyPasswordFile = sparkConf.get(RESOURCE_STAGING_SERVER_KEYSTORE_KEY_PASSWORD_FILE) | ||
|
|
||
| logSslConfigurations( | ||
| baseSslOptions, maybeKeyPem, maybeCertPem, maybeKeyStorePasswordFile, maybeKeyPasswordFile) | ||
|
|
||
| requireNandDefined(baseSslOptions.keyStore, maybeKeyPem, | ||
| "Shouldn't provide both key PEM and keyStore files for TLS.") | ||
| requireNandDefined(baseSslOptions.keyStore, maybeCertPem, | ||
| "Shouldn't provide both certificate PEM and keyStore files for TLS.") | ||
| requireNandDefined(baseSslOptions.keyStorePassword, maybeKeyStorePasswordFile, | ||
| "Shouldn't provide both the keyStore password value and the keyStore password file.") | ||
| requireNandDefined(baseSslOptions.keyPassword, maybeKeyPasswordFile, | ||
| "Shouldn't provide both the keyStore key password value and the keyStore key password file.") | ||
| requireBothOrNeitherDefined( | ||
| maybeKeyPem, | ||
| maybeCertPem, | ||
| "When providing a certificate PEM file, the key PEM file must also be provided.", | ||
| "When providing a key PEM file, the certificate PEM file must also be provided.") | ||
|
|
||
| val resolvedKeyStorePassword = baseSslOptions.keyStorePassword | ||
| .orElse(maybeKeyStorePasswordFile.map { keyStorePasswordFile => | ||
| safeFileToString(keyStorePasswordFile, "KeyStore password file") | ||
| }) | ||
| val resolvedKeyStoreKeyPassword = baseSslOptions.keyPassword | ||
| .orElse(maybeKeyPasswordFile.map { keyPasswordFile => | ||
| safeFileToString(keyPasswordFile, "KeyStore key password file") | ||
| }) | ||
| val resolvedKeyStore = baseSslOptions.keyStore | ||
| .orElse(maybeKeyPem.map { keyPem => | ||
| val keyPemFile = new File(keyPem) | ||
| val certPemFile = new File(maybeCertPem.get) | ||
| PemsToKeyStoreConverter.convertPemsToTempKeyStoreFile( | ||
| keyPemFile, | ||
| certPemFile, | ||
| "key", | ||
| resolvedKeyStorePassword, | ||
| resolvedKeyStoreKeyPassword, | ||
| baseSslOptions.keyStoreType) | ||
| }) | ||
| baseSslOptions.copy( | ||
| keyStore = resolvedKeyStore, | ||
| keyStorePassword = resolvedKeyStorePassword, | ||
| keyPassword = resolvedKeyStoreKeyPassword) | ||
| } | ||
|
|
||
| private def logSslConfigurations( | ||
| baseSslOptions: SSLOptions, | ||
| maybeKeyPem: Option[String], | ||
| maybeCertPem: Option[String], | ||
| maybeKeyStorePasswordFile: Option[String], | ||
| maybeKeyPasswordFile: Option[String]) = { | ||
| logDebug("The following SSL configurations were provided for the resource staging server:") | ||
| logDebug(s"KeyStore File: ${baseSslOptions.keyStore.map(_.getAbsolutePath).getOrElse("N/A")}") | ||
| logDebug("KeyStore Password: " + | ||
| baseSslOptions.keyStorePassword.map(_ => "<present_but_redacted>").getOrElse("N/A")) | ||
| logDebug(s"KeyStore Password File: ${maybeKeyStorePasswordFile.getOrElse("N/A")}") | ||
| logDebug("Key Password: " + | ||
| baseSslOptions.keyPassword.map(_ => "<present_but_redacted>").getOrElse("N/A")) | ||
| logDebug(s"Key Password File: ${maybeKeyPasswordFile.getOrElse("N/A")}") | ||
| logDebug(s"KeyStore Type: ${baseSslOptions.keyStoreType.getOrElse("N/A")}") | ||
| logDebug(s"Key PEM: ${maybeKeyPem.getOrElse("N/A")}") | ||
| logDebug(s"Certificate PEM: ${maybeCertPem.getOrElse("N/A")}") | ||
| } | ||
|
|
||
| private def requireBothOrNeitherDefined( | ||
| opt1: Option[_], | ||
| opt2: Option[_], | ||
| errMessageWhenFirstIsMissing: String, | ||
| errMessageWhenSecondIsMissing: String): Unit = { | ||
| requireSecondIfFirstIsDefined(opt1, opt2, errMessageWhenSecondIsMissing) | ||
| requireSecondIfFirstIsDefined(opt2, opt1, errMessageWhenFirstIsMissing) | ||
| } | ||
|
|
||
| private def requireSecondIfFirstIsDefined( | ||
| opt1: Option[_], opt2: Option[_], errMessageWhenSecondIsMissing: String): Unit = { | ||
| opt1.foreach { _ => | ||
| require(opt2.isDefined, errMessageWhenSecondIsMissing) | ||
| } | ||
| } | ||
|
|
||
| private def requireNandDefined(opt1: Option[_], opt2: Option[_], errMessage: String): Unit = { | ||
| opt1.foreach { _ => require(opt2.isEmpty, errMessage) } | ||
| } | ||
|
|
||
| private def safeFileToString(filePath: String, fileType: String): String = { | ||
| val file = new File(filePath) | ||
| if (!file.isFile) { | ||
| throw new SparkException(s"$fileType provided at ${file.getAbsolutePath} does not exist or" | ||
| + s" is not a file.") | ||
| } | ||
| Files.toString(file, Charsets.UTF_8) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this log some kind of "server started on hostname:port" message? Want to have a clear "I'm ready" message to look for in server logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have the hostname here but Spark tends to log "Started server listening on port X", and we should do something similar here.