root / README.md @ 4d95ea85
Historique | Voir | Annoter | Télécharger (4,73 ko)
1 |
# nftables puppet module |
---|---|
2 |
|
3 |
[](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 |
This module manages an opinionated nftables configuration. |
9 |
|
10 |
By default it sets up a firewall that drops every incoming |
11 |
and outgoing connection. |
12 |
|
13 |
It only allows outgoing dns, ntp and web and ingoing ssh |
14 |
traffic, although this can be overridden using parameters. |
15 |
|
16 |
The config file has a inet filter and a ip nat table setup. |
17 |
|
18 |
Additionally, the module comes with a basic infrastructure |
19 |
to hook into different places. |
20 |
|
21 |
## Configuration |
22 |
|
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 |
(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 |
|
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 |
for all masterchains. This chain is empty by default. |
46 |
|
47 |
INPUT and OUTPUT to the loopback device is allowed by |
48 |
default, though you could restrict it later. |
49 |
|
50 |
## Rules Validation |
51 |
|
52 |
Initially puppet deploys all configuration to |
53 |
`/etc/nftables/puppet-preflight/` and |
54 |
`/etc/nftables/puppet-preflight.nft`. This is validated with |
55 |
`nfc -c -L /etc/nftables/puppet-preflight/ -f /etc/nftables/puppet-preflight.nft`. |
56 |
If and only if successful the configuration will be copied to |
57 |
the real locations before the service is reloaded. |
58 |
|
59 |
## Basic types |
60 |
|
61 |
### nftables::config |
62 |
|
63 |
Manages a raw file in `/etc/nftables/puppet/${name}.nft` |
64 |
|
65 |
Use this for any custom table files. |
66 |
|
67 |
### nftables::chain |
68 |
|
69 |
Prepares a chain file as a `concat` file to which you will |
70 |
be able to add dedicated rules through `nftables::rule`. |
71 |
|
72 |
The name must be unique for all chains. The inject |
73 |
parameter can be used to directly add a jump to a |
74 |
masterchain. inject must follow the pattern |
75 |
`ORDER-MASTERCHAIN`, where order references a 2-digit |
76 |
number which defines the rule order (by default use e.g. 20) |
77 |
and masterchain references the chain to hook in the new |
78 |
chain. It's possible to specify the in-interface name and |
79 |
out-interface name for the inject rule. |
80 |
|
81 |
### nftables::rule |
82 |
|
83 |
A simple way to add rules to any chain. The name must be: |
84 |
`CHAIN_NAME-rulename`, where CHAIN_NAME refers to your |
85 |
chain and an arbitrary name for your rule. |
86 |
The rule will be a `concat::fragment` to the chain |
87 |
`CHAIN_NAME`. |
88 |
|
89 |
You can define the order by using the `order` param. |
90 |
|
91 |
Before defining your own rule, take a look to the list of ready-to-use rules |
92 |
available in the |
93 |
[REFERENCE](https://github.com/voxpupuli/puppet-nftables/blob/master/REFERENCE.md), |
94 |
somebody might have encapsulated a rule definition for you already. |
95 |
|
96 |
### nftables::set |
97 |
|
98 |
Adds a named set to a given table. It allows composing the |
99 |
set using individual parameters but also takes raw input |
100 |
via the content and source parameters. |
101 |
|
102 |
### nftables::simplerule |
103 |
|
104 |
Allows expressing firewall rules without having to use nftables's language by |
105 |
adding an abstraction layer a-la-Firewall. It's rather limited how far you can |
106 |
go so if you need rather complex rules or you can speak nftables it's |
107 |
recommended to use `nftables::rule` directly. |
108 |
|
109 |
## Facts |
110 |
|
111 |
One structured fact `nftables` is available |
112 |
|
113 |
``` |
114 |
{ |
115 |
tables => [ |
116 |
"bridge-filter", |
117 |
"bridge-nat", |
118 |
"inet-firewalld", |
119 |
"ip-firewalld", |
120 |
"ip6-firewalld" |
121 |
], |
122 |
version => "0.9.3" |
123 |
} |
124 |
``` |
125 |
|
126 |
* `nftables.version` is the version of the nft command from `nft --version`. |
127 |
* `nftables.tables` is the list of tables installed on the machine from `nft list tables`. |
128 |
|
129 |
## Editor goodies |
130 |
|
131 |
If you're using Emacs there are some snippets for |
132 |
[Yasnippet](https://github.com/joaotavora/yasnippet) available |
133 |
[here](https://github.com/nbarrientos/dotfiles/tree/cern/emacs/snippets/puppet-mode) |
134 |
that could make your life easier when using the module. This is third |
135 |
party configuration that's only included here for reference so changes |
136 |
in the interfaces exposed by this module are not guaranteed to be |
137 |
automatically applied there. |