wip
This commit is contained in:
parent
fc945d7f04
commit
6c178b514a
6 changed files with 27 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
from ipaddress import ip_interface
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'users': {
|
'users': {
|
||||||
'backup-receiver': {
|
'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(
|
@metadata_reactor.provides(
|
||||||
'users/backup-receiver/authorized_keys'
|
'users/backup-receiver/authorized_keys'
|
||||||
)
|
)
|
||||||
|
@ -15,7 +35,7 @@ def backup_authorized_keys(metadata):
|
||||||
'users': {
|
'users': {
|
||||||
'backup-receiver': {
|
'backup-receiver': {
|
||||||
'authorized_keys': [
|
'authorized_keys': [
|
||||||
other_node.metadata.get('users/backup/pubkey')
|
other_node.metadata.get('users/root/pubkey')
|
||||||
for other_node in repo.nodes
|
for other_node in repo.nodes
|
||||||
if other_node.has_bundle('backup')
|
if other_node.has_bundle('backup')
|
||||||
and other_node.metadata.get('backup/server') == node.name
|
and other_node.metadata.get('backup/server') == node.name
|
||||||
|
|
|
@ -5,7 +5,7 @@ directories['/etc/backup'] = {}
|
||||||
files['/etc/backup/config.json'] = {
|
files['/etc/backup/config.json'] = {
|
||||||
'content': dumps(
|
'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'))),
|
'paths': sorted(set(node.metadata.get('backup/paths'))),
|
||||||
},
|
},
|
||||||
indent=4,
|
indent=4,
|
||||||
|
|
|
@ -8,7 +8,4 @@ defaults = {
|
||||||
'server': None,
|
'server': None,
|
||||||
'paths': [],
|
'paths': [],
|
||||||
},
|
},
|
||||||
'users': {
|
|
||||||
'backup': {},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ def user(metadata):
|
||||||
|
|
||||||
if not 'privkey' in users[name] and not 'pubkey' in users[name]:
|
if not 'privkey' in users[name] and not 'pubkey' in users[name]:
|
||||||
privkey, pubkey = repo.libs.ssh.generate_ad25519_key_pair(
|
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]['keytype'] = 'ed25519'
|
||||||
users[name]['privkey'] = privkey
|
users[name]['privkey'] = privkey
|
||||||
|
|
|
@ -18,7 +18,7 @@ def generate_ad25519_key_pair(secret):
|
||||||
'-----BEGIN OPENSSH PRIVATE KEY-----',
|
'-----BEGIN OPENSSH PRIVATE KEY-----',
|
||||||
b64encode(deterministic_bytes).decode(),
|
b64encode(deterministic_bytes).decode(),
|
||||||
'-----END OPENSSH PRIVATE KEY-----',
|
'-----END OPENSSH PRIVATE KEY-----',
|
||||||
])
|
]) + '\n'
|
||||||
|
|
||||||
public_key = privkey_bytes.public_key().public_bytes(
|
public_key = privkey_bytes.public_key().public_bytes(
|
||||||
encoding=serialization.Encoding.OpenSSH,
|
encoding=serialization.Encoding.OpenSSH,
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
],
|
],
|
||||||
'metadata': {
|
'metadata': {
|
||||||
'id': '9cf52515-63a1-4659-a8ec-6c3c881727e5',
|
'id': '9cf52515-63a1-4659-a8ec-6c3c881727e5',
|
||||||
|
'backup-server': {
|
||||||
|
'hostname': 'backups.sublimity.de',
|
||||||
|
},
|
||||||
'network': {
|
'network': {
|
||||||
'interface': 'enp1s0',
|
'interface': 'enp1s0',
|
||||||
'ipv4': '10.0.0.5/24',
|
'ipv4': '10.0.0.5/24',
|
||||||
|
|
Loading…
Reference in a new issue