################################################################## # # agent code # - keeps root's SSH private key readable by root only # ################################################################## bundle agent restrict_ssh_key_permissions { files: "/root/.ssh/id_ed25519" perms => m("600"); } ################################################################## # # reactor code # - restores the permissions of root's SSH private key as soon # as they change, and logs the change # ################################################################## body when permissions_changed(file) { file_permissions_changed => "$(file)"; } bundle reactor log_ssh_key_permissions_change { reports: "Permissions of /root/.ssh/id_ed25519 changed on $(sys.fqhost) and were restored"; } bundle reactor enforce_ssh_key_perms { events: "protect SSH key" when => permissions_changed("/root/.ssh/id_ed25519"), then => { restrict_ssh_key_permissions, log_ssh_key_permissions_change, }; }