This commit is contained in:
mwiegand 2021-06-25 18:41:02 +02:00
parent fc945d7f04
commit 6c178b514a
6 changed files with 27 additions and 7 deletions

View file

@ -1,3 +1,5 @@
from ipaddress import ip_interface
defaults = {
'users': {
'backup-receiver': {
@ -7,6 +9,24 @@ defaults = {
}
@metadata_reactor.provides(
'dns'
)
def dns(metadata):
records = {}
if metadata.get('network/ipv4', None):
records['A'] = [str(ip_interface(metadata.get('network/ipv4')).ip)]
if metadata.get('network/ipv6', None):
records['AAAA'] = [str(ip_interface(metadata.get('network/ipv6')).ip)]
return {
'dns': {
metadata.get('backup-server/hostname'): records,
},
}
@metadata_reactor.provides(
'users/backup-receiver/authorized_keys'
)
@ -15,7 +35,7 @@ def backup_authorized_keys(metadata):
'users': {
'backup-receiver': {
'authorized_keys': [
other_node.metadata.get('users/backup/pubkey')
other_node.metadata.get('users/root/pubkey')
for other_node in repo.nodes
if other_node.has_bundle('backup')
and other_node.metadata.get('backup/server') == node.name

View file

@ -5,7 +5,7 @@ directories['/etc/backup'] = {}
files['/etc/backup/config.json'] = {
'content': dumps(
{
'server': node.metadata.get('backup/server'),
'server_hostname': repo.get_node(node.metadata.get('backup/server')).metadata.get('backup-server/hostname'),
'paths': sorted(set(node.metadata.get('backup/paths'))),
},
indent=4,

View file

@ -8,7 +8,4 @@ defaults = {
'server': None,
'paths': [],
},
'users': {
'backup': {},
},
}

View file

@ -32,7 +32,7 @@ def user(metadata):
if not 'privkey' in users[name] and not 'pubkey' in users[name]:
privkey, pubkey = repo.libs.ssh.generate_ad25519_key_pair(
b64decode(str(repo.vault.random_bytes_as_base64_for(metadata.get('id'), length=32)))
b64decode(str(repo.vault.random_bytes_as_base64_for(f"{name}@{metadata.get('id')}", length=32)))
)
users[name]['keytype'] = 'ed25519'
users[name]['privkey'] = privkey

View file

@ -18,7 +18,7 @@ def generate_ad25519_key_pair(secret):
'-----BEGIN OPENSSH PRIVATE KEY-----',
b64encode(deterministic_bytes).decode(),
'-----END OPENSSH PRIVATE KEY-----',
])
]) + '\n'
public_key = privkey_bytes.public_key().public_bytes(
encoding=serialization.Encoding.OpenSSH,

View file

@ -9,6 +9,9 @@
],
'metadata': {
'id': '9cf52515-63a1-4659-a8ec-6c3c881727e5',
'backup-server': {
'hostname': 'backups.sublimity.de',
},
'network': {
'interface': 'enp1s0',
'ipv4': '10.0.0.5/24',