Skip to content

Commit a415ca5

Browse files
authored
Merge pull request #30 from netmanagers/master
Minor update, to use `defaults.yaml`, `map.jinja`, etc.
2 parents 7893cdf + d7dc1a6 commit a415ca5

File tree

7 files changed

+171
-24
lines changed

7 files changed

+171
-24
lines changed

.gitignore

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,103 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a packager
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
148
.kitchen
2-
tests/build/
3-
*.swp
4-
*.pyc
49+
.kitchen.local.yml
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# dotenv
85+
.env
86+
87+
# virtualenv
88+
.venv
89+
venv/
90+
ENV/
91+
92+
# Spyder project settings
93+
.spyderproject
94+
.spyproject
95+
96+
# Rope project settings
597
.ropeproject
98+
99+
# mkdocs documentation
100+
/site
101+
102+
# mypy
103+
.mypy_cache/

CHANGELOG.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
iptables formula
22
================
33

4-
0.1 (2014-05-01)
4+
0.3.0 (2018-12-28)
55

6-
- Initial version with support just for iptables
6+
- Update formula to use defaults.yml and map.jinja
77

8-
0.1.1 (2018-12-27)
8+
0.2.0 (2018-12-27)
99

1010
- Update kitchen testing
11+
12+
0.1.0 (2014-05-01)
13+
14+
- Initial version with support just for iptables

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,29 @@ Thanks to the nature of Pillars it is possible to write global and local setting
66

77
Pull requests are welcome for other platforms (or other improvements ofcourse!)
88

9-
.. image:: https://travis-ci.org/saltstack-formulas/iptables-formula.svg?branch=master
9+
![Build Status](https://travis-ci.org/saltstack-formulas/iptables-formula.svg?branch=master "Travis-CI testing status")
1010

1111
Usage
1212
=====
1313

1414
All the configuration for the firewall is done via the pillar (see the pillar.example file).
1515

1616
Enable globally:
17+
1718
`pillars/firewall.sls`
18-
```
19+
20+
```yaml
1921
firewall:
2022
enabled: True
2123
install: True
2224
strict: True
2325
```
2426
2527
Allow SSH:
28+
2629
`pillars/firewall/ssh.sls`
27-
```
30+
31+
```yaml
2832
firewall:
2933
services:
3034
ssh:
@@ -35,7 +39,8 @@ firewall:
3539
```
3640

3741
Apply rules to specific interface:
38-
```
42+
43+
```yaml
3944
firewall:
4045
services:
4146
ssh:
@@ -45,7 +50,9 @@ firewall:
4550
```
4651

4752
Apply rules for multiple protocols:
48-
```
53+
54+
55+
```yaml
4956
firewall:
5057
services:
5158
ssh:
@@ -56,7 +63,7 @@ firewall:
5663

5764
Allow an entire class such as your internal network:
5865

59-
```
66+
```yaml
6067
whitelist:
6168
networks:
6269
ips_allow:
@@ -66,6 +73,7 @@ Allow an entire class such as your internal network:
6673
Salt combines both and effectively enables your firewall and applies the rules.
6774

6875
Notes:
76+
6977
* Setting install to True will install `iptables` and `iptables-persistent` for you
7078
* Strict mode means: Deny **everything** except explicitly allowed (use with care!)
7179
* 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.
@@ -78,7 +86,8 @@ Using iptables.service
7886
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.
7987

8088
`pillars/otherservice.sls`
81-
```
89+
90+
```yaml
8291
otherservice:
8392
firewall:
8493
services:
@@ -89,7 +98,8 @@ otherservice:
8998
```
9099

91100
`states/otherservice.sls`
92-
```
101+
102+
```yaml
93103
#!stateconf yaml . jinja
94104
95105
include:
@@ -106,7 +116,7 @@ Using iptables.nat
106116

107117
You can use nat for interface.
108118

109-
```
119+
```yaml
110120
#Support nat
111121
# iptables -t nat -A POSTROUTING -o eth0 -s 192.168.18.0/24 -d 10.20.0.2 -j MASQUERADE
112122

iptables/defaults.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
firewall:
4+
enabled: false
5+
install: false
6+
strict: false
7+
block_nomatch: false
8+
pkgs:
9+
- iptables

iptables/init.sls

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
14
# Firewall management module
2-
{%- if salt['pillar.get']('firewall:enabled') %}
3-
{% set firewall = salt['pillar.get']('firewall', {}) %}
4-
{% set install = firewall.get('install', False) %}
5-
{% set strict_mode = firewall.get('strict', False) %}
6-
{% set global_block_nomatch = firewall.get('block_nomatch', False) %}
7-
{% set packages = salt['grains.filter_by']({
8-
'Debian': ['iptables', 'iptables-persistent'],
9-
'RedHat': ['iptables'],
10-
'default': 'Debian'}) %}
5+
{% from "iptables/map.jinja" import firewall with context %}
6+
{% set install = firewall.install %}
7+
{% set strict_mode = firewall.strict %}
8+
{% set global_block_nomatch = firewall.block_nomatch %}
9+
{% set packages = firewall.pkgs %}
1110
11+
{%- if firewall.enabled %}
1212
{%- if install %}
1313
# Install required packages for firewalling
1414
iptables_packages:
@@ -165,4 +165,9 @@
165165
{%- endfor %}
166166
{%- endfor %}
167167
168+
{% else %} # Firewall is disabled by default
169+
firewall_disabled:
170+
test.show_notification:
171+
- name: Firewall is disabled by default
172+
- text: firewall:enabled is False
168173
{%- endif %}

iptables/map.jinja

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=jinja
3+
4+
{% import_yaml 'iptables/defaults.yaml' as defaults %}
5+
{% import_yaml 'iptables/osfamilymap.yaml' as osfamilymap %}
6+
7+
{% set firewall = salt['grains.filter_by'](
8+
defaults,
9+
merge = salt['grains.filter_by'](
10+
osfamilymap,
11+
grain='os_family',
12+
merge = salt['pillar.get']('firewall', {})
13+
),
14+
base='firewall')
15+
%}

iptables/osfamilymap.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
Debian:
4+
pkgs:
5+
- iptables
6+
- iptables-persistent

0 commit comments

Comments
 (0)