-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 41 security #43
Open
mkaranasou
wants to merge
4
commits into
develop
Choose a base branch
from
issue_41_security
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
Binary file not shown.
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,24 @@ | ||
# source: https://www.ibm.com/support/knowledgecenter/en/SS3H8V_1.1.0/com.ibm.izoda.v1r1.azka100/topics/azkic_t_securingwebUIs.htm | ||
|
||
echo ">>> Setting up SSL for Spark UI..." | ||
echo "Keystore path : " | ||
read -s -r KEYSTORE_PATH | ||
echo "Truststore path : " | ||
read -s -r TRUSTSTORE_PATH | ||
echo "Store password : " | ||
read -s -r STORE_PASS | ||
echo "Key password : " | ||
read -s -r KEY_PASS | ||
echo "L : " | ||
read -s -r L | ||
echo "S : " | ||
read -s -r S | ||
echo "C : " | ||
read -s -r C | ||
|
||
keytool -genkeypair -keystore "$KEYSTORE_PATH/keystore" -keyalg RSA -alias selfsigned -dname "CN=sparkcert L=$L S=$S C=$C" -storepass "$STORE_PASS" -keypass "$KEY_PASS" | ||
|
||
keytool -exportcert -keystore "$KEYSTORE_PATH/keystore" -alias selfsigned -storepass $STORE_PASS -file spark.cer | ||
|
||
# note: do not forget to import cert in all nodes | ||
keytool -importcert -keystore "$TRUSTSTORE_PATH/truststore" -alias selfsigned -storepass $STORE_PASS -file spark.cer -noprompt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have checked this only locally. We'll need to test this on the cluster. |
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 |
---|---|---|
|
@@ -10,8 +10,10 @@ | |
from pyspark import SparkConf, StorageLevel | ||
from pyspark.sql import SparkSession | ||
|
||
from baskerville.models.config import SparkConfig | ||
|
||
def get_or_create_spark_session(spark_conf): | ||
|
||
def get_or_create_spark_session(spark_conf: SparkConfig): | ||
""" | ||
Returns a configured spark session | ||
:param SparkConfig spark_conf: the spark configuration | ||
|
@@ -145,6 +147,41 @@ def get_or_create_spark_session(spark_conf): | |
conf.set('spark.sql.shuffle.partitions', spark_conf.shuffle_partitions) | ||
conf.set('spark.sql.autoBroadcastJoinThreshold', 1024*1024*100) # 100MB | ||
|
||
# security | ||
# https://spark.apache.org/docs/latest/security.html | ||
# note that: The same secret is shared by all Spark applications and | ||
# daemons in that case, which limits the security of these deployments, | ||
# especially on multi-tenant clusters. | ||
if spark_conf.auth_secret: | ||
conf.set('spark.authenticate', 'true') | ||
conf.set('spark.authenticate.secret', spark_conf.auth_secret) | ||
|
||
# encryption | ||
conf.set('spark.network.crypto.enabled', 'true') | ||
conf.set('spark.io.encryption.enabled', 'true') | ||
# https://www.fortytools.com/blog/servlet-filter-for-http-basic-auth | ||
conf.set('spark.ui.filters', 'baskerville.security.BasicAuthFilter') | ||
# conf.set('spark.acls.enable', 'true') | ||
# conf.set('spark.admin.acls', spark_conf.admin_acls) | ||
|
||
# SSL https://spark.apache.org/docs/latest/security.html#ssl-configuration | ||
if spark_conf.ssl_enabled == 'true': | ||
conf.set('spark.ssl.enabled', spark_conf.ssl_enabled) | ||
conf.set('spark.ssl.trustStore', spark_conf.ssl_truststore) | ||
conf.set('spark.ssl.trustStorePassword', spark_conf.ssl_truststore_password) | ||
conf.set('spark.ssl.keyStore', spark_conf.ssl_keystore) | ||
conf.set('spark.ssl.keyStorePassword', spark_conf.ssl_keystore_password) | ||
conf.set('spark.ssl.keyPassword', spark_conf.ssl_keypassword) | ||
conf.set('spark.ssl.protocol', 'TLSv1.2') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about the tls protocol version, will double check. |
||
|
||
# conf.set('spark.driver.port', spark_conf.driver_port) | ||
# conf.set('spark.blockManager.port', spark_conf.block_manager_port) | ||
|
||
# The REST Submission Server and the MesosClusterDispatcher do not support | ||
# authentication. You should ensure that all network access to the REST API | ||
# & MesosClusterDispatcher (port 6066 and 7077 respectively by default) are | ||
# restricted to hosts that are trusted to submit jobs. | ||
|
||
spark = SparkSession.builder \ | ||
.config(conf=conf) \ | ||
.appName(spark_conf.app_name) \ | ||
|
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.
Needs to be tested on the cluster.