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
# 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. Looking at `nftables::inet_filter` for inspiration might
66
be a good idea.
67

    
68
## Rules Validation
69

    
70
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
## Basic types
78

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

    
87
Prepares a chain file as a `concat` file to which you will
88
be able to add dedicated rules through `nftables::rule`.
89

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

    
99
### nftables::rule
100

    
101
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

    
107
You can define the order by using the `order` param.
108

    
109
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
### nftables::set
115

    
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

    
120
### nftables::simplerule
121

    
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

    
127
## 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
## Editor goodies
148

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