I need to clean up a bit the authorized keys files on our infra
i created a simple palybook that goes and removed one key from the remote authorized_keys files but when I run it in check/diff mode i see it tried to remove far too many lines
no the key are differents but i think that ansible modules only match the beginning of the line but not the whole file
i am not going to list all the public keys here but:
the public key that has to be removed and the ones that are wrongly being removed have the ‘same’ beginning::
ssh-rsa AAAAB3NzaC1yc2EAAAA…
after this both lines in authorized keys differ
so does the authorized_key module only looks for the beginning of the line?
the /path/to/totpubkey.pub is a normal regular ssh-rsa public key file are standard public file with the publick key and authorized key files are one key per line… nothing fancy
The fact that multiple keys begin with AAAAB3NzaC1yc2EAAAA is because
they share the same header - this is OK.
The module takes the entire key string into account.
Can you maybe reproduce this in a way that we can look at it?
Otherwise it will be impossible to tell what is wrong (other that
guessing what it might be).
You could try and anonymize the usernames and comments and if that has the same problems, post that file. Then you’d be only posting public keys but no user names etc?
I am working on it to provide you an use case… but.
is by any chance the authorizing_file modules sanitizing aka removing duplicates entries on the remote authorized_key file even if it was not in the key string passed to be removed
in that case there is probably no issue i must do some tests
>
> I am working on it to provide you an use case.. but.
>
> is by any chance the authorizing_file modules sanitizing aka
> removing duplicates entries on the remote authorized_key file even
> if it was not in the key string passed to be removed
The value in the dictionary contains more information so that the file
can be rebuilt - except that duplicate keys won't survive.
It's probably a good idea to mention that in the module docs. If
someone wants to create a PR for that (it's a good start to trying PRs
for collections!), feel free!
created on vagrant some ssh files and created a authorized_keys with duplicates and tried to add/remove a line that is not a duplicate
the result is that if there is a line to be added/removed from the authorized_keys files the duplicates are also removed if there are no lines found to be removed then nothing happens
illustration:
authorized keys files notice the publicates in line 1,4,5 line 4 has a different comment line 5 has no comment