Skip to content

Commit 28929a5

Browse files
authored
Merge pull request #36 from netmanagers/master
feat: allow to configure the firewall using a rules' dict
2 parents f6ff6bd + be3a96a commit 28929a5

File tree

11 files changed

+376
-145
lines changed

11 files changed

+376
-145
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ env:
3232
- INSTANCE: default-fedora-29-2019-2-py3
3333
# - INSTANCE: default-opensuse-leap-15-2019-2-py3
3434
# - INSTANCE: default-debian-9-2018-3-py2
35-
# - INSTANCE: default-ubuntu-1604-2018-3-py2
35+
- INSTANCE: default-ubuntu-1604-2018-3-py2
3636
# - INSTANCE: default-centos-7-2018-3-py2
3737
# - INSTANCE: default-fedora-29-2018-3-py2
3838
# TODO: Use this when fixed instead of `opensuse-leap-42`
3939
# Ref: https://github.com/netmanagers/salt-image-builder/issues/2
4040
# - INSTANCE: default-opensuse-leap-15-2018-3-py2
4141
# - INSTANCE: default-opensuse-leap-42-2018-3-py2
4242
# - INSTANCE: default-debian-8-2017-7-py2
43-
# - INSTANCE: default-ubuntu-1604-2017-7-py2
43+
# - INSTANCE: tables-ubuntu-1604-2017-7-py2
4444
# TODO: Enable after improving the formula to work with other than `systemd`
4545
# - INSTANCE: default-centos-6-2017-7-py2
4646
# - INSTANCE: default-fedora-28-2017-7-py2
47-
# - INSTANCE: default-opensuse-leap-42-2017-7-py2
47+
- INSTANCE: tables-opensuse-leap-42-2017-7-py2
4848

4949
script:
5050
- bundle exec kitchen verify ${INSTANCE}

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ source "https://rubygems.org"
33
gem 'kitchen-docker', '>= 2.9'
44
gem 'kitchen-salt', '>= 0.6.0'
55
gem 'kitchen-inspec', '>= 1.1'
6-

docs/README.rst

