Skip to content

Commit 1ca9f81

Browse files
committed
roles/ssh_server: multi key and OpenSSH v8 support
Add support for OpenSSH v8 (ouput of `ssh-keygen` changed slightly) in module `ssh_cert` and use a better implementation for multiple user CA. Now we are reading user_ca from `group_vars/all.yaml`. `user_ca_keys` should be list of each allowed User CA on one host (in this way is easier to rotate CAs without reissuing keys to each user at the same time). The production CA must be the first one in the list. Host certificate will be checked only against the first CA and updated if their host key was issued from another CA in the list. For this reason now we are using a template to create `/etc/ssh/user_ca.pub` on the target, to preserve the key order. `group_vars/all.yaml.example` has been updated to reflect the new usage.
1 parent 1ca84a3 commit 1ca9f81

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

group_vars/all.yaml.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
management_gateway: 0.0.0.0
44
# ip of the vm vlan gateway
55
vm_gateway: 0.0.0.0
6-
# Put here the public key of the users CA.
7-
user_ca_key: ""
6+
# Put here a list of public keys for each allowed users CA.
7+
# The first one should be the current production one.
8+
user_ca_keys:
9+
- ""
810
# Put here the public ip for your organisation
911
public_ip: 0.0.0.0
1012
# Put here the domain for your organisation

library/ssh_cert.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def serial(lines):
2424
def signin_ca(lines):
2525
for l in lines:
2626
if l.startswith('Signing CA'):
27-
return l.split().pop()
27+
# return l.split().pop()
28+
# Starting from OpenSSH v8 the output format of ssh-keygen
29+
# has changed, this should work for all versions:
30+
return l.split()[3]
31+
2832

2933

3034
def still_valid(cert_timestamps):
@@ -79,6 +83,8 @@ def main():
7983
'-f', result['ca']['path'],
8084
])
8185

86+
# If multiple CA are present verify cert against the first one
87+
ca_output = ca_output.splitlines()[0]
8288
ca_lines = ca_output.decode().split(maxsplit=2)
8389
result['ca']['fingerprint'] = ca_lines[1]
8490
result['ca']['comment'] = ca_lines[2]

roles/ssh_server/tasks/main.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
- openssh-server
99
- openssh-sftp-server
1010

11-
- name: lookup user ca key
12-
set_fact:
13-
user_ca_key: "{{ lookup('file', 'lilik_ca_s1.pub') }}"
14-
1511
- name: Update container user CA key
16-
copy:
17-
content: "{{ user_ca_key }}"
12+
template:
13+
src: user_ca.pub.j2
1814
dest: "/etc/ssh/user_ca.pub"
1915
notify: restart ssh
2016

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% for key in user_ca_keys %}
2+
{{ key }}
3+
{% endfor %}
4+

0 commit comments

Comments
 (0)