root / manifests / rule.pp @ 7030bde0
Historique | Voir | Annoter | Télécharger (2,03 ko)
1 |
# @summary Provides an interface to create a firewall rule |
---|---|
2 |
# |
3 |
# @example add a rule named 'myhttp' to the 'default_in' chain to allow incoming traffic to TCP port 80 |
4 |
# nftables::rule { |
5 |
# 'default_in-myhttp': |
6 |
# content => 'tcp dport 80 accept', |
7 |
# } |
8 |
# |
9 |
# @example add a rule named 'count' to the 'PREROUTING6' chain in table 'ip6 nat' to count traffic |
10 |
# nftables::rule { |
11 |
# 'PREROUTING6-count': |
12 |
# content => 'counter', |
13 |
# table => 'ip6-nat' |
14 |
# } |
15 |
# |
16 |
# @param ensure |
17 |
# Should the rule be created. |
18 |
# |
19 |
# @param rulename |
20 |
# The symbolic name for the rule and to what chain to add it. The |
21 |
# format is defined by the Nftables::RuleName type. |
22 |
# |
23 |
# @param order |
24 |
# A number representing the order of the rule. |
25 |
# |
26 |
# @param table |
27 |
# The name of the table to add this rule to. |
28 |
# |
29 |
# @param content |
30 |
# The raw statements that compose the rule represented using the nftables |
31 |
# language. |
32 |
# |
33 |
# @param source |
34 |
# Same goal as content but sourcing the value from a file. |
35 |
define nftables::rule ( |
36 |
Enum['present','absent'] $ensure = 'present', |
37 |
Nftables::RuleName $rulename = $title, |
38 |
Pattern[/^\d\d$/] $order = '50', |
39 |
String $table = 'inet-filter', |
40 |
Optional[String] $content = undef, |
41 |
Optional[Variant[String,Array[String,1]]] $source = undef, |
42 |
) { |
43 |
if $ensure == 'present' { |
44 |
$data = split($rulename, '-') |
45 |
|
46 |
if $data[2] { |
47 |
$fragment = "nftables-${table}-chain-${data[0]}-rule-${data[1]}-${data[2]}" |
48 |
} else { |
49 |
$fragment = "nftables-${table}-chain-${data[0]}-rule-${data[1]}" |
50 |
} |
51 |
|
52 |
concat::fragment { "${fragment}_header": |
53 |
content => "# Start of fragment order:${order} rulename:${rulename}", |
54 |
order => "${order}-${fragment}-a", |
55 |
target => "nftables-${table}-chain-${data[0]}", |
56 |
} |
57 |
|
58 |
concat::fragment { |
59 |
$fragment: |
60 |
order => "${order}-${fragment}-b", |
61 |
target => "nftables-${table}-chain-${data[0]}", |
62 |
} |
63 |
|
64 |
if $content { |
65 |
Concat::Fragment[$fragment] { |
66 |
content => " ${content}", |
67 |
} |
68 |
} else { |
69 |
Concat::Fragment[$fragment] { |
70 |
source => $source, |
71 |
} |
72 |
} |
73 |
} |
74 |
} |