Skip to content

Commit

Permalink
Handle invalid ssh keys, fix saltstack#987
Browse files Browse the repository at this point in the history
ssh keys cannot have spaces, return failure string on invalid ssh keys, fix
issue where keys with comments were added over and over.
  • Loading branch information
Andrew Kuhnhausen committed Mar 22, 2012
1 parent 8672288 commit 5c0a238
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions salt/modules/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _replace_auth_key(
enc,
comment,
options)

lines = []
uinfo = __salt__['user.info'](user)
full = os.path.join(uinfo['home'], config)
Expand Down Expand Up @@ -161,13 +162,8 @@ def _validate_keys(key_file):
options = []

enc = comps[0]
# check if key has a space
if len(comps) == 3:
key = comps[1] + ' ' + comps[2]
comment = ' '.join(comps[3:])
else:
key = comps[1]
comment = ' '.join(comps[2:])
key = comps[1]
comment = ' '.join(comps[2:])

ret[key] = {'enc': enc,
'comment': comment,
Expand Down Expand Up @@ -221,10 +217,7 @@ def rm_auth_key(user, key, config='.ssh/authorized_keys'):
else:
options = []

if len(comps) == 3:
pkey = comps[1] + ' ' + comps[2]
else:
pkey = comps[1]
pkey = comps[1]

if pkey == key:
continue
Expand Down Expand Up @@ -281,6 +274,9 @@ def set_auth_key(
salt '*' ssh.set_auth_key <user> <key> dsa 'my key' '[]' .ssh/authorized_keys
'''
if len(key.split()) > 1:
return "Fail: SSH key has spaces"

enc = _refine_enc(enc)
replace = False
uinfo = __salt__['user.info'](user)
Expand Down

0 comments on commit 5c0a238

Please sign in to comment.