This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Feature: on node user creation #303
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c7af6d
client side on node user creation
jafreck 6e0885b
start create user on node implementation
jafreck 8cd247b
fix on node user creation
jafreck 38ada54
remove debug statements
jafreck dc12ed7
remove commented code
jafreck 569d917
line too long
jafreck e3a2806
fix spinner password prompt ui bug
jafreck 7119193
Merge branch 'feature/on-node-user-creation' of https://github.com/ja…
jafreck 2f5cc87
Merge branch 'master' into feature/on-node-user-creation
jafreck 527c17f
Merge branch 'master' into feature/on-node-user-creation
jafreck 2a03e0b
Merge branch 'feature/on-node-user-creation' of https://github.com/ja…
jafreck 06f85c2
set wait to false by default, formatting
jafreck 9186827
encrypt password on client, decrypt on node
jafreck b1a0b07
update docs, log warning if password used
jafreck 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import azure.batch.models as batch_models | ||
import azure.batch.models.batch_error as batch_error | ||
from Crypto.PublicKey import RSA | ||
from Crypto.Cipher import AES, PKCS1_OAEP | ||
from datetime import datetime, timezone, timedelta | ||
import yaml | ||
''' | ||
Creates a user if the user configuration file at $DOCKER_WORKING_DIR/user.yaml exists | ||
''' | ||
|
||
def create_user(batch_client): | ||
path = os.path.join(os.environ['DOCKER_WORKING_DIR'], "user.yaml") | ||
|
||
if not os.path.isfile(path): | ||
print("No user to create.") | ||
return | ||
|
||
with open(path) as file: | ||
user_conf = yaml.load(file.read()) | ||
|
||
try: | ||
password = None if user_conf['ssh-key'] else decrypt_password(user_conf) | ||
|
||
batch_client.compute_node.add_user( | ||
pool_id=os.environ['AZ_BATCH_POOL_ID'], | ||
node_id=os.environ['AZ_BATCH_NODE_ID'], | ||
user=batch_models.ComputeNodeUser( | ||
name=user_conf['username'], | ||
is_admin=True, | ||
password=password, | ||
ssh_public_key=str(user_conf['ssh-key']), | ||
expiry_time=datetime.now(timezone.utc) + timedelta(days=365) | ||
) | ||
) | ||
except batch_error.BatchErrorException as e: | ||
print(e) | ||
|
||
def decrypt_password(user_conf): | ||
cipher_text = user_conf['password'] | ||
encrypted_aes_session_key = user_conf['aes_session_key'] | ||
cipher_aes_nonce = user_conf['cipher_aes_nonce'] | ||
tag = user_conf['tag'] | ||
|
||
# Read private key | ||
private_key = RSA.import_key(open(os.path.join(os.environ['DOCKER_WORKING_DIR'], 'id_rsa')).read()) | ||
# Decrypt the session key with the public RSA key | ||
cipher_rsa = PKCS1_OAEP.new(private_key) | ||
session_key = cipher_rsa.decrypt(encrypted_aes_session_key) | ||
|
||
# Decrypt the data with the AES session key | ||
cipher_aes = AES.new(session_key, AES.MODE_EAX, cipher_aes_nonce) | ||
password = cipher_aes.decrypt_and_verify(cipher_text, tag) | ||
return password.decode("utf-8") |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ azure-storage==0.33.0 | |
azure-mgmt-storage==1.5.0 | ||
azure-mgmt-batch==5.0.0 | ||
pyyaml==3.12 | ||
pycryptodome==3.4.7 |
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.
Will this get auto-populated from the users' secrets.yaml?
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.
On the CLI, yeah -- that happens here:
https://github.com/jafreck/aztk/blob/06f85c2538db98e168fed8c38fe9b88524f95e5f/cli/spark/endpoints/cluster/cluster_create.py#L87
For the SDK, no the secrets.yaml file is not used at all.