root / manifests / init.pp @ 802d80d1
Historique | Voir | Annoter | Télécharger (4,45 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 nat |
36 |
# Add default tables and chains to process NAT traffic. |
37 |
# |
38 |
# @param sets |
39 |
# Allows sourcing set definitions directly from Hiera. |
40 |
# |
41 |
# @param log_prefix |
42 |
# String that will be used as prefix when logging packets. It can contain |
43 |
# two variables using standard sprintf() string-formatting: |
44 |
# * chain: Will be replaced by the name of the chain. |
45 |
# * comment: Allows chains to add extra comments. |
46 |
# |
47 |
# @param reject_with |
48 |
# How to discard packets not matching any rule. If `false`, the |
49 |
# fate of the packet will be defined by the chain policy (normally |
50 |
# drop), otherwise the packet will be rejected with the REJECT_WITH |
51 |
# policy indicated by the value of this parameter. |
52 |
# |
53 |
# @param in_out_conntrack |
54 |
# Adds INPUT and OUTPUT rules to allow traffic that's part of an |
55 |
# established connection and also to drop invalid packets. |
56 |
# |
57 |
# @param firewalld_enable |
58 |
# Configures how the firewalld systemd service unit is enabled. It might be |
59 |
# useful to set this to false if you're externaly removing firewalld from |
60 |
# the system completely. |
61 |
# |
62 |
class nftables ( |
63 |
Boolean $in_ssh = true, |
64 |
Boolean $in_icmp = true, |
65 |
Boolean $out_ntp = true, |
66 |
Boolean $out_dns = true, |
67 |
Boolean $out_http = true, |
68 |
Boolean $out_https = true, |
69 |
Boolean $out_icmp = true, |
70 |
Boolean $out_all = false, |
71 |
Boolean $in_out_conntrack = true, |
72 |
Boolean $nat = true, |
73 |
Hash $rules = {}, |
74 |
Hash $sets = {}, |
75 |
String $log_prefix = '[nftables] %<chain>s %<comment>s', |
76 |
Variant[Boolean[false], Pattern[ |
77 |
/icmp(v6|x)? type .+|tcp reset/]] |
78 |
$reject_with = 'icmpx type port-unreachable', |
79 |
Variant[Boolean[false], Enum['mask']] |
80 |
$firewalld_enable = 'mask', |
81 |
) { |
82 |
|
83 |
package{'nftables': |
84 |
ensure => installed, |
85 |
} -> file_line{ |
86 |
'enable_nftables': |
87 |
line => 'include "/etc/nftables/puppet.nft"', |
88 |
path => '/etc/sysconfig/nftables.conf', |
89 |
notify => Service['nftables'], |
90 |
} -> file{ |
91 |
default: |
92 |
owner => 'root', |
93 |
group => 'root', |
94 |
mode => '0640'; |
95 |
'/etc/nftables/puppet-preflight': |
96 |
ensure => directory, |
97 |
mode => '0750', |
98 |
purge => true, |
99 |
force => true, |
100 |
recurse => true; |
101 |
'/etc/nftables/puppet-preflight.nft': |
102 |
ensure => file, |
103 |
content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat }); |
104 |
} ~> exec{ |
105 |
'nft validate': |
106 |
refreshonly => true, |
107 |
command => '/usr/sbin/nft -I /etc/nftables/puppet-preflight -c -f /etc/nftables/puppet-preflight.nft || ( /usr/bin/echo "#CONFIG BROKEN" >> /etc/nftables/puppet-preflight.nft && /bin/false)'; |
108 |
} -> file{ |
109 |
default: |
110 |
owner => 'root', |
111 |
group => 'root', |
112 |
mode => '0640'; |
113 |
'/etc/nftables/puppet.nft': |
114 |
ensure => file, |
115 |
content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat }); |
116 |
'/etc/nftables/puppet': |
117 |
ensure => directory, |
118 |
mode => '0750', |
119 |
purge => true, |
120 |
force => true, |
121 |
recurse => true; |
122 |
} ~> service{'nftables': |
123 |
ensure => running, |
124 |
enable => true, |
125 |
hasrestart => true, |
126 |
restart => '/usr/bin/systemctl reload nftables', |
127 |
} |
128 |
|
129 |
systemd::dropin_file{'puppet_nft.conf': |
130 |
ensure => present, |
131 |
unit => 'nftables.service', |
132 |
source => 'puppet:///modules/nftables/systemd/puppet_nft.conf', |
133 |
notify => Service['nftables'], |
134 |
} |
135 |
|
136 |
service{'firewalld': |
137 |
ensure => stopped, |
138 |
enable => $firewalld_enable, |
139 |
} |
140 |
|
141 |
include nftables::inet_filter |
142 |
if $nat { |
143 |
include nftables::ip_nat |
144 |
} |
145 |
|
146 |
# inject custom rules e.g. from hiera |
147 |
$rules.each |$n,$v| { |
148 |
nftables::rule{ |
149 |
$n: |
150 |
* => $v |
151 |
} |
152 |
} |
153 |
|
154 |
# inject custom sets e.g. from hiera |
155 |
$sets.each |$n,$v| { |
156 |
nftables::set{ |
157 |
$n: |
158 |
* => $v |
159 |
} |
160 |
} |
161 |
} |