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