Manage authorized_keys using cfengine

466 views Asked by At

I'm trying to manage OpenSSH's authorized_keys using cfengine.

It's easy to add/delete special lines in authorized_keys, but I cannot figure out how to delete unwanted lines.

e.g. I need to add pubkey_one, pubkey_two, pubkey_three to authorized_key, then delete any lines not listed above.

Any help or hint would appreciated :-)

1

There are 1 answers

2
Diego Zamboni On

For this particular case, I think the easiest would be to use edit_defaults => empty, so that CFEngine starts from an empty file. Something like this:

files:
  "/home/user/.ssh/authorized_keys"
    edit_defaults => empty,
    edit_line => add_authorized_keys;

Note that body edit_defaults empty is defined in cfengine_stdlib.cf, so you need to include it in your inputs.