Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / manifests / simplerule.pp @ b46c9ce9

Historique | Voir | Annoter | Télécharger (2,69 ko)

1
# @summary Provides a simplified interface to nftables::rule
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
# @param rulename
15
#   The symbolic name for the rule to add. Defaults to the resource's title.
16
#
17
# @param order
18
#   A number representing the order of the rule.
19
#
20
# @param chain
21
#   The name of the chain to add this rule to.
22
#
23
# @param table
24
#   The name of the table to add this rule to.
25
#
26
# @param action
27
#   The verdict for the matched traffic.
28
#
29
# @param comment
30
#   A typically human-readable comment for the rule.
31
#
32
# @param dport
33
#   The destination port, ports or port range.
34
#
35
# @param proto
36
#   The transport-layer protocol to match.
37
#
38
# @param daddr
39
#   The destination address, CIDR or set to match.
40
#
41
# @param set_type
42
#   When using sets as saddr or daddr, the type of the set.
43
#   Use `ip` for sets of type `ipv4_addr`.
44
#
45
# @param sport
46
#   The source port, ports or port range.
47
#
48
# @param saddr
49
#   The source address, CIDR or set to match.
50
#
51
# @param counter
52
#   Enable traffic counters for the matched traffic.
53
define nftables::simplerule (
54
  Enum['present','absent'] $ensure = 'present',
55
  Pattern[/^[-a-zA-Z0-9_]+$/] $rulename = $title,
56
  Pattern[/^\d\d$/] $order = '50',
57
  String $chain  = 'default_in',
58
  String $table = 'inet-filter',
59
  Enum['accept', 'continue', 'drop', 'queue', 'return'] $action = 'accept',
60
  Optional[String] $comment = undef,
61
  Optional[Nftables::Port] $dport = undef,
62
  Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] $proto = undef,
63
  Optional[Nftables::Addr] $daddr = undef,
64
  Enum['ip', 'ip6'] $set_type = 'ip6',
65
  Optional[Nftables::Port] $sport = undef,
66
  Optional[Nftables::Addr] $saddr = undef,
67
  Boolean $counter = false,
68
) {
69
  if $dport and !$proto {
70
    fail('Specifying a transport protocol via $proto is mandatory when passing a $dport')
71
  }
72

    
73
  if $sport and !$proto {
74
    fail('Specifying a transport protocol via $proto is mandatory when passing a $sport')
75
  }
76

    
77
  if $ensure == 'present' {
78
    nftables::rule { "${chain}-${rulename}":
79
      content => epp('nftables/simplerule.epp',
80
        {
81
          'action'   => $action,
82
          'comment'  => $comment,
83
          'counter'  => $counter,
84
          'daddr'    => $daddr,
85
          'dport'    => $dport,
86
          'proto'    => $proto,
87
          'saddr'    => $saddr,
88
          'set_type' => $set_type,
89
          'sport'    => $sport,
90
        }
91
      ),
92
      order   => $order,
93
      table   => $table,
94
    }
95
  }
96
}