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