root / manifests / simplerule.pp @ 77abc10b
Historique | Voir | Annoter | Télécharger (1,87 ko)
1 |
# @summary Provides a simplified interface to nftables::rule for basic use cases |
---|---|
2 |
# |
3 |
# @example allow incoming traffic from port 541 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 |
# sport => 541, |
12 |
# } |
13 |
|
14 |
define nftables::simplerule ( |
15 |
Enum['present','absent'] $ensure = 'present', |
16 |
Pattern[/^[-a-zA-Z0-9_]+$/] $rulename = $title, |
17 |
Pattern[/^\d\d$/] $order = '50', |
18 |
String $chain = 'default_in', |
19 |
String $table = 'inet-filter', |
20 |
Enum['accept', 'drop'] $action = 'accept', |
21 |
Optional[String] $comment = undef, |
22 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] $dport = undef, |
23 |
Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] $proto = undef, |
24 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr = undef, |
25 |
Enum['ip', 'ip6'] $set_type = 'ip6', |
26 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] $sport = undef, |
27 |
Boolean $counter = false, |
28 |
) { |
29 |
if $dport and !$proto { |
30 |
fail('Specifying a transport protocol via $proto is mandatory when passing a $dport') |
31 |
} |
32 |
|
33 |
if $sport and !$proto { |
34 |
fail('Specifying a transport protocol via $proto is mandatory when passing a $sport') |
35 |
} |
36 |
|
37 |
if $ensure == 'present' { |
38 |
nftables::rule { "${chain}-${rulename}": |
39 |
content => epp('nftables/simplerule.epp', |
40 |
{ |
41 |
'action' => $action, |
42 |
'comment' => $comment, |
43 |
'counter' => $counter, |
44 |
'dport' => $dport, |
45 |
'proto' => $proto, |
46 |
'daddr' => $daddr, |
47 |
'set_type' => $set_type, |
48 |
'sport' => $sport, |
49 |
} |
50 |
), |
51 |
order => $order, |
52 |
table => $table, |
53 |
} |
54 |
} |
55 |
} |