Projet

Général

Profil

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

root / README.md @ fc8e52ed

Historique | Voir | Annoter | Télécharger (5,61 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 01f33f80 Antoine Beaupré
the filter and NAT tables, as well as processes any
41 0ba57c66 mh
`custom-*.nft` files before hand.
42
43
The filter and NAT tables both have all the master chains
44 01f33f80 Antoine Beaupré
(`INPUT`, `OUTPUT`, `FORWARD` in case of filter and `PREROUTING`
45
and `POSTROUTING` in case of NAT) configured, to which you
46 7940fb07 tr
can hook in your own chains that can contain specific
47
rules.
48 0ba57c66 mh
49
All filter masterchains drop by default.
50 01f33f80 Antoine Beaupré
By default we have a set of `default_MASTERCHAIN` chains
51 0ba57c66 mh
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 01f33f80 Antoine Beaupré
`INPUT` and `OUTPUT` to the loopback device is allowed by
59 7940fb07 tr
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 01f33f80 Antoine Beaupré
this module. Look at `nftables::inet_filter` for inspiration.
66 7b9d6ffc Nacho Barrientos
67 2fda87af Nacho Barrientos
## Rules Validation
68 4ed97e58 Nacho Barrientos
69 30462da1 Steve Traylen
Initially puppet deploys all configuration to
70
`/etc/nftables/puppet-preflight/` and
71
`/etc/nftables/puppet-preflight.nft`. This is validated with
72 647b2d5c Antoine Beaupré
`nft -c -I /etc/nftables/puppet-preflight/ -f /etc/nftables/puppet-preflight.nft`.
73 30462da1 Steve Traylen
If and only if successful the configuration will be copied to
74
the real locations before the service is reloaded.
75
76 0b1e3353 canihavethisone
## Un-managed rules
77
78
By default, rules added manually by the administrator to the in-memory
79
ruleset will be left untouched. However,
80
`nftables::purge_unmanaged_rules` can be set to `true` to revert this
81
behaviour and force a reload of the ruleset during the Puppet run if
82
non-managed changes are detected.
83
84 2fda87af Nacho Barrientos
## Basic types
85
86 0ba57c66 mh
### nftables::config
87
88
Manages a raw file in `/etc/nftables/puppet/${name}.nft`
89
90
Use this for any custom table files.
91
92 2fda87af Nacho Barrientos
### nftables::chain
93 0ba57c66 mh
94 7940fb07 tr
Prepares a chain file as a `concat` file to which you will
95
be able to add dedicated rules through `nftables::rule`.
96 0ba57c66 mh
97 7940fb07 tr
The name must be unique for all chains. The inject
98
parameter can be used to directly add a jump to a
99
masterchain. inject must follow the pattern
100
`ORDER-MASTERCHAIN`, where order references a 2-digit
101
number which defines the rule order (by default use e.g. 20)
102
and masterchain references the chain to hook in the new
103 af544fea tr
chain. It's possible to specify the in-interface name and
104
out-interface name for the inject rule.
105 0ba57c66 mh
106 2fda87af Nacho Barrientos
### nftables::rule
107 0ba57c66 mh
108 7940fb07 tr
A simple way to add rules to any chain. The name must be:
109
`CHAIN_NAME-rulename`, where CHAIN_NAME refers to your
110
chain and an arbitrary name for your rule.
111
The rule will be a `concat::fragment` to the chain
112
`CHAIN_NAME`.
113 0ba57c66 mh
114
You can define the order by using the `order` param.
115 20b96360 Nacho Barrientos
116 13f26dfc Nacho Barrientos
Before defining your own rule, take a look to the list of ready-to-use rules
117
available in the
118
[REFERENCE](https://github.com/voxpupuli/puppet-nftables/blob/master/REFERENCE.md),
119
somebody might have encapsulated a rule definition for you already.
120
121 2fda87af Nacho Barrientos
### nftables::set
122 20b96360 Nacho Barrientos
123
Adds a named set to a given table. It allows composing the
124
set using individual parameters but also takes raw input
125
via the content and source parameters.
126 abb04c95 Nacho Barrientos
127 2fda87af Nacho Barrientos
### nftables::simplerule
128 abb04c95 Nacho Barrientos
129
Allows expressing firewall rules without having to use nftables's language by
130
adding an abstraction layer a-la-Firewall. It's rather limited how far you can
131
go so if you need rather complex rules or you can speak nftables it's
132
recommended to use `nftables::rule` directly.
133 b1b61501 Nacho Barrientos
134 4d95ea85 Steve Traylen
## Facts
135
136
One structured fact `nftables` is available
137
138
```
139
{
140
  tables => [
141
    "bridge-filter",
142
    "bridge-nat",
143
    "inet-firewalld",
144
    "ip-firewalld",
145
    "ip6-firewalld"
146
  ],
147
  version => "0.9.3"
148
}
149
```
150
151
* `nftables.version` is the version of the nft command from `nft --version`.
152
* `nftables.tables` is the list of tables installed on the machine from `nft list tables`.
153
154 b1b61501 Nacho Barrientos
## Editor goodies
155
156
If you're using Emacs there are some snippets for
157
[Yasnippet](https://github.com/joaotavora/yasnippet) available
158 693a3d98 Nacho Barrientos
[here](https://github.com/nbarrientos/dotfiles/tree/master/.emacs.d/snippets/puppet-mode)
159 b1b61501 Nacho Barrientos
that could make your life easier when using the module. This is third
160
party configuration that's only included here for reference so changes
161
in the interfaces exposed by this module are not guaranteed to be
162
automatically applied there.