root / README.md @ 435a5db2
Historique | Voir | Annoter | Télécharger (5,09 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 | By default it sets up a firewall that drops every incoming |
||
11 | and outgoing connection. |
||
12 | |||
13 | 7940fb07 | tr | It only allows outgoing dns, ntp and web and ingoing ssh |
14 | 1330c27e | Nacho Barrientos | traffic, although this can be overridden using parameters. |
15 | 0ba57c66 | mh | |
16 | The config file has a inet filter and a ip nat table setup. |
||
17 | |||
18 | 0f31ffbe | Nacho Barrientos | Additionally, the module comes with a basic infrastructure |
19 | 0ba57c66 | mh | to hook into different places. |
20 | |||
21 | 2fda87af | Nacho Barrientos | ## Configuration |
22 | 0ba57c66 | mh | |
23 | The main configuration file loaded by the nftables service |
||
24 | will be `files/config/puppet.nft`, all other files created |
||
25 | by that module go into `files/config/puppet` and will also |
||
26 | be purged if not managed anymore. |
||
27 | |||
28 | The main configuration file includes dedicated files for |
||
29 | the filter and nat tables, as well as processes any |
||
30 | `custom-*.nft` files before hand. |
||
31 | |||
32 | The filter and NAT tables both have all the master chains |
||
33 | 7940fb07 | tr | (INPUT, OUTPUT, FORWARD in case of filter and PREROUTING |
34 | and POSTROUTING in case of NAT) configured, to which you |
||
35 | can hook in your own chains that can contain specific |
||
36 | rules. |
||
37 | 0ba57c66 | mh | |
38 | All filter masterchains drop by default. |
||
39 | By default we have a set of default_MASTERCHAIN chains |
||
40 | configured to which you can easily add your custom rules. |
||
41 | |||
42 | For specific needs you can add your own chain. |
||
43 | |||
44 | There is a global chain, that defines the default behavior |
||
45 | 620da9a6 | Nacho Barrientos | for all masterchains. This chain is empty by default. |
46 | 0ba57c66 | mh | |
47 | 7940fb07 | tr | INPUT and OUTPUT to the loopback device is allowed by |
48 | default, though you could restrict it later. |
||
49 | 0ba57c66 | mh | |
50 | 7b9d6ffc | Nacho Barrientos | On the other hand, if you don't want any of the default tables, chains |
51 | and rules created by the module, you can set `nftables::inet_filter` |
||
52 | and/or `nftables::nat` to `false` and build your whole nftables |
||
53 | configuration from scratch by using the building blocks provided by |
||
54 | this module. Looking at `nftables::inet_filter` for inspiration might |
||
55 | be a good idea. |
||
56 | |||
57 | 2fda87af | Nacho Barrientos | ## Rules Validation |
58 | 4ed97e58 | Nacho Barrientos | |
59 | 30462da1 | Steve Traylen | Initially puppet deploys all configuration to |
60 | `/etc/nftables/puppet-preflight/` and |
||
61 | `/etc/nftables/puppet-preflight.nft`. This is validated with |
||
62 | `nfc -c -L /etc/nftables/puppet-preflight/ -f /etc/nftables/puppet-preflight.nft`. |
||
63 | If and only if successful the configuration will be copied to |
||
64 | the real locations before the service is reloaded. |
||
65 | |||
66 | 2fda87af | Nacho Barrientos | ## Basic types |
67 | |||
68 | 0ba57c66 | mh | ### nftables::config |
69 | |||
70 | Manages a raw file in `/etc/nftables/puppet/${name}.nft` |
||
71 | |||
72 | Use this for any custom table files. |
||
73 | |||
74 | 2fda87af | Nacho Barrientos | ### nftables::chain |
75 | 0ba57c66 | mh | |
76 | 7940fb07 | tr | Prepares a chain file as a `concat` file to which you will |
77 | be able to add dedicated rules through `nftables::rule`. |
||
78 | 0ba57c66 | mh | |
79 | 7940fb07 | tr | The name must be unique for all chains. The inject |
80 | parameter can be used to directly add a jump to a |
||
81 | masterchain. inject must follow the pattern |
||
82 | `ORDER-MASTERCHAIN`, where order references a 2-digit |
||
83 | number which defines the rule order (by default use e.g. 20) |
||
84 | and masterchain references the chain to hook in the new |
||
85 | af544fea | tr | chain. It's possible to specify the in-interface name and |
86 | out-interface name for the inject rule. |
||
87 | 0ba57c66 | mh | |
88 | 2fda87af | Nacho Barrientos | ### nftables::rule |
89 | 0ba57c66 | mh | |
90 | 7940fb07 | tr | A simple way to add rules to any chain. The name must be: |
91 | `CHAIN_NAME-rulename`, where CHAIN_NAME refers to your |
||
92 | chain and an arbitrary name for your rule. |
||
93 | The rule will be a `concat::fragment` to the chain |
||
94 | `CHAIN_NAME`. |
||
95 | 0ba57c66 | mh | |
96 | You can define the order by using the `order` param. |
||
97 | 20b96360 | Nacho Barrientos | |
98 | 13f26dfc | Nacho Barrientos | Before defining your own rule, take a look to the list of ready-to-use rules |
99 | available in the |
||
100 | [REFERENCE](https://github.com/voxpupuli/puppet-nftables/blob/master/REFERENCE.md), |
||
101 | somebody might have encapsulated a rule definition for you already. |
||
102 | |||
103 | 2fda87af | Nacho Barrientos | ### nftables::set |
104 | 20b96360 | Nacho Barrientos | |
105 | Adds a named set to a given table. It allows composing the |
||
106 | set using individual parameters but also takes raw input |
||
107 | via the content and source parameters. |
||
108 | abb04c95 | Nacho Barrientos | |
109 | 2fda87af | Nacho Barrientos | ### nftables::simplerule |
110 | abb04c95 | Nacho Barrientos | |
111 | Allows expressing firewall rules without having to use nftables's language by |
||
112 | adding an abstraction layer a-la-Firewall. It's rather limited how far you can |
||
113 | go so if you need rather complex rules or you can speak nftables it's |
||
114 | recommended to use `nftables::rule` directly. |
||
115 | b1b61501 | Nacho Barrientos | |
116 | 4d95ea85 | Steve Traylen | ## Facts |
117 | |||
118 | One structured fact `nftables` is available |
||
119 | |||
120 | ``` |
||
121 | { |
||
122 | tables => [ |
||
123 | "bridge-filter", |
||
124 | "bridge-nat", |
||
125 | "inet-firewalld", |
||
126 | "ip-firewalld", |
||
127 | "ip6-firewalld" |
||
128 | ], |
||
129 | version => "0.9.3" |
||
130 | } |
||
131 | ``` |
||
132 | |||
133 | * `nftables.version` is the version of the nft command from `nft --version`. |
||
134 | * `nftables.tables` is the list of tables installed on the machine from `nft list tables`. |
||
135 | |||
136 | b1b61501 | Nacho Barrientos | ## Editor goodies |
137 | |||
138 | If you're using Emacs there are some snippets for |
||
139 | [Yasnippet](https://github.com/joaotavora/yasnippet) available |
||
140 | 693a3d98 | Nacho Barrientos | [here](https://github.com/nbarrientos/dotfiles/tree/master/.emacs.d/snippets/puppet-mode) |
141 | b1b61501 | Nacho Barrientos | that could make your life easier when using the module. This is third |
142 | party configuration that's only included here for reference so changes |
||
143 | in the interfaces exposed by this module are not guaranteed to be |
||
144 | automatically applied there. |