root / manifests / init.pp @ b10c6216
Historique | Voir | Annoter | Télécharger (3,42 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 out_icmp |
27 |
# Allow outbound ICMPv4/v6 traffic. |
28 |
# |
29 |
# @param in_ssh |
30 |
# Allow inbound to ssh servers. |
31 |
# |
32 |
# @param in_icmp |
33 |
# Allow inbound ICMPv4/v6 traffic. |
34 |
# |
35 |
# @param log_prefix |
36 |
# String that will be used as prefix when logging packets. It can contain |
37 |
# two variables using standard sprintf() string-formatting: |
38 |
# * chain: Will be replaced by the name of the chain. |
39 |
# * comment: Allows chains to add extra comments. |
40 |
# |
41 |
# @param log_limit |
42 |
# String with the content of a limit statement to be applied |
43 |
# to the rules that log discarded traffic. Set to false to |
44 |
# disable rate limiting. |
45 |
# |
46 |
# @param reject_with |
47 |
# How to discard packets not matching any rule. If `false`, the |
48 |
# fate of the packet will be defined by the chain policy (normally |
49 |
# drop), otherwise the packet will be rejected with the REJECT_WITH |
50 |
# policy indicated by the value of this parameter. |
51 |
# |
52 |
# @param in_out_conntrack |
53 |
# Adds INPUT and OUTPUT rules to allow traffic that's part of an |
54 |
# established connection and also to drop invalid packets. |
55 |
# |
56 |
# @param firewalld_enable |
57 |
# Configures how the firewalld systemd service unit is enabled. It might be |
58 |
# useful to set this to false if you're externaly removing firewalld from |
59 |
# the system completely. |
60 |
# |
61 |
class nftables ( |
62 |
Boolean $in_ssh = true, |
63 |
Boolean $in_icmp = true, |
64 |
Boolean $out_ntp = true, |
65 |
Boolean $out_dns = true, |
66 |
Boolean $out_http = true, |
67 |
Boolean $out_https = true, |
68 |
Boolean $out_icmp = true, |
69 |
Boolean $out_all = false, |
70 |
Boolean $in_out_conntrack = true, |
71 |
Hash $rules = {}, |
72 |
String $log_prefix = '[nftables] %<chain>s %<comment>s', |
73 |
Variant[Boolean[false], String] |
74 |
$log_limit = '3/minute burst 5 packets', |
75 |
Variant[Boolean[false], Pattern[ |
76 |
/icmp(v6|x)? type .+|tcp reset/]] |
77 |
$reject_with = 'icmpx type port-unreachable', |
78 |
Variant[Boolean[false], Enum['mask']] |
79 |
$firewalld_enable = 'mask', |
80 |
) { |
81 |
|
82 |
package{'nftables': |
83 |
ensure => installed, |
84 |
} -> file_line{ |
85 |
'enable_nftables': |
86 |
line => 'include "/etc/nftables/puppet.nft"', |
87 |
path => '/etc/sysconfig/nftables.conf', |
88 |
notify => Service['nftables'], |
89 |
} -> file{ |
90 |
default: |
91 |
owner => 'root', |
92 |
group => 'root', |
93 |
mode => '0640'; |
94 |
'/etc/nftables/puppet.nft': |
95 |
ensure => file, |
96 |
source => 'puppet:///modules/nftables/config/puppet.nft'; |
97 |
'/etc/nftables/puppet': |
98 |
ensure => directory, |
99 |
mode => '0750', |
100 |
purge => true, |
101 |
force => true, |
102 |
recurse => true; |
103 |
} ~> service{'nftables': |
104 |
ensure => running, |
105 |
enable => true, |
106 |
} |
107 |
|
108 |
service{'firewalld': |
109 |
ensure => stopped, |
110 |
enable => $firewalld_enable, |
111 |
} |
112 |
|
113 |
include nftables::inet_filter |
114 |
include nftables::ip_nat |
115 |
|
116 |
# inject custom rules e.g. from hiera |
117 |
$rules.each |$n,$v| { |
118 |
nftables::rule{ |
119 |
$n: |
120 |
* => $v |
121 |
} |
122 |
} |
123 |
} |