This commit is contained in:
mwiegand 2021-06-26 13:36:22 +02:00
parent f37e2d2fbd
commit cb8eb8dac2
4 changed files with 81 additions and 20 deletions

View file

@ -1,6 +1,6 @@
<%!
def column_width(column, table):
return max(map(lambda row: len(row[column]), table)) if table else 0
return max(map(lambda row: len(row[column]), table)) if table else 0
%>\
$TTL 600
@ IN SOA ns.sublimity.de. admin.sublimity.de. (
@ -15,9 +15,9 @@ $TTL 600
${(record['name'] or '@').ljust(column_width('name', records))} \
IN \
${record['type'].ljust(column_width('type', records))} \
% if record['type'] == 'TXT':
% if record['type'] == 'TXT':
(${' '.join('"'+record['value'][i:i+255]+'"' for i in range(0, len(record['value']), 255))})
% else:
% else:
${record['value']}
% endif
% endif
% endfor

View file

@ -1,3 +1,2 @@
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

View file

@ -1,8 +1,13 @@
% for zone in zones:
zone "${zone}" {
type master;
file "/var/lib/bind/db.${zone}";
% for view in views:
view "${view['name']}" {
match-clients {${' '.join(f'{e}; ' for e in view['acl'])}};
% for zone in zones:
zone "${zone}" {
type master;
file "/var/lib/bind/${view['name']}/db.${zone}";
};
% endfor
include "/etc/bind/named.conf.default-zones";
include "/etc/bind/zones.rfc1918";
};
% endfor
include "/etc/bind/zones.rfc1918";

View file

@ -1,4 +1,6 @@
directories['/var/lib/bind'] = {
from ipaddress import ip_address
directories[f'/var/lib/bind'] = {
'purge': True,
'needed_by': [
'svc_systemd:bind9',
@ -38,9 +40,28 @@ files['/etc/bind/named.conf.options'] = {
'svc_systemd:bind9:restart',
],
}
views = [
{
'name': 'internal',
'is_internal': True,
'acl': [
'10.0.0.0/16',
]
},
{
'name': 'external',
'is_internal': False,
'acl': [
'any',
]
},
]
files['/etc/bind/named.conf.local'] = {
'content_type': 'mako',
'context': {
'views': views,
'zones': sorted(node.metadata.get('bind/zones')),
},
'owner': 'root',
@ -53,14 +74,27 @@ files['/etc/bind/named.conf.local'] = {
],
}
for zone, records in node.metadata.get('bind/zones').items():
files[f'/var/lib/bind/db.{zone}'] = {
'group': 'bind',
'source': 'db',
'content_type': 'mako',
'context': {
'records': records,
},
def use_record(record, records, view):
if record['type'] in ['A', 'AAAA']:
if view == 'external':
# no internal addresses in external view
if ip_address(record['value']).is_private:
return False
elif view == 'internal':
# external addresses in internal view only, if no internal exists
if ip_address(record['value']).is_global:
for other_record in records:
if (
record['name'] == other_record['name'] and
record['type'] == other_record['type'] and
ip_address(other_record['value']).is_private
):
return False
return True
for view in views:
directories[f"/var/lib/bind/{view['name']}"] = {
'purge': True,
'needed_by': [
'svc_systemd:bind9',
],
@ -69,6 +103,29 @@ for zone, records in node.metadata.get('bind/zones').items():
],
}
for zone, records in node.metadata.get('bind/zones').items():
files[f"/var/lib/bind/{view['name']}/db.{zone}"] = {
'group': 'bind',
'source': 'db',
'content_type': 'mako',
'context': {
'view': view['name'],
'records': list(filter(
lambda record: use_record(record, records, view['name']),
records
)),
},
'needs': [
f"directory:/var/lib/bind/{view['name']}",
],
'needed_by': [
'svc_systemd:bind9',
],
'triggers': [
'svc_systemd:bind9:restart',
],
}
svc_systemd['bind9'] = {}
actions['named-checkconf'] = {