Skip to content

Commit e6bbb5d

Browse files
author
Lorenzo Zolfanelli
committed
server_ssh: do not overwrite existing user ca if not managed by ansible
Only one key is managed by Ansible at time, if not-managed keys are present in user_ca.pub they are not removed, but the new key is appended to the file. If the ansible-managed key is changed it is overwritten. The ansible-managed key is detected using a leadind tag in the key line in user_ca.pub. Maybe it would be best to have a "key" version parameter and variable with options to enable key rotation/revocation. Anyway it provides an easy way to push new user ca while machine already configured with previous version of this role will still accept login from user with certificate issued from the older cas.
1 parent e0f1d25 commit e6bbb5d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

roles/ssh_server/tasks/main.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
set_fact:
1313
user_ca_key: "{{ lookup('file', 'lilik_ca_s1.pub') }}"
1414

15-
- name: Update container user CA key
16-
copy:
17-
content: "{{ user_ca_key }}"
15+
- name: Update container user CA cert
16+
lineinfile:
17+
line: "{{ user_ca_key }} +AnsibleManaged_CA_cert"
18+
regexp: " \+AnsibleManaged_CA_cert"
1819
dest: "/etc/ssh/user_ca.pub"
20+
create: yes
1921
notify: restart ssh
2022

2123
- name: Validate SSH host certificate if any

0 commit comments

Comments
 (0)