2020-11-13 21:39:09 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/iptables-rules.d': {
|
|
|
|
'purge': True,
|
2021-01-09 13:02:50 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:iptables_enforce',
|
|
|
|
},
|
2020-11-13 21:39:09 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/systemd/system/iptables-enforce.service': {
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/usr/local/sbin/iptables-enforce': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': repo.libs.tools.resolve_identifier(repo, node.name),
|
|
|
|
'mode': '0700',
|
|
|
|
'triggers': {
|
|
|
|
'action:iptables_enforce',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-21 10:44:27 +00:00
|
|
|
enforce_deps = {
|
|
|
|
'directory:/etc/iptables-rules.d',
|
|
|
|
'file:/usr/local/sbin/iptables-enforce',
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for bundle, rules in node.metadata.get('iptables/bundle_rules', {}).items():
|
2020-11-13 21:39:09 +00:00
|
|
|
files[f'/etc/iptables-rules.d/20-{bundle}'] = {
|
|
|
|
# We must never use sorted() here. Bundles might rely on their order.
|
2020-11-14 11:24:12 +00:00
|
|
|
'content': '\n'.join(rules) + '\n',
|
2020-11-13 21:39:09 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:iptables_enforce',
|
|
|
|
},
|
|
|
|
}
|
2021-03-21 10:44:27 +00:00
|
|
|
enforce_deps.add(f'file:/etc/iptables-rules.d/20-{bundle}')
|
2020-11-13 21:39:09 +00:00
|
|
|
|
|
|
|
if 'custom_rules' in node.metadata.get('iptables', {}):
|
2021-02-12 19:37:36 +00:00
|
|
|
files['/etc/iptables-rules.d/40-custom'] = {
|
2020-11-14 11:24:12 +00:00
|
|
|
'content': '\n'.join(node.metadata['iptables']['custom_rules']) + '\n',
|
2020-11-13 21:39:09 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:iptables_enforce',
|
|
|
|
},
|
|
|
|
}
|
2021-03-21 10:44:27 +00:00
|
|
|
enforce_deps.add('file:/etc/iptables-rules.d/40-custom')
|
2020-11-13 21:39:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
'iptables_enforce': {
|
|
|
|
'command': '/usr/local/sbin/iptables-enforce',
|
|
|
|
'triggered': True,
|
2021-03-21 10:44:27 +00:00
|
|
|
'needs': enforce_deps,
|
2020-11-13 21:39:09 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'iptables-enforce': {
|
|
|
|
'running': None,
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/systemd/system/iptables-enforce.service',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|