root / manifests / rule.pp @ 25b3f3f4
Historique | Voir | Annoter | Télécharger (2,32 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 | 94285e5f | Steve Traylen | # @example Redirect port 443 to port 8443 |
17 | # nftables::rule { 'PREROUTING-redirect': |
||
18 | # content => 'tcp dport 443 redirect to :8443', |
||
19 | # table => 'ip-nat', |
||
20 | # } |
||
21 | # nftables::rule{'PREROUTING6-redirect': |
||
22 | # content => 'tcp dport 443 redirect to :8443', |
||
23 | # table => 'ip6-nat', |
||
24 | # } |
||
25 | # |
||
26 | 13f26dfc | Nacho Barrientos | # @param ensure |
27 | # Should the rule be created. |
||
28 | # |
||
29 | # @param rulename |
||
30 | # The symbolic name for the rule and to what chain to add it. The |
||
31 | # format is defined by the Nftables::RuleName type. |
||
32 | # |
||
33 | # @param order |
||
34 | # A number representing the order of the rule. |
||
35 | # |
||
36 | # @param table |
||
37 | # The name of the table to add this rule to. |
||
38 | # |
||
39 | # @param content |
||
40 | # The raw statements that compose the rule represented using the nftables |
||
41 | # language. |
||
42 | # |
||
43 | # @param source |
||
44 | # Same goal as content but sourcing the value from a file. |
||
45 | 11bf7237 | Steve Traylen | define nftables::rule ( |
46 | 31b17627 | Steve Traylen | Enum['present','absent'] $ensure = 'present', |
47 | 8c00b818 | Nacho Barrientos | Nftables::RuleName $rulename = $title, |
48 | 31b17627 | Steve Traylen | Pattern[/^\d\d$/] $order = '50', |
49 | 324b6851 | Tim Meusel | String $table = 'inet-filter', |
50 | 31b17627 | Steve Traylen | Optional[String] $content = undef, |
51 | Optional[Variant[String,Array[String,1]]] $source = undef, |
||
52 | 11bf7237 | Steve Traylen | ) { |
53 | 0ba57c66 | mh | if $ensure == 'present' { |
54 | 8efbdf9a | tr | $data = split($rulename, '-') |
55 | |||
56 | 18ec6f48 | tr | if $data[2] { |
57 | $fragment = "nftables-${table}-chain-${data[0]}-rule-${data[1]}-${data[2]}" |
||
58 | } else { |
||
59 | $fragment = "nftables-${table}-chain-${data[0]}-rule-${data[1]}" |
||
60 | } |
||
61 | |||
62 | 11bf7237 | Steve Traylen | concat::fragment { "${fragment}_header": |
63 | e53053ce | Steve Traylen | content => "# Start of fragment order:${order} rulename:${rulename}", |
64 | 61f03b47 | Steve Traylen | order => "${order}-${fragment}-a", |
65 | e53053ce | Steve Traylen | target => "nftables-${table}-chain-${data[0]}", |
66 | } |
||
67 | |||
68 | 11bf7237 | Steve Traylen | concat::fragment { |
69 | 18ec6f48 | tr | $fragment: |
70 | 61f03b47 | Steve Traylen | order => "${order}-${fragment}-b", |
71 | 8efbdf9a | tr | target => "nftables-${table}-chain-${data[0]}", |
72 | 0ba57c66 | mh | } |
73 | |||
74 | if $content { |
||
75 | 11bf7237 | Steve Traylen | Concat::Fragment[$fragment] { |
76 | 0ba57c66 | mh | content => " ${content}", |
77 | } |
||
78 | } else { |
||
79 | 11bf7237 | Steve Traylen | Concat::Fragment[$fragment] { |
80 | 0ba57c66 | mh | source => $source, |
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |