Projet

Général

Profil

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

root / manifests / simplerule.pp @ fb58f7b3

Historique | Voir | Annoter | Télécharger (1,59 ko)

1 4ec94616 Nacho Barrientos
# @summary Provides a simplified interface to nftables::rule for basic use cases
2
#
3
# @example allow incoming traffic 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
#   }
12
13 467ea4e2 Nacho Barrientos
define nftables::simplerule (
14
  Enum['present','absent'] $ensure = 'present',
15
  Pattern[/^[-a-zA-Z0-9_]+$/] $rulename = $title,
16
  Pattern[/^\d\d$/] $order = '50',
17
  String $chain  = 'default_in',
18
  String $table = 'inet-filter',
19
  Enum['accept', 'drop'] $action = 'accept',
20
  Optional[String] $comment = undef,
21 fb58f7b3 Nacho Barrientos
  Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] $dport = undef,
22
  Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] $proto = undef,
23 467ea4e2 Nacho Barrientos
  Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr = undef,
24
  Enum['ip', 'ip6'] $set_type = 'ip6',
25
  Boolean $counter = false,
26
) {
27 3a52fb41 Nacho Barrientos
  if $dport and !$proto {
28 2489f932 Nacho Barrientos
    fail('Specifying a transport protocol via $proto is mandatory when passing a $dport')
29 3a52fb41 Nacho Barrientos
  }
30
31 83382bb5 Nacho Barrientos
  if $ensure == 'present' {
32 467ea4e2 Nacho Barrientos
    nftables::rule { "${chain}-${rulename}":
33 83382bb5 Nacho Barrientos
      content => epp('nftables/simplerule.epp',
34
        {
35 aaa37172 Nacho Barrientos
          'action'   => $action,
36
          'comment'  => $comment,
37 d43ced4d Nacho Barrientos
          'counter'  => $counter,
38 aaa37172 Nacho Barrientos
          'dport'    => $dport,
39
          'proto'    => $proto,
40
          'daddr'    => $daddr,
41
          'set_type' => $set_type,
42 83382bb5 Nacho Barrientos
        }
43
      ),
44
      order   => $order,
45
      table   => $table,
46
    }
47
  }
48
}