root / manifests / simplerule.pp @ 2489f932
Historique | Voir | Annoter | Télécharger (1,65 ko)
1 |
# @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 |
define nftables::simplerule( |
14 |
Enum['present','absent'] |
15 |
$ensure = 'present', |
16 |
Pattern[/^[-a-zA-Z0-9_]+$/] |
17 |
$rulename = $title, |
18 |
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 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] |
29 |
$dport = undef, |
30 |
Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] |
31 |
$proto = undef, |
32 |
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 |
Boolean |
37 |
$counter = false, |
38 |
){ |
39 |
|
40 |
if $dport and !$proto { |
41 |
fail('Specifying a transport protocol via $proto is mandatory when passing a $dport') |
42 |
} |
43 |
|
44 |
if $ensure == 'present' { |
45 |
nftables::rule{"${chain}-${rulename}": |
46 |
content => epp('nftables/simplerule.epp', |
47 |
{ |
48 |
'action' => $action, |
49 |
'comment' => $comment, |
50 |
'counter' => $counter, |
51 |
'dport' => $dport, |
52 |
'proto' => $proto, |
53 |
'daddr' => $daddr, |
54 |
'set_type' => $set_type, |
55 |
} |
56 |
), |
57 |
order => $order, |
58 |
table => $table, |
59 |
} |
60 |
} |
61 |
} |