salt icon indicating copy to clipboard operation
salt copied to clipboard

State ssh_auth.absent does not remove keys is type or options are present in key "name"

Open dlindquist opened this issue 13 years ago • 4 comments

Given that there is no example for ssh_auth.absent in the documentation, a Salt state writer might write the following state to remove a key by copying a key "name" that was previously specified in a ssh_auth.present state:

sshkeys:
  ssh_auth:
    - absent
    - user: root
    - comment: removing user@email from authorized keys
    - names:
      - ssh-rsa AAAAB3Nza[...]== user@mail

However, Salt will falsely return that the key is not present. This is because the absent function uses:

    # Get just the key
    name = name.split(' ')[0]

https://github.com/saltstack/salt/blob/fbfd926fdd0c7686b6be4da1dbfe4e9e18bbea60/salt/states/ssh_auth.py#L272

For the above example, the ssh_auth.absent state will incorrectly check for the key "ssh-rsa" using the ssh.check_key module.

I've verified that the remove key operation works properly if the "ssh-rsa" prefix is omitted in the example above.

dlindquist avatar Nov 20 '13 19:11 dlindquist

Good call. We should make sure present and absent take the same inputs so you can copy and paste. (That's the problem, right? Copying and pasting?)

basepi avatar Nov 20 '13 22:11 basepi

Copy and pasting from a present state was what caught this issue for us. However, pasting a key in from a .pub file could have triggered this issue as well.

dlindquist avatar Nov 20 '13 23:11 dlindquist

Ah, gotcha. Thanks.

basepi avatar Nov 20 '13 23:11 basepi

Fixed with PR #9030

cro avatar Dec 04 '13 20:12 cro