ssh_auth absent call does not remove the key if source is used
I have the following ssh_auth call to add ssh root access:
root_ssh_key_{{ user_name }}:
ssh_auth.{{ state }}:
- user: root
- source: salt://ssh/keys/{{ user_name }}.id_rsa.pub
- require:
- user: {{ user_name }}
It works perfectly when state is set to present. But when I set the state to absent the salt says Key not present but it is still there.
The problem is that it create a security breach and if the source option is not supported, salt should warn me and not let me think that the key was removed.
I tried to use the ssh.py module from the develop branch but it do not work either.
My salt version:
# salt --versions-report
Salt: 0.17.5
Python: 2.7.3 (default, Jan 2 2013, 13:56:14)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.1.10
msgpack-pure: Not Installed
pycrypto: 2.6
PyYAML: 3.10
PyZMQ: 13.1.0
ZMQ: 3.2.3
Thanks for the report! We'll get this fixed.
I'm not totally convinced this is a bug as it sits, but I definitely agree that this needs some clarification.
What's happening here is that you're passing an arbitrary name of root_ssh_key_{{ user_name }} to the absent state and it looks for a key matching that name in the file. If you look at the actual .authorized_keys file, of course, there is no key by that name. It's only an ID known to Salt which has no correlation whatsoever with lines in the .authorized_keys file.
If you were to pass in a name that did match a key in the file, the absent state should function as expected. Here, it is doing the right thing (i.e., reporting that a given key isn't in the .authorized_keys) file, but I agree that it's a little unclear.
Would modifying the documentation for the ssh_auth module to reflect this distinction ease your concerns? Or, is there a better return message here? Thoughts, comments welcome. Thanks!
P.S. I'm going to tag this issue as 'Expected Behavior' until we can sort out what needs to be done here.
Alternatively, we could also support the source argument for the absent function and then pull down that key and use it for comparison. That might be a nice feature.
Yes, I think this would be a nice feature and until it is implemented the source argument should be forbidden with the absent function to avoid unattended behaviour.
I think it should compare the actual content of the key and remove it from authorized_keys. It would be easy to overlook that the name should match.
ZD-1397
Fixed by https://github.com/saltstack/salt/pull/12372