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