Projet

Général

Profil

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

root / README.md @ f24e622f

Historique | Voir | Annoter | Télécharger (5,31 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
## Basic types
77

    
78
### nftables::config
79

    
80
Manages a raw file in `/etc/nftables/puppet/${name}.nft`
81

    
82
Use this for any custom table files.
83

    
84
### nftables::chain
85

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

    
89
The name must be unique for all chains. The inject
90
parameter can be used to directly add a jump to a
91
masterchain. inject must follow the pattern
92
`ORDER-MASTERCHAIN`, where order references a 2-digit
93
number which defines the rule order (by default use e.g. 20)
94
and masterchain references the chain to hook in the new
95
chain. It's possible to specify the in-interface name and
96
out-interface name for the inject rule.
97

    
98
### nftables::rule
99

    
100
A simple way to add rules to any chain. The name must be:
101
`CHAIN_NAME-rulename`, where CHAIN_NAME refers to your
102
chain and an arbitrary name for your rule.
103
The rule will be a `concat::fragment` to the chain
104
`CHAIN_NAME`.
105

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

    
108
Before defining your own rule, take a look to the list of ready-to-use rules
109
available in the
110
[REFERENCE](https://github.com/voxpupuli/puppet-nftables/blob/master/REFERENCE.md),
111
somebody might have encapsulated a rule definition for you already.
112

    
113
### nftables::set
114

    
115
Adds a named set to a given table. It allows composing the
116
set using individual parameters but also takes raw input
117
via the content and source parameters.
118

    
119
### nftables::simplerule
120

    
121
Allows expressing firewall rules without having to use nftables's language by
122
adding an abstraction layer a-la-Firewall. It's rather limited how far you can
123
go so if you need rather complex rules or you can speak nftables it's
124
recommended to use `nftables::rule` directly.
125

    
126
## Facts
127

    
128
One structured fact `nftables` is available
129

    
130
```
131
{
132
  tables => [
133
    "bridge-filter",
134
    "bridge-nat",
135
    "inet-firewalld",
136
    "ip-firewalld",
137
    "ip6-firewalld"
138
  ],
139
  version => "0.9.3"
140
}
141
```
142

    
143
* `nftables.version` is the version of the nft command from `nft --version`.
144
* `nftables.tables` is the list of tables installed on the machine from `nft list tables`.
145

    
146
## Editor goodies
147

    
148
If you're using Emacs there are some snippets for
149
[Yasnippet](https://github.com/joaotavora/yasnippet) available
150
[here](https://github.com/nbarrientos/dotfiles/tree/master/.emacs.d/snippets/puppet-mode)
151
that could make your life easier when using the module. This is third
152
party configuration that's only included here for reference so changes
153
in the interfaces exposed by this module are not guaranteed to be
154
automatically applied there.