Skip to content

Commit

Permalink
Use a bash script to add ssh key.
Browse files Browse the repository at this point in the history
Instead of using cloud-init a bash script removes more variables
from the equation.
  • Loading branch information
smarlowucf committed Mar 21, 2018
1 parent 7ded067 commit f9b5ed7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions ipa/ipa_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
IPA_HISTORY_FILE = os.path.join(HOME, '.config', 'ipa', '.history')
IPA_RESULTS_PATH = os.path.join(HOME, 'ipa', 'results')

CLOUD_INIT_CONFIG = '''#cloud-config
users:
- name: {user}
ssh-authorized-keys:
- {key}
BASH_SSH_SCRIPT = '''#!/bin/bash
echo {key} >> /home/{user}/.ssh/authorized_keys
'''

SYNC_POINTS = (
Expand Down
4 changes: 2 additions & 2 deletions ipa/ipa_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ipa import ipa_utils
from ipa.ipa_constants import (
CLOUD_INIT_CONFIG,
BASH_SSH_SCRIPT,
EC2_CONFIG_FILE,
EC2_DEFAULT_TYPE,
EC2_DEFAULT_USER
Expand Down Expand Up @@ -238,7 +238,7 @@ def _get_user_data(self):
the ssh user and private key file.
"""
key = ipa_utils.generate_public_ssh_key(self.ssh_private_key).decode()
data = CLOUD_INIT_CONFIG.format(user=self.ssh_user, key=key)
data = BASH_SSH_SCRIPT.format(user=self.ssh_user, key=key)
return data

def _launch_instance(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ipa_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def test_ec2_get_user_data(self, mock_generate_ssh_key):

result = provider._get_user_data()

assert result == '#cloud-config\nusers:\n - name: ec2-user\n ' \
'ssh-authorized-keys:\n - testkey12345\n'
assert result == '#!/bin/bash\n' \
'echo testkey12345 >> /home/ec2-user/.ssh/authorized_keys\n'

@patch.object(EC2Provider, '_get_user_data')
@patch.object(EC2Provider, '_get_subnet')
Expand Down

0 comments on commit f9b5ed7

Please sign in to comment.