root / manifests / init.pp @ 802d80d1
Historique | Voir | Annoter | Télécharger (4,45 ko)
1 | e17693e3 | Steve Traylen | # @summary Configure nftables |
---|---|---|---|
2 | # |
||
3 | # @example |
||
4 | # class{'nftables: |
||
5 | # out_ntp = false, |
||
6 | # out_dns = true, |
||
7 | b3a7a6dd | tr | # } |
8 | e17693e3 | Steve Traylen | # |
9 | b3a7a6dd | tr | # @param out_all |
10 | e17693e3 | Steve Traylen | # 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 | 79e9a23f | Nacho Barrientos | # @param out_icmp |
27 | # Allow outbound ICMPv4/v6 traffic. |
||
28 | # |
||
29 | e17693e3 | Steve Traylen | # @param in_ssh |
30 | # Allow inbound to ssh servers. |
||
31 | # |
||
32 | 79e9a23f | Nacho Barrientos | # @param in_icmp |
33 | # Allow inbound ICMPv4/v6 traffic. |
||
34 | # |
||
35 | 82d10659 | Nacho Barrientos | # @param nat |
36 | # Add default tables and chains to process NAT traffic. |
||
37 | # |
||
38 | 802d80d1 | Nacho Barrientos | # @param sets |
39 | # Allows sourcing set definitions directly from Hiera. |
||
40 | # |
||
41 | ac0af4aa | Nacho Barrientos | # @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 | 70727742 | Nacho Barrientos | # @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 | ea96d5db | Nacho Barrientos | # @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 | ae9872e2 | Nacho Barrientos | # @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 | be0b08e1 | tr | class nftables ( |
63 | 70727742 | Nacho Barrientos | Boolean $in_ssh = true, |
64 | 79e9a23f | Nacho Barrientos | Boolean $in_icmp = true, |
65 | 70727742 | Nacho Barrientos | Boolean $out_ntp = true, |
66 | Boolean $out_dns = true, |
||
67 | Boolean $out_http = true, |
||
68 | Boolean $out_https = true, |
||
69 | 79e9a23f | Nacho Barrientos | Boolean $out_icmp = true, |
70 | 70727742 | Nacho Barrientos | Boolean $out_all = false, |
71 | ea96d5db | Nacho Barrientos | Boolean $in_out_conntrack = true, |
72 | 82d10659 | Nacho Barrientos | Boolean $nat = true, |
73 | 70727742 | Nacho Barrientos | Hash $rules = {}, |
74 | 802d80d1 | Nacho Barrientos | Hash $sets = {}, |
75 | ac0af4aa | Nacho Barrientos | String $log_prefix = '[nftables] %<chain>s %<comment>s', |
76 | 70727742 | Nacho Barrientos | Variant[Boolean[false], Pattern[ |
77 | /icmp(v6|x)? type .+|tcp reset/]] |
||
78 | $reject_with = 'icmpx type port-unreachable', |
||
79 | ae9872e2 | Nacho Barrientos | Variant[Boolean[false], Enum['mask']] |
80 | $firewalld_enable = 'mask', |
||
81 | be0b08e1 | tr | ) { |
82 | |||
83 | 0ba57c66 | mh | 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 | e140adff | tr | owner => 'root', |
93 | group => 'root', |
||
94 | mode => '0640'; |
||
95 | 30462da1 | Steve Traylen | '/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 | 82d10659 | Nacho Barrientos | ensure => file, |
103 | content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat }); |
||
104 | 30462da1 | Steve Traylen | } ~> 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 | 0ba57c66 | mh | '/etc/nftables/puppet.nft': |
114 | 82d10659 | Nacho Barrientos | ensure => file, |
115 | content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat }); |
||
116 | 0ba57c66 | mh | '/etc/nftables/puppet': |
117 | ensure => directory, |
||
118 | 5acb554a | tr | mode => '0750', |
119 | 0ba57c66 | mh | purge => true, |
120 | force => true, |
||
121 | recurse => true; |
||
122 | } ~> service{'nftables': |
||
123 | 30462da1 | Steve Traylen | 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 | 0ba57c66 | mh | } |
135 | |||
136 | f02562f2 | tr | service{'firewalld': |
137 | ensure => stopped, |
||
138 | ae9872e2 | Nacho Barrientos | enable => $firewalld_enable, |
139 | f02562f2 | tr | } |
140 | |||
141 | c8092701 | tr | include nftables::inet_filter |
142 | 82d10659 | Nacho Barrientos | if $nat { |
143 | include nftables::ip_nat |
||
144 | } |
||
145 | b3a7a6dd | tr | |
146 | # inject custom rules e.g. from hiera |
||
147 | 66ed7f61 | mh | $rules.each |$n,$v| { |
148 | nftables::rule{ |
||
149 | $n: |
||
150 | * => $v |
||
151 | } |
||
152 | } |
||
153 | 802d80d1 | Nacho Barrientos | |
154 | # inject custom sets e.g. from hiera |
||
155 | $sets.each |$n,$v| { |
||
156 | nftables::set{ |
||
157 | $n: |
||
158 | * => $v |
||
159 | } |
||
160 | } |
||
161 | 0ba57c66 | mh | } |