Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / README.md @ 6824a5a3

Historique | Voir | Annoter | Télécharger (5,32 ko)

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