root / manifests / simplerule.pp @ 4ec94616
Historique | Voir | Annoter | Télécharger (1,65 ko)
1 | 4ec94616 | Nacho Barrientos | # @summary Provides a simplified interface to nftables::rule for basic use cases |
---|---|---|---|
2 | # |
||
3 | # @example allow incoming traffic on port 543 TCP to a given IP range and count packets |
||
4 | # nftables::simplerule{'my_service_in': |
||
5 | # action => 'accept', |
||
6 | # comment => 'allow traffic to port 543', |
||
7 | # counter => true, |
||
8 | # proto => 'tcp', |
||
9 | # dport => 543, |
||
10 | # daddr => '2001:1458::/32', |
||
11 | # } |
||
12 | |||
13 | 83382bb5 | Nacho Barrientos | define nftables::simplerule( |
14 | Enum['present','absent'] |
||
15 | $ensure = 'present', |
||
16 | Pattern[/^[-a-zA-Z0-9_]+$/] |
||
17 | fb65734d | Nacho Barrientos | $rulename = $title, |
18 | 83382bb5 | Nacho Barrientos | Pattern[/^\d\d$/] |
19 | $order = '50', |
||
20 | String |
||
21 | $chain = 'default_in', |
||
22 | Optional[String] |
||
23 | $table = 'inet-filter', |
||
24 | Enum['accept', 'drop'] |
||
25 | $action = 'accept', |
||
26 | Optional[String] |
||
27 | $comment = undef, |
||
28 | 3a52fb41 | Nacho Barrientos | Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] |
29 | 83382bb5 | Nacho Barrientos | $dport = undef, |
30 | 316bc3f8 | Nacho Barrientos | Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] |
31 | 83382bb5 | Nacho Barrientos | $proto = undef, |
32 | aaa37172 | Nacho Barrientos | Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] |
33 | $daddr = undef, |
||
34 | Enum['ip', 'ip6'] |
||
35 | $set_type = 'ip6', |
||
36 | d43ced4d | Nacho Barrientos | Boolean |
37 | $counter = false, |
||
38 | 83382bb5 | Nacho Barrientos | ){ |
39 | |||
40 | 3a52fb41 | Nacho Barrientos | if $dport and !$proto { |
41 | fail('Specifying a transport protocol via $proto is mandatory when passing a port') |
||
42 | } |
||
43 | |||
44 | 83382bb5 | Nacho Barrientos | if $ensure == 'present' { |
45 | fb65734d | Nacho Barrientos | nftables::rule{"${chain}-${rulename}": |
46 | 83382bb5 | Nacho Barrientos | content => epp('nftables/simplerule.epp', |
47 | { |
||
48 | aaa37172 | Nacho Barrientos | 'action' => $action, |
49 | 'comment' => $comment, |
||
50 | d43ced4d | Nacho Barrientos | 'counter' => $counter, |
51 | aaa37172 | Nacho Barrientos | 'dport' => $dport, |
52 | 'proto' => $proto, |
||
53 | 'daddr' => $daddr, |
||
54 | 'set_type' => $set_type, |
||
55 | 83382bb5 | Nacho Barrientos | } |
56 | ), |
||
57 | order => $order, |
||
58 | table => $table, |
||
59 | } |
||
60 | } |
||
61 | } |