root / README.md @ 3b1f4e94
Historique | Voir | Annoter | Télécharger (6,13 ko)
1 | 0ba57c66 | mh | # nftables puppet module |
---|---|---|---|
2 | |||
3 | 82b6fd57 | Steve Traylen | [](https://forge.puppetlabs.com/puppet/nftables) |
4 | [](https://forge.puppetlabs.com/puppet/nftables) |
||
5 | [](http://www.puppetmodule.info/m/puppet-nftables) |
||
6 | [](LICENSE) |
||
7 | |||
8 | 1ffab17b | Nacho Barrientos | This module manages an opinionated nftables configuration. |
9 | 0ba57c66 | mh | |
10 | 6824a5a3 | Antoine Beaupré | By default it sets up a firewall that drops every connection, except |
11 | outbound ICMP, DNS, NTP, HTTP, and HTTPS, and inbound ICMP and SSH |
||
12 | traffic: |
||
13 | 0ba57c66 | mh | |
14 | a8908f9c | Tomas Barton | ```puppet |
15 | include nftables |
||
16 | ``` |
||
17 | 0ba57c66 | mh | |
18 | 6824a5a3 | Antoine Beaupré | This can be overridden using parameters, for example, this allows all |
19 | outbound traffic: |
||
20 | 0ba57c66 | mh | |
21 | a8908f9c | Tomas Barton | ```puppet |
22 | class { 'nftables': |
||
23 | ea9bf72e | Kenyon Ralph | out_all => true, |
24 | a8908f9c | Tomas Barton | } |
25 | ``` |
||
26 | 6824a5a3 | Antoine Beaupré | |
27 | There are also pre-built rules for specific services, for example this |
||
28 | will allow a web server to serve traffic over HTTPS: |
||
29 | |||
30 | a8908f9c | Tomas Barton | ```puppet |
31 | include nftables |
||
32 | include nftables::rules::https |
||
33 | ``` |
||
34 | 6824a5a3 | Antoine Beaupré | |
35 | Note that the module conflicts with the `firewalld` system and will |
||
36 | stop it in Puppet runs. |
||
37 | 0ba57c66 | mh | |
38 | 2fda87af | Nacho Barrientos | ## Configuration |
39 | 0ba57c66 | mh | |
40 | The main configuration file loaded by the nftables service |
||
41 | will be `files/config/puppet.nft`, all other files created |
||
42 | by that module go into `files/config/puppet` and will also |
||
43 | be purged if not managed anymore. |
||
44 | |||
45 | The main configuration file includes dedicated files for |
||
46 | 01f33f80 | Antoine Beaupré | the filter and NAT tables, as well as processes any |
47 | 0ba57c66 | mh | `custom-*.nft` files before hand. |
48 | |||
49 | The filter and NAT tables both have all the master chains |
||
50 | 01f33f80 | Antoine Beaupré | (`INPUT`, `OUTPUT`, `FORWARD` in case of filter and `PREROUTING` |
51 | and `POSTROUTING` in case of NAT) configured, to which you |
||
52 | 7940fb07 | tr | can hook in your own chains that can contain specific |
53 | rules. |
||
54 | 0ba57c66 | mh | |
55 | All filter masterchains drop by default. |
||
56 | 01f33f80 | Antoine Beaupré | By default we have a set of `default_MASTERCHAIN` chains |
57 | 0ba57c66 | mh | configured to which you can easily add your custom rules. |
58 | |||
59 | For specific needs you can add your own chain. |
||
60 | |||
61 | There is a global chain, that defines the default behavior |
||
62 | 620da9a6 | Nacho Barrientos | for all masterchains. This chain is empty by default. |
63 | 0ba57c66 | mh | |
64 | 01f33f80 | Antoine Beaupré | `INPUT` and `OUTPUT` to the loopback device is allowed by |
65 | 7940fb07 | tr | default, though you could restrict it later. |
66 | 0ba57c66 | mh | |
67 | 7b9d6ffc | Nacho Barrientos | On the other hand, if you don't want any of the default tables, chains |
68 | and rules created by the module, you can set `nftables::inet_filter` |
||
69 | and/or `nftables::nat` to `false` and build your whole nftables |
||
70 | configuration from scratch by using the building blocks provided by |
||
71 | 01f33f80 | Antoine Beaupré | this module. Look at `nftables::inet_filter` for inspiration. |
72 | 7b9d6ffc | Nacho Barrientos | |
73 | 2fda87af | Nacho Barrientos | ## Rules Validation |
74 | 4ed97e58 | Nacho Barrientos | |
75 | 30462da1 | Steve Traylen | Initially puppet deploys all configuration to |
76 | `/etc/nftables/puppet-preflight/` and |
||
77 | `/etc/nftables/puppet-preflight.nft`. This is validated with |
||
78 | 647b2d5c | Antoine Beaupré | `nft -c -I /etc/nftables/puppet-preflight/ -f /etc/nftables/puppet-preflight.nft`. |
79 | 30462da1 | Steve Traylen | If and only if successful the configuration will be copied to |
80 | the real locations before the service is reloaded. |
||
81 | |||
82 | 0b1e3353 | canihavethisone | ## Un-managed rules |
83 | |||
84 | By default, rules added manually by the administrator to the in-memory |
||
85 | ruleset will be left untouched. However, |
||
86 | `nftables::purge_unmanaged_rules` can be set to `true` to revert this |
||
87 | behaviour and force a reload of the ruleset during the Puppet run if |
||
88 | non-managed changes are detected. |
||
89 | |||
90 | 2fda87af | Nacho Barrientos | ## Basic types |
91 | |||
92 | 0ba57c66 | mh | ### nftables::config |
93 | |||
94 | Manages a raw file in `/etc/nftables/puppet/${name}.nft` |
||
95 | |||
96 | Use this for any custom table files. |
||
97 | |||
98 | 2fda87af | Nacho Barrientos | ### nftables::chain |
99 | 0ba57c66 | mh | |
100 | 7940fb07 | tr | Prepares a chain file as a `concat` file to which you will |
101 | be able to add dedicated rules through `nftables::rule`. |
||
102 | 0ba57c66 | mh | |
103 | 7940fb07 | tr | The name must be unique for all chains. The inject |
104 | parameter can be used to directly add a jump to a |
||
105 | masterchain. inject must follow the pattern |
||
106 | `ORDER-MASTERCHAIN`, where order references a 2-digit |
||
107 | number which defines the rule order (by default use e.g. 20) |
||
108 | and masterchain references the chain to hook in the new |
||
109 | af544fea | tr | chain. It's possible to specify the in-interface name and |
110 | out-interface name for the inject rule. |
||
111 | 0ba57c66 | mh | |
112 | 2fda87af | Nacho Barrientos | ### nftables::rule |
113 | 0ba57c66 | mh | |
114 | 7940fb07 | tr | A simple way to add rules to any chain. The name must be: |
115 | `CHAIN_NAME-rulename`, where CHAIN_NAME refers to your |
||
116 | chain and an arbitrary name for your rule. |
||
117 | The rule will be a `concat::fragment` to the chain |
||
118 | `CHAIN_NAME`. |
||
119 | 0ba57c66 | mh | |
120 | You can define the order by using the `order` param. |
||
121 | 20b96360 | Nacho Barrientos | |
122 | 13f26dfc | Nacho Barrientos | Before defining your own rule, take a look to the list of ready-to-use rules |
123 | available in the |
||
124 | [REFERENCE](https://github.com/voxpupuli/puppet-nftables/blob/master/REFERENCE.md), |
||
125 | somebody might have encapsulated a rule definition for you already. |
||
126 | |||
127 | 2fda87af | Nacho Barrientos | ### nftables::set |
128 | 20b96360 | Nacho Barrientos | |
129 | Adds a named set to a given table. It allows composing the |
||
130 | set using individual parameters but also takes raw input |
||
131 | via the content and source parameters. |
||
132 | abb04c95 | Nacho Barrientos | |
133 | 2fda87af | Nacho Barrientos | ### nftables::simplerule |
134 | abb04c95 | Nacho Barrientos | |
135 | Allows expressing firewall rules without having to use nftables's language by |
||
136 | adding an abstraction layer a-la-Firewall. It's rather limited how far you can |
||
137 | go so if you need rather complex rules or you can speak nftables it's |
||
138 | recommended to use `nftables::rule` directly. |
||
139 | b1b61501 | Nacho Barrientos | |
140 | 4d95ea85 | Steve Traylen | ## Facts |
141 | |||
142 | One structured fact `nftables` is available |
||
143 | |||
144 | ``` |
||
145 | { |
||
146 | tables => [ |
||
147 | "bridge-filter", |
||
148 | "bridge-nat", |
||
149 | "inet-firewalld", |
||
150 | "ip-firewalld", |
||
151 | "ip6-firewalld" |
||
152 | ], |
||
153 | version => "0.9.3" |
||
154 | } |
||
155 | ``` |
||
156 | |||
157 | * `nftables.version` is the version of the nft command from `nft --version`. |
||
158 | * `nftables.tables` is the list of tables installed on the machine from `nft list tables`. |
||
159 | |||
160 | b1b61501 | Nacho Barrientos | ## Editor goodies |
161 | |||
162 | If you're using Emacs there are some snippets for |
||
163 | [Yasnippet](https://github.com/joaotavora/yasnippet) available |
||
164 | 693a3d98 | Nacho Barrientos | [here](https://github.com/nbarrientos/dotfiles/tree/master/.emacs.d/snippets/puppet-mode) |
165 | b1b61501 | Nacho Barrientos | that could make your life easier when using the module. This is third |
166 | party configuration that's only included here for reference so changes |
||
167 | in the interfaces exposed by this module are not guaranteed to be |
||
168 | automatically applied there. |
||
169 | 47a60cdf | Simon Hoenscheid | |
170 | ## Development |
||
171 | |||
172 | This module relies on CI testing. To ensure the tests and documentation is complete. |
||
173 | |||
174 | The following steps are a blueprint for the necessary work to add a new rule to the module: |
||
175 | |||
176 | 1. add a new class for the new rule (there are enough examples) |
||
177 | 2. document class and parameters |
||
178 | 3. Add a spec test for the new rule to `spec/classes/rules` |
||
179 | 4. add the rule to `spec/acceptance/all_rules_spec.rb` |
||
180 | 6ee35b94 | Simon Hönscheid | 5. update the reference with `bundle exec rake strings:generate:reference` |
181 | 47a60cdf | Simon Hoenscheid | 6. commit, push and open a PR |