Lines changed: 107 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -54,142 +54,158 @@ All the configuration for the firewall is done via the pillar (see the pillar.ex
5454

5555
Enable globally:
5656

57-
`pillars/firewall.sls`
57+
``pillars/firewall.sls``
5858

59-
```yaml
60-
firewall:
61-
enabled: True
62-
install: True
63-
strict: True
64-
```
59+
.. code-block:: yaml
60+
61+
firewall:
62+
enabled: True
63+
install: True
64+
strict: True
6565
6666
Allow SSH:
6767

68-
`pillars/firewall/ssh.sls`
68+
``pillars/firewall/ssh.sls``
69+
70+
.. code-block:: yaml
6971
70-
```yaml
71-
firewall:
72-
services:
73-
ssh:
74-
block_nomatch: False
75-
ips_allow:
76-
- 192.168.0.0/24
77-
- 10.0.2.2/32
78-
```
72+
firewall:
73+
services:
74+
ssh:
75+
block_nomatch: False
76+
ips_allow:
77+
- 192.168.0.0/24
78+
- 10.0.2.2/32
7979
8080
Apply rules to specific interface:
8181

82-
```yaml
83-
firewall:
84-
services:
85-
ssh:
86-
interfaces:
87-
- eth0
88-
- eth1
89-
```
82+
.. code-block:: yaml
83+
84+
firewall:
85+
services:
86+
ssh:
87+
interfaces:
88+
- eth0
89+
- eth1
9090
9191
Apply rules for multiple protocols:
9292

9393

94-
```yaml
95-
firewall:
96-
services:
97-
ssh:
98-
protos:
99-
- udp
100-
- tcp
101-
```
94+
.. code-block:: yaml
95+
96+
firewall:
97+
services:
98+
ssh:
99+
protos:
100+
- udp
101+
- tcp
102102
103103
Allow an entire class such as your internal network:
104104

105-
```yaml
106-
whitelist:
107-
networks:
108-
ips_allow:
109-
- 10.0.0.0/8
110-
```
105+
.. code-block:: yaml
106+
107+
whitelist:
108+
networks:
109+
ips_allow:
110+
- 10.0.0.0/8
111111
112112
Salt combines both and effectively enables your firewall and applies the rules.
113113

114114
Notes:
115115

116-
* Setting install to True will install `iptables` and `iptables-persistent` for you
116+
* Setting install to True will install ``iptables`` and ``iptables-persistent`` for you
117117
* Strict mode means: Deny **everything** except explicitly allowed (use with care!)
118118
* block_nomatch: With non-strict mode adds in a "REJECT" rule below the accept rules, otherwise other traffic to that service is still allowed. Can be defined per-service or globally, defaults to False.
119-
* Service names can be either port numbers or service names (e.g. ssh, zabbix-agent, http) and are available for viewing/configuring in `/etc/services`
120-
* If no `ips_allow` stanza is provided for any particular ruleset instead of not adding the rule the addition itself is scoped globally (0.0.0.0/0)
119+
* Service names can be either port numbers or service names (e.g. ssh, zabbix-agent, http) and are available for viewing/configuring in ``/etc/services``
120+
* If no ``ips_allow`` stanza is provided for any particular ruleset instead of not adding the rule the addition itself is scoped globally (0.0.0.0/0)
121121

122122
Using iptables.service
123123
^^^^^^^^^^^^^^^^^^^^^^
124124

125-
Salt can't merge pillars, so you can only define `firewall:services` in once place. With the firewall.service state and stateconf, you can define pillars for different services and include and extend the iptables.service state with the `parent` parameter to enable a default firewall configuration with special rules for different services.
125+
Salt can't merge pillars, so you can only define ``firewall:services`` in once place. With the firewall.service state and stateconf, you can define pillars for different services and include and extend the iptables.service state with the ``parent`` parameter to enable a default firewall configuration with special rules for different services.
126126

127-
`pillars/otherservice.sls`
127+
``pillars/otherservice.sls``
128128

129-
```yaml
130-
otherservice:
131-
firewall:
132-
services:
133-
http:
134-
block_nomatch: False
135-
ips_allow:
136-
- 0.0.0.0/0
137-
```
129+
.. code-block:: yaml
138130
139-
`states/otherservice.sls`
131+
otherservice:
132+
firewall:
133+
services:
134+
http:
135+
block_nomatch: False
136+
ips_allow:
137+
- 0.0.0.0/0
140138
141-
```yaml
142-
#!stateconf yaml . jinja
139+
``states/otherservice.sls``
143140

144-
include:
145-
- iptables.service
141+
.. code-block:: yaml
146142
147-
extend:
148-
iptables.service::sls_params:
149-
stateconf.set:
150-
- parent: otherservice
151-
```
143+
#!stateconf yaml . jinja
144+
145+
include:
146+
- iptables.service
147+
148+
extend:
149+
iptables.service::sls_params:
150+
stateconf.set:
151+
- parent: otherservice
152152
153153
Using iptables.nat
154154
^^^^^^^^^^^^^^^^^^
155155

156156
You can use nat for interface. This is supported for IPv4 alone. IPv6 deployments should not use NAT.
157157

158-
```yaml
159-
#Support nat
160-
# iptables -t nat -A POSTROUTING -o eth0 -s 192.168.18.0/24 -d 10.20.0.2 -j MASQUERADE
158+
.. code-block:: yaml
159+
160+
# Support nat
161+
# iptables -t nat -A POSTROUTING -o eth0 -s 192.168.18.0/24 -d 10.20.0.2 -j MASQUERADE
162+
163+
nat:
164+
eth0:
165+
rules:
166+
'192.168.18.0/24':
167+
- 10.20.0.2
168+
169+
Configure the firewall using ``tables``
170+
---------------------------------------
161171

162-
nat:
163-
eth0:
164-
rules:
165-
'192.168.18.0/24':
166-
- 10.20.0.2
167-
```
172+
The state ``iptables.tables`` let's you configure your firewall iterating over pillars
173+
defining rules and policies to add to the different tables (filter, mangle, nat) instead of using services.
174+
This way, you can configure iptables the *classic way*. Note that you still need to include the ``iptables`` state.
175+
176+
To enable the 'tables' mode, set:
177+
178+
.. code-block:: yaml
179+
180+
firewall:
181+
use_tables: True
182+
183+
and then add rules to configure iptables. Check the ``pillar.example``'s *table* section to see some examples.
168184

169185
IPv6 Support
170186
------------
171187

172188
This formula supports IPv6 as long as it is activated with the option:
173189

174-
```
175-
firewall:
176-
ipv6: True
177-
```
178-
179-
Services and whitelists are supported under the sections `services_ipv6` and `whitelist_ipv6`, as below:
180-
181-
```
182-
services_ipv6:
183-
ssh:
184-
block_nomatch: False
185-
ips_allow:
186-
- 2a02:2028:773:d01:10a5:f34f:e7ff:f55b/64
187-
- 2a02:2028:773:d01:1814:28ef:e91b:70b8/64
188-
whitelist_ipv6:
189-
networks:
190-
ips_allow:
191-
- 2a02:2028:773:d01:1814:28ef:e91b:70b8/64
192-
```
190+
.. code-block:: yaml
191+
192+
firewall:
193+
ipv6: True
194+
195+
Services and whitelists are supported under the sections ``services_ipv6`` and ``whitelist_ipv6``, as below:
196+
197+
.. code-block:: yaml
198+
199+
services_ipv6:
200+
ssh:
201+
block_nomatch: False
202+
ips_allow:
203+
- 2a02:2028:773:d01:10a5:f34f:e7ff:f55b/64
204+
- 2a02:2028:773:d01:1814:28ef:e91b:70b8/64
205+
whitelist_ipv6:
206+
networks:
207+
ips_allow:
208+
- 2a02:2028:773:d01:1814:28ef:e91b:70b8/64
193209
194210
These sections are only processed if the ipv6 support is activated.
195211

iptables/defaults.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,47 @@ firewall:
44
enabled: false
55
install: false
66
strict: false
7+
use_tables: false
78
block_nomatch: false
89
pkgs:
910
- iptables
11+
12+
filter:
13+
INPUT:
14+
policy: ACCEPT
15+
rules: {}
16+
FORWARD:
17+
policy: ACCEPT
18+
rules: {}
19+
OUTPUT:
20+
policy: ACCEPT
21+
rules: {}
22+
23+
nat:
24+
PREROUTING:
25+
policy: ACCEPT
26+
rules: {}
27+
INPUT:
28+
policy: ACCEPT
29+
rules: {}
30+
OUTPUT:
31+
policy: ACCEPT
32+
rules: {}
33+
POSTROUTING:
34+
policy: ACCEPT
35+
rules: {}
36+
37+
mangle:
38+
PREROUTING:
39+
policy: ACCEPT
40+
rules: {}
41+
INPUT:
42+
policy: ACCEPT
43+
rules: {}
44+
OUTPUT:
45+
policy: ACCEPT
46+
rules: {}
47+
POSTROUTING:
48+
policy: ACCEPT
49+
rules: {}
50+

0 commit comments

Comments
 (0)