module

Krikri::PluginHelpers::AuthorizedKeysFile

AuthorizedKeysFile - pure logic for ensuring a public key line is present/absent in an OpenSSH authorized_keys-style file, entirely without I/O so it's unit-testable with plain strings.

Constants

KEY_TYPES = ["sk-ecdsa-sha2-nistp256@openssh.com", "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com", "webauthn-sk-ecdsa-sha2-nistp256@openssh.com", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp256-cert-v01@openssh.com", "ecdsa-sha2-nistp384", "ecdsa-sha2-nistp384-cert-v01@openssh.com", "ecdsa-sha2-nistp521", "ecdsa-sha2-nistp521-cert-v01@openssh.com", "sk-ssh-ed25519@openssh.com", "sk-ssh-ed25519-cert-v01@openssh.com", "ssh-ed25519", "ssh-ed25519-cert-v01@openssh.com", "ssh-dss", "ssh-rsa", "ssh-xmss@openssh.com", "ssh-xmss-cert-v01@openssh.com", "rsa-sha2-256", "rsa-sha2-512", "ssh-rsa-cert-v01@openssh.com", "rsa-sha2-512-cert-v01@openssh.com", "ssh-dss-cert-v01@openssh.com"] of ::String

The Ansible module's own VALID_SSH2_KEY_TYPES (ansible.posix authorized_key's parsekey): a line is a key line iff one of its whitespace-separated tokens is exactly one of these.

Class methods

ensure(text : String, key_line : String, present : Bool) : Tuple(String, Bool)

Ensures key_line's signature is present (or absent) in text. Returns {new_text, changed}.

Source
ensure_keys(text : String, key_lines : Array(String), present : Bool, exclusive : Bool = false) : Tuple(String, Bool)

Multi-key form mirroring the Ansible module's enforce_state: each new key is matched against the file by its blob (the Ansible module's parsekeys dict is keyed on the blob alone), and "already present" means the whole parsed key matches - blob, type, OPTIONS DICT, and comment. key_options are part of that comparison in the real module (its parsed_new_key[:4] != existing_keys[blob][:4] check), so adding key_options: to an existing bare key is a real change: the old line is deleted and the options-prefixed line re-serialized (moved to the end of the file, like the Ansible module's delete-then-reinsert). On any write the whole file is re-serialized from its parsed keys, exactly like the Ansible module's serialize() pass. With exclusive (state present only), every existing key whose blob isn't among the new keys is deleted - the Ansible module's "remove all other keys to honor exclusive".

Source
key_signature(line : String) : String | Nil

Extracts the "type base64blob" portion of a key line, ignoring any leading options and trailing comment - that's what makes a key unique, matching how sshd itself treats authorized_keys entries. Returns nil for blank/comment/unparseable lines.

Source