Browse Source

add ipset support for firewalld

tags/v0.6.2
Niels Abspoel 8 years ago
parent
commit
c5a01c837e
7 changed files with 152 additions and 8 deletions
  1. +1
    -1
      VERSION
  2. +1
    -0
      firewalld/defaults.yaml
  3. +31
    -0
      firewalld/files/ipset.xml
  4. +3
    -0
      firewalld/files/zone.xml
  5. +1
    -0
      firewalld/init.sls
  6. +48
    -0
      firewalld/ipsets.sls
  7. +67
    -7
      pillar.example.sls

+ 1
- 1
VERSION View File

0.1.0
0.2.0

+ 1
- 0
firewalld/defaults.yaml View File

# vim: ft=yaml # vim: ft=yaml
firewalld: firewalld:
package: firewalld package: firewalld
ipsetpackage: ipset
service: firewalld service: firewalld
config: /etc/firewalld.conf config: /etc/firewalld.conf

+ 31
- 0
firewalld/files/ipset.xml View File

<?xml version="1.0" encoding="utf-8"?>
<ipset{%- if 'type' in ipset %} type="{{ ipset.type }}" {%- endif %}>
{%- if 'short' in ipset %}
<short>{{ ipset.short }}</short>
{%- endif %}
{%- if 'description' in ipset %}
<description>{{ ipset.description }}</description>
{%- endif %}
{%- if 'options' in ipset %}
{%- if 'maxelem' in ipset.options %}
{%- for v in ipset.options.maxelem %}
<option name="maxelem" value="{{ v }}"/>
{%- endfor %}
{%- endif %}
{%- if 'timeout' in ipset.options %}
{%- for v in ipset.options.timeout %}
<option name="timeout" value="{{ v }}"/>
{%- endfor %}
{%- endif %}
{%- if 'hashsize' in ipset.options %}
{%- for v in ipset.options.hashsize %}
<option name="hashsize" value="{{ v }}"/>
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if 'entries' in ipset %}
{%- for v in ipset.entries %}
<entry>{{ v }}</entry>
{%- endfor %}
{%- endif %}
</ipset>

+ 3
- 0
firewalld/files/zone.xml View File

{%- else %} {%- else %}
<rule> <rule>
{%- endif %} {%- endif %}
{%- if 'ipset' in rule %}
<source ipset="{{ rule.ipset.name }}"/>
{%- endif %}
{%- if 'source' in rule %} {%- if 'source' in rule %}
<source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %}/> <source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %}/>
{%- endif %} {%- endif %}

+ 1
- 0
firewalld/init.sls View File

{% if salt['pillar.get']('firewalld:enabled') %} {% if salt['pillar.get']('firewalld:enabled') %}
include: include:
- firewalld.config - firewalld.config
- firewalld.ipsets
- firewalld.services - firewalld.services
- firewalld.zones - firewalld.zones



+ 48
- 0
firewalld/ipsets.sls View File

# == State: firewalld.ipsets
#
# This state ensures that /etc/firewalld/ipsets/ exists.
#
{% from "firewalld/map.jinja" import firewalld with context %}

{%- if salt['pillar.get']('firewalld:ipset') %}
package_ipset:
pkg.installed:
- name: {{ firewalld.ipsetpackage }}

directory_firewalld_ipsets:
file.directory: # make sure this is a directory
- name: /etc/firewalld/ipsets
- user: root
- group: root
- mode: 750
- require:
- pkg: package_firewalld # make sure package is installed
- listen_in:
- module: service_firewalld # restart service

# == Define: firewalld.ipsets
#
# This defines a ipset configuration, see firewalld.ipset (5) man page.
#
{% for k, v in salt['pillar.get']('firewalld:ipsets', {}).items() %}
{% set z_name = v.name|default(k) %}

/etc/firewalld/ipsets/{{ z_name }}.xml:
file.managed:
- name: /etc/firewalld/ipsets/{{ z_name }}.xml
- user: root
- group: root
- mode: 644
- source: salt://firewalld/files/ipset.xml
- template: jinja
- require:
- pkg: package_firewalld # make sure package is installed
- file: directory_firewalld_ipsets
- listen_in:
- module: service_firewalld # restart service
- context:
name: {{ z_name }}
ipset: {{ v }}

{% endfor %}
{%- endif %}

+ 67
- 7
pillar.example.sls View File

# CentOS7 FirewallD firewall
# FirewallD pillar examples:
firewalld: firewalld:
enabled: True enabled: True
ipset: True
default_zone: public default_zone: public

services: services:
sshcustom: sshcustom:
short: sshcustom short: sshcustom
description: SSH on port 3232 and 5252. Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful. description: SSH on port 3232 and 5252. Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.
ports: ports:
tcp:
tcp:
- 3232 - 3232
- 5252 - 5252
modules:
modules:
- some_module_to_load - some_module_to_load
destinations: destinations:
ipv4:
ipv4:
- 224.0.0.251 - 224.0.0.251
- 224.0.0.252 - 224.0.0.252
ipv6:
ipv6:
- ff02::fb - ff02::fb
- ff02::fc - ff02::fc

zabbixcustom:
short: Zabbixcustom
description: "zabbix custom rule"
ports:
tcp:
- "10051"
salt-minion:
short: salt-minion
description: "salt-minion"
ports:
tcp:
- "8000"

ipsets:
fail2ban-ssh:
short: fail2ban-ssh
description: fail2ban-ssh ipset
type: 'hash:ip'
options:
maxelem:
- 65536
timeout:
- 300
hashsize:
- 1024
entries:
- 10.0.0.1


zones: zones:
public: public:
short: Public short: Public
description: "For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted." description: "For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted."
services: services:
- http - http
- zabbixcustom
- https - https
- ssh - ssh
- dhcpv6-client

- salt-minion
rich_rules:
- family: ipv4
source:
address: 8.8.8.8/24
accept: true
- family: ipv4
ipset:
name: fail2ban-ssh
reject:
type: icmp-port-unreachable
ports:
{% if grains['id'] == 'salt.example.com' %}
- comment: salt-master
port: 4505
protocol: tcp
- comment: salt-python
port: 4506
protocol: tcp
{% endif %}
- comment: zabbix-agent
port: 10050
protocol: tcp
- comment: bacula-client
port: 9102
protocol: tcp
- comment: vsftpd
port: 21
protocol: tcp

Loading…
Cancel
Save