2020-11-14 13:35:54 +00:00
|
|
|
users_from_metadata = set()
|
2021-02-18 17:12:25 +00:00
|
|
|
additional_users = node.metadata.get('openssh/allowed_users', set())
|
2020-11-14 13:35:54 +00:00
|
|
|
|
|
|
|
for user, config in node.metadata.get('users', {}).items():
|
2021-02-18 14:12:30 +00:00
|
|
|
if 'ssh_pubkey' in config and not config.get('delete', False):
|
2020-11-14 13:35:54 +00:00
|
|
|
users_from_metadata.add(user)
|
|
|
|
|
|
|
|
login_users = users_from_metadata.union(additional_users)
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/ssh/sshd_config': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'login_users': login_users,
|
|
|
|
'admin_users': users_from_metadata,
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'action:sshd_check_config',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/systemd/system/ssh.service.d/bundlewrap.conf': {
|
|
|
|
'source': 'override.conf',
|
|
|
|
'triggers': {
|
|
|
|
'action:sshd_check_config',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:24:57 +00:00
|
|
|
if node.has_bundle('pacman'):
|
|
|
|
package = 'pkg_pacman:openssh'
|
|
|
|
service = 'sshd'
|
|
|
|
else:
|
|
|
|
package = 'pkg_apt:openssh-server'
|
|
|
|
service = 'ssh'
|
|
|
|
|
2020-11-14 13:35:54 +00:00
|
|
|
actions = {
|
|
|
|
'sshd_check_config': {
|
|
|
|
'command': 'sshd -T -C user=root -C host=localhost -C addr=localhost',
|
|
|
|
'triggered': True,
|
|
|
|
'triggers': {
|
2021-02-18 13:24:57 +00:00
|
|
|
'svc_systemd:{}:restart'.format(service),
|
2020-11-14 13:35:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
2021-02-18 13:24:57 +00:00
|
|
|
service: {
|
2020-11-14 13:35:54 +00:00
|
|
|
'needs': {
|
|
|
|
'file:/etc/systemd/system/ssh.service.d/bundlewrap.conf',
|
|
|
|
'file:/etc/ssh/sshd_config',
|
2021-02-18 13:24:57 +00:00
|
|
|
package,
|
2020-11-14 13:35:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|