Projet

Général

Profil

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

root / README.md @ 0b1e3353

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

1
# nftables puppet module
2

    
3
[![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
This module manages an opinionated nftables configuration.
9

    
10
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

    
14
    include nftables
15

    
16
This can be overridden using parameters, for example, this allows all
17
outbound traffic:
18

    
19
    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

    
32
## Configuration
33

    
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
(`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

    
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
for all masterchains. This chain is empty by default.
57

    
58
`INPUT` and `OUTPUT` to the loopback device is allowed by
59
default, though you could restrict it later.
60

    
61
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. Look at `nftables::inet_filter` for inspiration.
66

    
67
## Rules Validation
68

    
69
Initially puppet deploys all configuration to
70
`/etc/nftables/puppet-preflight/` and
71
`/etc/nftables/puppet-preflight.nft`. This is validated with
72
`nft -c -I /etc/nftables/puppet-preflight/ -f /etc/nftables/puppet-preflight.nft`.
73
If and only if successful the configuration will be copied to
74
the real locations before the service is reloaded.
75

    
76
## 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
## Basic types
85

    
86
### 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
### nftables::chain
93

    
94
Prepares a chain file as a `concat` file to which you will
95
be able to add dedicated rules through `nftables::rule`.
96

    
97
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
chain. It's possible to specify the in-interface name and
104
out-interface name for the inject rule.
105

    
106
### nftables::rule
107

    
108
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

    
114
You can define the order by using the `order` param.
115

    
116
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
### nftables::set
122

    
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

    
127
### nftables::simplerule
128

    
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

    
134
## 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
## Editor goodies
155

    
156
If you're using Emacs there are some snippets for
157
[Yasnippet](https://github.com/joaotavora/yasnippet) available
158
[here](https://github.com/nbarrientos/dotfiles/tree/master/.emacs.d/snippets/puppet-mode)
159
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.