root / manifests / rule.pp @ cbe342b9
Historique | Voir | Annoter | Télécharger (2,03 ko)
1 | 13f26dfc | Nacho Barrientos | # @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 | 11bf7237 | Steve Traylen | define nftables::rule ( |
36 | 31b17627 | Steve Traylen | Enum['present','absent'] $ensure = 'present', |
37 | 8c00b818 | Nacho Barrientos | Nftables::RuleName $rulename = $title, |
38 | 31b17627 | Steve Traylen | Pattern[/^\d\d$/] $order = '50', |
39 | 324b6851 | Tim Meusel | String $table = 'inet-filter', |
40 | 31b17627 | Steve Traylen | Optional[String] $content = undef, |
41 | Optional[Variant[String,Array[String,1]]] $source = undef, |
||
42 | 11bf7237 | Steve Traylen | ) { |
43 | 0ba57c66 | mh | if $ensure == 'present' { |
44 | 8efbdf9a | tr | $data = split($rulename, '-') |
45 | |||
46 | 18ec6f48 | tr | 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 | 11bf7237 | Steve Traylen | concat::fragment { "${fragment}_header": |
53 | e53053ce | Steve Traylen | content => "# Start of fragment order:${order} rulename:${rulename}", |
54 | 61f03b47 | Steve Traylen | order => "${order}-${fragment}-a", |
55 | e53053ce | Steve Traylen | target => "nftables-${table}-chain-${data[0]}", |
56 | } |
||
57 | |||
58 | 11bf7237 | Steve Traylen | concat::fragment { |
59 | 18ec6f48 | tr | $fragment: |
60 | 61f03b47 | Steve Traylen | order => "${order}-${fragment}-b", |
61 | 8efbdf9a | tr | target => "nftables-${table}-chain-${data[0]}", |
62 | 0ba57c66 | mh | } |
63 | |||
64 | if $content { |
||
65 | 11bf7237 | Steve Traylen | Concat::Fragment[$fragment] { |
66 | 0ba57c66 | mh | content => " ${content}", |
67 | } |
||
68 | } else { |
||
69 | 11bf7237 | Steve Traylen | Concat::Fragment[$fragment] { |
70 | 0ba57c66 | mh | source => $source, |
71 | } |
||
72 | } |
||
73 | } |
||
74 | } |