sshd_cert: First version of role

This commit is contained in:
Timo Makinen 2024-03-23 19:18:30 +00:00
parent df2573a650
commit 7ce6d58923
3 changed files with 47 additions and 0 deletions

View file

@ -48,6 +48,7 @@
- pki
- psacct
- sshd
- sshd_cert
- node_exporter
loop_control:
loop_var: role

View file

@ -0,0 +1,3 @@
---
dependencies:
- {role: sshd}

View file

@ -0,0 +1,43 @@
---
- name: Copy public key for signing
ansible.builtin.fetch:
src: /etc/ssh/ssh_host_ed25519_key.pub
dest: "/srv/sshca/pubkeys/{{ inventory_hostname }}.pub"
flat: true
- name: Sign key
ansible.builtin.command:
argv:
- ssh-keygen
- -s
- /srv/sshca/ca/ca
- -I
- "{{ inventory_hostname }}"
- -h
- -n
- "{{ inventory_hostname }}"
- -V
- -1h:+365d
- -z
- "{{ ansible_date_time.epoch }}"
- "/srv/sshca/pubkeys/{{ inventory_hostname }}.pub"
creates: "/srv/sshca/pubkeys/{{ inventory_hostname }}-cert.pub"
delegate_to: localhost
- name: Install certificate
ansible.builtin.copy:
dest: /etc/ssh/ssh_host_ed25519_key-cert.pub
src: "/srv/sshca/pubkeys/{{ inventory_hostname }}-cert.pub"
mode: "0644"
owner: root
group: "{{ ansible_wheel }}"
notify: Restart sshd
- name: Enable host certificate
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
line: HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
regexp: "^(# )?HostCertificate .*"
insertafter: "^HostKey .*"
validate: "sshd -t -f %s"
notify: Restart sshd