Skip to content

Commit cdc5b81

Browse files
authored
Revert "ssh_util: handle non-default AuthorizedKeysFile config (canonical#586)" (canonical#775)
This reverts commit b0e7381.
1 parent 1163004 commit cdc5b81

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

cloudinit/ssh_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ def extract_authorized_keys(username, sshd_cfg_file=DEF_SSHD_CFG):
262262

263263
except (IOError, OSError):
264264
# Give up and use a default key filename
265-
auth_key_fns.append(default_authorizedkeys_file)
265+
auth_key_fns[0] = default_authorizedkeys_file
266266
util.logexc(LOG, "Failed extracting 'AuthorizedKeysFile' in SSH "
267267
"config from %r, using 'AuthorizedKeysFile' file "
268268
"%r instead", DEF_SSHD_CFG, auth_key_fns[0])
269269

270-
# always store all the keys in the first file configured on sshd_config
271-
return (auth_key_fns[0], parse_authorized_keys(auth_key_fns))
270+
# always store all the keys in the user's private file
271+
return (default_authorizedkeys_file, parse_authorized_keys(auth_key_fns))
272272

273273

274274
def setup_user_keys(keys, username, options=None):

tests/unittests/test_sshutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def test_multiple_authorizedkeys_file_order1(self, m_getpwnam):
593593
fpw.pw_name, sshd_config)
594594
content = ssh_util.update_authorized_keys(auth_key_entries, [])
595595

596-
self.assertEqual(authorized_keys, auth_key_fn)
596+
self.assertEqual("%s/.ssh/authorized_keys" % fpw.pw_dir, auth_key_fn)
597597
self.assertTrue(VALID_CONTENT['rsa'] in content)
598598
self.assertTrue(VALID_CONTENT['dsa'] in content)
599599

@@ -610,15 +610,15 @@ def test_multiple_authorizedkeys_file_order2(self, m_getpwnam):
610610
sshd_config = self.tmp_path('sshd_config')
611611
util.write_file(
612612
sshd_config,
613-
"AuthorizedKeysFile %s %s" % (user_keys, authorized_keys)
613+
"AuthorizedKeysFile %s %s" % (authorized_keys, user_keys)
614614
)
615615

616616
(auth_key_fn, auth_key_entries) = ssh_util.extract_authorized_keys(
617617
fpw.pw_name, sshd_config
618618
)
619619
content = ssh_util.update_authorized_keys(auth_key_entries, [])
620620

621-
self.assertEqual(user_keys, auth_key_fn)
621+
self.assertEqual("%s/.ssh/authorized_keys" % fpw.pw_dir, auth_key_fn)
622622
self.assertTrue(VALID_CONTENT['rsa'] in content)
623623
self.assertTrue(VALID_CONTENT['dsa'] in content)
624624

0 commit comments

Comments
 (0)