root / manifests / init.pp @ b10c6216
Historique | Voir | Annoter | Télécharger (3,42 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 | ac0af4aa | Nacho Barrientos | # @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 | b10c6216 | Nacho Barrientos | # @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 | 70727742 | Nacho Barrientos | # @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 | ea96d5db | Nacho Barrientos | # @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 | ae9872e2 | Nacho Barrientos | # @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 | be0b08e1 | tr | class nftables ( |
62 | 70727742 | Nacho Barrientos | Boolean $in_ssh = true, |
63 | 79e9a23f | Nacho Barrientos | Boolean $in_icmp = true, |
64 | 70727742 | Nacho Barrientos | Boolean $out_ntp = true, |
65 | Boolean $out_dns = true, |
||
66 | Boolean $out_http = true, |
||
67 | Boolean $out_https = true, |
||
68 | 79e9a23f | Nacho Barrientos | Boolean $out_icmp = true, |
69 | 70727742 | Nacho Barrientos | Boolean $out_all = false, |
70 | ea96d5db | Nacho Barrientos | Boolean $in_out_conntrack = true, |
71 | 70727742 | Nacho Barrientos | Hash $rules = {}, |
72 | ac0af4aa | Nacho Barrientos | String $log_prefix = '[nftables] %<chain>s %<comment>s', |
73 | b10c6216 | Nacho Barrientos | Variant[Boolean[false], String] |
74 | $log_limit = '3/minute burst 5 packets', |
||
75 | 70727742 | Nacho Barrientos | Variant[Boolean[false], Pattern[ |
76 | /icmp(v6|x)? type .+|tcp reset/]] |
||
77 | $reject_with = 'icmpx type port-unreachable', |
||
78 | ae9872e2 | Nacho Barrientos | Variant[Boolean[false], Enum['mask']] |
79 | $firewalld_enable = 'mask', |
||
80 | be0b08e1 | tr | ) { |
81 | |||
82 | 0ba57c66 | mh | 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 | e140adff | tr | owner => 'root', |
92 | group => 'root', |
||
93 | mode => '0640'; |
||
94 | 0ba57c66 | mh | '/etc/nftables/puppet.nft': |
95 | 5acb554a | tr | ensure => file, |
96 | 0ba57c66 | mh | source => 'puppet:///modules/nftables/config/puppet.nft'; |
97 | '/etc/nftables/puppet': |
||
98 | ensure => directory, |
||
99 | 5acb554a | tr | mode => '0750', |
100 | 0ba57c66 | mh | purge => true, |
101 | force => true, |
||
102 | recurse => true; |
||
103 | } ~> service{'nftables': |
||
104 | e140adff | tr | ensure => running, |
105 | enable => true, |
||
106 | 0ba57c66 | mh | } |
107 | |||
108 | f02562f2 | tr | service{'firewalld': |
109 | ensure => stopped, |
||
110 | ae9872e2 | Nacho Barrientos | enable => $firewalld_enable, |
111 | f02562f2 | tr | } |
112 | |||
113 | c8092701 | tr | include nftables::inet_filter |
114 | include nftables::ip_nat |
||
115 | b3a7a6dd | tr | |
116 | # inject custom rules e.g. from hiera |
||
117 | 66ed7f61 | mh | $rules.each |$n,$v| { |
118 | nftables::rule{ |
||
119 | $n: |
||
120 | * => $v |
||
121 | } |
||
122 | } |
||
123 | 0ba57c66 | mh | } |