From ce84d0a81ee5d9634ed93df08a974115ae41a439 Mon Sep 17 00:00:00 2001 From: Nihal Muktala Date: Tue, 22 Aug 2023 15:22:40 +0000 Subject: [PATCH 1/5] Fix for issue #144 --- ebcli/operations/sshops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebcli/operations/sshops.py b/ebcli/operations/sshops.py index 9a5e48f23..e9a0b4e09 100644 --- a/ebcli/operations/sshops.py +++ b/ebcli/operations/sshops.py @@ -132,7 +132,7 @@ def ssh_into_instance(instance_id, keep_open=False, force_open=False, custom_ssh custom_ssh = custom_ssh.split() else: ident_file = _get_ssh_file(keypair_name) - custom_ssh = ['ssh', '-i', ident_file] + custom_ssh = ['ssh', '-i', ident_file, '-o', 'IdentitiesOnly yes'] custom_ssh.extend([user + '@' + ip]) From d71f554b4ced939c0c3390c54ebd98f3e367b656 Mon Sep 17 00:00:00 2001 From: NihalM99 Date: Fri, 20 Oct 2023 01:29:04 +0000 Subject: [PATCH 2/5] Fix for tests --- tests/unit/operations/test_sshops.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/unit/operations/test_sshops.py b/tests/unit/operations/test_sshops.py index 7047236d2..895b53bbf 100644 --- a/tests/unit/operations/test_sshops.py +++ b/tests/unit/operations/test_sshops.py @@ -55,7 +55,9 @@ def test_generate_and_upload_keypair__exit_code_0( '-f', os.path.expanduser('~') + '{0}.ssh{0}aws-eb-us-west-2'.format(os.path.sep), '-C', - 'aws-eb-us-west-2' + 'aws-eb-us-west-2', + '-o', + 'IdentitiesOnly yes' ] ) @@ -81,7 +83,9 @@ def test_generate_and_upload_keypair__exit_code_1( '-f', os.path.expanduser('~') + '{0}.ssh{0}aws-eb-us-west-2'.format(os.path.sep), '-C', - 'aws-eb-us-west-2' + 'aws-eb-us-west-2', + '-o', + 'IdentitiesOnly yes' ] ) @@ -320,7 +324,7 @@ def test_ssh_into_instance__uses_private_address( call_mock.return_value = 0 sshops.ssh_into_instance('instance-id') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@172.31.35.210']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@172.31.35.210', '-o', 'IdentitiesOnly yes']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -346,7 +350,7 @@ def test_ssh_into_instance__ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_not_called() revoke_ssh_mock.assert_not_called() - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238', '-o', 'IdentitiesOnly yes']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -372,7 +376,7 @@ def test_ssh_into_instance__no_ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_called_once_with('sg-12312313') revoke_ssh_mock.assert_called_once_with('sg-12312313') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238','-o', 'IdentitiesOnly yes']) @mock.patch('ebcli.operations.sshops.prompt_for_ec2_keyname') @mock.patch('ebcli.operations.sshops.commonops.update_environment') From 79f575e4901e4cccd3f4985e534c035bebe5182e Mon Sep 17 00:00:00 2001 From: NihalM99 Date: Fri, 20 Oct 2023 02:05:02 +0000 Subject: [PATCH 3/5] Test --- tests/unit/operations/test_sshops.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/unit/operations/test_sshops.py b/tests/unit/operations/test_sshops.py index 895b53bbf..81b939a67 100644 --- a/tests/unit/operations/test_sshops.py +++ b/tests/unit/operations/test_sshops.py @@ -55,9 +55,7 @@ def test_generate_and_upload_keypair__exit_code_0( '-f', os.path.expanduser('~') + '{0}.ssh{0}aws-eb-us-west-2'.format(os.path.sep), '-C', - 'aws-eb-us-west-2', - '-o', - 'IdentitiesOnly yes' + 'aws-eb-us-west-2' ] ) @@ -84,8 +82,6 @@ def test_generate_and_upload_keypair__exit_code_1( os.path.expanduser('~') + '{0}.ssh{0}aws-eb-us-west-2'.format(os.path.sep), '-C', 'aws-eb-us-west-2', - '-o', - 'IdentitiesOnly yes' ] ) @@ -324,7 +320,7 @@ def test_ssh_into_instance__uses_private_address( call_mock.return_value = 0 sshops.ssh_into_instance('instance-id') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@172.31.35.210', '-o', 'IdentitiesOnly yes']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@172.31.35.210']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -350,7 +346,7 @@ def test_ssh_into_instance__ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_not_called() revoke_ssh_mock.assert_not_called() - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238', '-o', 'IdentitiesOnly yes']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -376,7 +372,7 @@ def test_ssh_into_instance__no_ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_called_once_with('sg-12312313') revoke_ssh_mock.assert_called_once_with('sg-12312313') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238','-o', 'IdentitiesOnly yes']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) @mock.patch('ebcli.operations.sshops.prompt_for_ec2_keyname') @mock.patch('ebcli.operations.sshops.commonops.update_environment') From 9a8cdf6d113508aaf8883afeac68c0db438d869d Mon Sep 17 00:00:00 2001 From: NihalM99 Date: Fri, 20 Oct 2023 03:00:39 +0000 Subject: [PATCH 4/5] Fix tests --- tests/unit/operations/test_sshops.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/operations/test_sshops.py b/tests/unit/operations/test_sshops.py index 81b939a67..c83f3e3d9 100644 --- a/tests/unit/operations/test_sshops.py +++ b/tests/unit/operations/test_sshops.py @@ -320,7 +320,7 @@ def test_ssh_into_instance__uses_private_address( call_mock.return_value = 0 sshops.ssh_into_instance('instance-id') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@172.31.35.210']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', '-o', 'IdentitiesOnly yes', 'ec2-user@172.31.35.210']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -346,7 +346,7 @@ def test_ssh_into_instance__ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_not_called() revoke_ssh_mock.assert_not_called() - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', '-o', 'IdentitiesOnly yes', 'ec2-user@54.218.96.238']) @mock.patch('ebcli.operations.sshops.ec2.describe_instance') @mock.patch('ebcli.operations.sshops.ec2.describe_security_group') @@ -372,7 +372,7 @@ def test_ssh_into_instance__no_ssh_rule_exists( sshops.ssh_into_instance('instance-id') authorize_ssh_mock.assert_called_once_with('sg-12312313') revoke_ssh_mock.assert_called_once_with('sg-12312313') - call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', 'ec2-user@54.218.96.238']) + call_mock.assert_called_once_with(['ssh', '-i', 'aws-eb-us-west-2', '-o', 'IdentitiesOnly yes', 'ec2-user@54.218.96.238']) @mock.patch('ebcli.operations.sshops.prompt_for_ec2_keyname') @mock.patch('ebcli.operations.sshops.commonops.update_environment') From 27af63aa2e23e6270ba78280a486930e7ad11a8d Mon Sep 17 00:00:00 2001 From: NihalM99 <97417949+NihalM99@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:03:47 -0700 Subject: [PATCH 5/5] Update test_sshops.py --- tests/unit/operations/test_sshops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/operations/test_sshops.py b/tests/unit/operations/test_sshops.py index c83f3e3d9..6b9ff47a0 100644 --- a/tests/unit/operations/test_sshops.py +++ b/tests/unit/operations/test_sshops.py @@ -81,7 +81,7 @@ def test_generate_and_upload_keypair__exit_code_1( '-f', os.path.expanduser('~') + '{0}.ssh{0}aws-eb-us-west-2'.format(os.path.sep), '-C', - 'aws-eb-us-west-2', + 'aws-eb-us-west-2' ] )