root / manifests / init.pp @ ae9872e2
Historique | Voir | Annoter | Télécharger (2,97 ko)
1 |
# @summary Configure nftables |
---|---|
2 |
# |
3 |
# @example |
4 |
# class{'nftables: |
5 |
# out_ntp = false, |
6 |
# out_dns = true, |
7 |
# } |
8 |
# |
9 |
# @param out_all |
10 |
# Allow all outbound connections. If `true` then all other |
11 |
# out parameters `out_ntp`, `out_dns`, ... will be assuemed |
12 |
# false. |
13 |
# |
14 |
# @param out_ntp |
15 |
# Allow outbound to ntp servers. |
16 |
# |
17 |
# @param out_http |
18 |
# Allow outbound to http servers. |
19 |
# |
20 |
# @param out_https |
21 |
# Allow outbound to https servers. |
22 |
# |
23 |
# @param out_https |
24 |
# Allow outbound to https servers. |
25 |
# |
26 |
# @param in_ssh |
27 |
# Allow inbound to ssh servers. |
28 |
# |
29 |
# @param log_prefix |
30 |
# String that will be used as prefix when logging packets. It can contain |
31 |
# two variables using standard sprintf() string-formatting: |
32 |
# * chain: Will be replaced by the name of the chain. |
33 |
# * comment: Allows chains to add extra comments. |
34 |
# |
35 |
# @param reject_with |
36 |
# How to discard packets not matching any rule. If `false`, the |
37 |
# fate of the packet will be defined by the chain policy (normally |
38 |
# drop), otherwise the packet will be rejected with the REJECT_WITH |
39 |
# policy indicated by the value of this parameter. |
40 |
# |
41 |
# @param in_out_conntrack |
42 |
# Adds INPUT and OUTPUT rules to allow traffic that's part of an |
43 |
# established connection and also to drop invalid packets. |
44 |
# |
45 |
# @param firewalld_enable |
46 |
# Configures how the firewalld systemd service unit is enabled. It might be |
47 |
# useful to set this to false if you're externaly removing firewalld from |
48 |
# the system completely. |
49 |
# |
50 |
class nftables ( |
51 |
Boolean $in_ssh = true, |
52 |
Boolean $out_ntp = true, |
53 |
Boolean $out_dns = true, |
54 |
Boolean $out_http = true, |
55 |
Boolean $out_https = true, |
56 |
Boolean $out_all = false, |
57 |
Boolean $in_out_conntrack = true, |
58 |
Hash $rules = {}, |
59 |
String $log_prefix = '[nftables] %<chain>s %<comment>s', |
60 |
Variant[Boolean[false], Pattern[ |
61 |
/icmp(v6|x)? type .+|tcp reset/]] |
62 |
$reject_with = 'icmpx type port-unreachable', |
63 |
Variant[Boolean[false], Enum['mask']] |
64 |
$firewalld_enable = 'mask', |
65 |
) { |
66 |
|
67 |
package{'nftables': |
68 |
ensure => installed, |
69 |
} -> file_line{ |
70 |
'enable_nftables': |
71 |
line => 'include "/etc/nftables/puppet.nft"', |
72 |
path => '/etc/sysconfig/nftables.conf', |
73 |
notify => Service['nftables'], |
74 |
} -> file{ |
75 |
default: |
76 |
owner => 'root', |
77 |
group => 'root', |
78 |
mode => '0640'; |
79 |
'/etc/nftables/puppet.nft': |
80 |
ensure => file, |
81 |
source => 'puppet:///modules/nftables/config/puppet.nft'; |
82 |
'/etc/nftables/puppet': |
83 |
ensure => directory, |
84 |
mode => '0750', |
85 |
purge => true, |
86 |
force => true, |
87 |
recurse => true; |
88 |
} ~> service{'nftables': |
89 |
ensure => running, |
90 |
enable => true, |
91 |
} |
92 |
|
93 |
service{'firewalld': |
94 |
ensure => stopped, |
95 |
enable => $firewalld_enable, |
96 |
} |
97 |
|
98 |
include nftables::inet_filter |
99 |
include nftables::ip_nat |
100 |
|
101 |
# inject custom rules e.g. from hiera |
102 |
$rules.each |$n,$v| { |
103 |
nftables::rule{ |
104 |
$n: |
105 |
* => $v |
106 |
} |
107 |
} |
108 |
} |