This commit is contained in:
mwiegand 2021-11-07 13:20:45 +01:00
parent 5400df94ed
commit 02bd0b6511
4 changed files with 63 additions and 37 deletions

View file

@ -9,7 +9,6 @@ defaults = {
}, },
}, },
'bind': { 'bind': {
'zones': {},
'slaves': {}, 'slaves': {},
'views': { 'views': {
'internal': { 'internal': {
@ -22,6 +21,7 @@ defaults = {
'192.168.0.0/16', '192.168.0.0/16',
}, },
'keys': {}, 'keys': {},
'zones': {},
}, },
'external': { 'external': {
'default': True, 'default': True,
@ -31,6 +31,7 @@ defaults = {
'any', 'any',
}, },
'keys': {}, 'keys': {},
'zones': {},
}, },
}, },
'keys': { 'keys': {
@ -81,36 +82,40 @@ def collect_records(metadata):
if metadata.get('bind/type') == 'slave': if metadata.get('bind/type') == 'slave':
return {} return {}
zones = {} views = {}
for other_node in repo.nodes:
for fqdn, records in other_node.metadata.get('dns', {}).items():
matching_zones = sorted(
filter(
lambda potential_zone: fqdn.endswith(potential_zone),
metadata.get('bind/zones').keys()
),
key=len,
)
if matching_zones:
zone = matching_zones[-1]
else:
continue
name = fqdn[0:-len(zone) - 1] for view_name, view_conf in metadata.get('bind/views').items():
for other_node in repo.nodes:
for fqdn, records in other_node.metadata.get('dns', {}).items():
matching_zones = sorted(
filter(
lambda potential_zone: fqdn.endswith(potential_zone),
metadata.get('bind/zones').keys()
),
key=len,
)
if matching_zones:
zone = matching_zones[-1]
else:
continue
for type, values in records.items(): name = fqdn[0:-len(zone) - 1]
for value in values:
zones\ for type, values in records.items():
.setdefault(zone, {})\ for value in values:
.setdefault('records', set())\ if repo.libs.bind.record_matches_view(value, type, name, zone, view_name, metadata, repo):
.add( views\
h({'name': name, 'type': type, 'value': value}) .setdefault(view_name, {})\
) .setdefault('zones', {})\
.setdefault(zone, {})\
.setdefault('records', set())\
.add(
h({'name': name, 'type': type, 'value': value})
)
return { return {
'bind': { 'bind': {
'zones': zones, 'views': views,
}, },
} }

32
libs/bind.py Normal file
View file

@ -0,0 +1,32 @@
from ipaddress import ip_address
def record_matches_view(value, type, name, zone, view, metadata, repo):
if type not in ['A', 'AAAA']:
return True
if metadata.get(f'bind/views/{view}/is_internal'):
if ip_address(value).is_private:
return True
elif not list(filter(
lambda other_value: ip_address(other_value).is_private,
{
other_value
for other_node in repo.nodes
if other_node.metadata.get(f'dns/{name}.{zone}/{type}', [])
for other_value in other_node.metadata.get(f'dns/{name}.{zone}/{type}')
}
)):
return True
else:
if ip_address(value).is_global:
if value == "10.0.0.17" and view == 'external': print(333)
return True
elif not list(filter(
lambda other_value: ip_address(other_value).is_global,
{
other_value
for other_node in repo.nodes
if other_node.metadata.get(f'dns/{name}.{zone}/{type}', [])
for other_value in other_node.metadata.get(f'dns/{name}.{zone}/{type}')
}
)):
return True

View file

@ -40,11 +40,6 @@
}, },
}, },
}, },
'letsencrypt': {
'domains': {
'test11.ckn.li': {},
}
},
'java': { 'java': {
'version': 11, 'version': 11,
}, },

View file

@ -64,12 +64,6 @@
'letsencrypt': { 'letsencrypt': {
'domains': { 'domains': {
'ckn.li': {}, 'ckn.li': {},
'test6.ckn.li': {
'aliases': {'www.test6.ckn.li'},
'location': '/root/temp',
'owner': 'telegraf',
'reload': {'telegraf'},
},
'sublimity.de': {}, 'sublimity.de': {},
'freibrief.net': {}, 'freibrief.net': {},
}, },