From f0b381dd53fbbbbae5683baa4482eee633907b6e Mon Sep 17 00:00:00 2001 From: Sean Marlow Date: Thu, 1 Apr 2021 15:19:12 -0500 Subject: [PATCH] Use cloud config instead of bash script. To set ssh key and confirm root login disabled. --- img_proof/ipa_constants.py | 7 +++++-- tests/test_ipa_cloud.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/img_proof/ipa_constants.py b/img_proof/ipa_constants.py index 4ef8d41d..4129fe61 100644 --- a/img_proof/ipa_constants.py +++ b/img_proof/ipa_constants.py @@ -45,8 +45,11 @@ IPA_HISTORY_FILE = os.path.join(HOME, '.config', 'img_proof', '.history') IPA_RESULTS_PATH = os.path.join(HOME, 'img_proof', 'results') -BASH_SSH_SCRIPT = '''#!/bin/bash -echo {key} >> /home/{user}/.ssh/authorized_keys +BASH_SSH_SCRIPT = '''#cloud-config +disable_root: true + +runcmd: + - [ sh, -c, 'echo {key} >> /home/{user}/.ssh/authorized_keys' ] ''' SYNC_POINTS = ( diff --git a/tests/test_ipa_cloud.py b/tests/test_ipa_cloud.py index 5f721677..85c27272 100644 --- a/tests/test_ipa_cloud.py +++ b/tests/test_ipa_cloud.py @@ -133,8 +133,11 @@ def test_cloud_get_user_data(self, mock_get_ssh_key): result = provider._get_user_data() assert result == \ - '#!/bin/bash\n' \ - 'echo testkey12345 >> /home/ec2-user/.ssh/authorized_keys\n' + "#cloud-config\n" \ + "disable_root: true\n\n" \ + "runcmd:\n" \ + " - [ sh, -c, 'echo testkey12345 >> " \ + "/home/ec2-user/.ssh/authorized_keys' ]\n" def test_cloud_get_non_null_values(self): """Test cloud get non null values method."""