wip
This commit is contained in:
parent
f37e2d2fbd
commit
cb8eb8dac2
4 changed files with 81 additions and 20 deletions
|
@ -1,3 +1,2 @@
|
||||||
include "/etc/bind/named.conf.options";
|
include "/etc/bind/named.conf.options";
|
||||||
include "/etc/bind/named.conf.local";
|
include "/etc/bind/named.conf.local";
|
||||||
include "/etc/bind/named.conf.default-zones";
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
% for view in views:
|
||||||
|
view "${view['name']}" {
|
||||||
|
match-clients {${' '.join(f'{e}; ' for e in view['acl'])}};
|
||||||
% for zone in zones:
|
% for zone in zones:
|
||||||
zone "${zone}" {
|
zone "${zone}" {
|
||||||
type master;
|
type master;
|
||||||
file "/var/lib/bind/db.${zone}";
|
file "/var/lib/bind/${view['name']}/db.${zone}";
|
||||||
};
|
};
|
||||||
% endfor
|
% endfor
|
||||||
|
include "/etc/bind/named.conf.default-zones";
|
||||||
include "/etc/bind/zones.rfc1918";
|
include "/etc/bind/zones.rfc1918";
|
||||||
|
};
|
||||||
|
% endfor
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
directories['/var/lib/bind'] = {
|
from ipaddress import ip_address
|
||||||
|
|
||||||
|
directories[f'/var/lib/bind'] = {
|
||||||
'purge': True,
|
'purge': True,
|
||||||
'needed_by': [
|
'needed_by': [
|
||||||
'svc_systemd:bind9',
|
'svc_systemd:bind9',
|
||||||
|
@ -38,9 +40,28 @@ files['/etc/bind/named.conf.options'] = {
|
||||||
'svc_systemd:bind9:restart',
|
'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'] = {
|
files['/etc/bind/named.conf.local'] = {
|
||||||
'content_type': 'mako',
|
'content_type': 'mako',
|
||||||
'context': {
|
'context': {
|
||||||
|
'views': views,
|
||||||
'zones': sorted(node.metadata.get('bind/zones')),
|
'zones': sorted(node.metadata.get('bind/zones')),
|
||||||
},
|
},
|
||||||
'owner': 'root',
|
'owner': 'root',
|
||||||
|
@ -53,14 +74,50 @@ files['/etc/bind/named.conf.local'] = {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
],
|
||||||
|
'triggers': [
|
||||||
|
'svc_systemd:bind9:restart',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
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/db.{zone}'] = {
|
files[f"/var/lib/bind/{view['name']}/db.{zone}"] = {
|
||||||
'group': 'bind',
|
'group': 'bind',
|
||||||
'source': 'db',
|
'source': 'db',
|
||||||
'content_type': 'mako',
|
'content_type': 'mako',
|
||||||
'context': {
|
'context': {
|
||||||
'records': records,
|
'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': [
|
'needed_by': [
|
||||||
'svc_systemd:bind9',
|
'svc_systemd:bind9',
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue