Defined Type: nftables::service

Defined in:
modules/nftables/manifests/service.pp

Summary

Create nft rules for a service

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: present) —

    Ensure of the resource

  • proto (Wmflib::Protocol) —

    Either 'udp' or 'tcp'

  • prio (Integer[0,99]) (defaults to: 10) —

    The rules are included with a path prefix, by default all rules use 10, but if ordering matters for a given service it can also be lower or higher

  • desc (Optional[String]) (defaults to: undef) —

    An optional description which gets added as a comment to the .nft file

  • port (Optional[Nftables::Port]) (defaults to: undef) —

    Either a port or an array of allowed ports. If neither port or port_range are set, all ports are allowed

  • port_range (Optional[Firewall::Portrange]) (defaults to: undef) —

    A tuple of ports represending an allowed range. If neither port or port_range are set, all ports are allowed

  • $src_ips —

    If neither $src_ips nor $src_sets are provided, all source addresses will be allowed. Otherwise only traffic coming from the addresses in the parameter and/or $src_sets

  • $dst_ips: —

    Likewise, but with destination addresses

  • src_sets (Optional[Array[String[1]]]) (defaults to: undef) —

    see srange docs

  • dst_sets (Optional[Array[String[1]]]) (defaults to: undef) —

    see srange docs

  • notrack (Boolean) (defaults to: false) —

    Optional boolean to disable connection tracking for matching traffic

  • qos (Optional[Firewall::Qos]) (defaults to: undef) —

    Optional string with value of 'high', 'low', 'normal' or 'mgmt' to indicate the quality-of-service the traffic should get across the network, controlled by setting the DSCP bits in the packet header.

  • src_ips (Optional[Array[Stdlib::IP::Address]]) (defaults to: undef)
  • dst_ips (Optional[Array[Stdlib::IP::Address]]) (defaults to: undef)
  • unrestricted_access (Optional[Boolean]) (defaults to: false)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'modules/nftables/manifests/service.pp', line 22

define nftables::service (
    Wmflib::Protocol                     $proto,
    Wmflib::Ensure                       $ensure              = present,
    Integer[0,99]                        $prio                = 10,
    Optional[String]                     $desc                = undef,
    Optional[Nftables::Port]             $port                = undef,
    Optional[Firewall::Portrange]        $port_range          = undef,
    Optional[Array[Stdlib::IP::Address]] $src_ips             = undef,
    Optional[Array[Stdlib::IP::Address]] $dst_ips             = undef,
    Optional[Array[String[1]]]           $src_sets            = undef,
    Optional[Array[String[1]]]           $dst_sets            = undef,
    Optional[Boolean]                    $unrestricted_access = false,
    Boolean                              $notrack             = false,
    Optional[Firewall::Qos]              $qos                 = undef,
) {
    $rulesets = nftables::rulesets(
        'input',
        $proto,
        $port,
        $port_range,
        $src_ips,
        $dst_ips,
        $src_sets,
        $dst_sets,
        $qos
    )

    $file_require = nftables::require_sets($src_sets, $dst_sets)

    if $rulesets['base'] != [] {
        $content = @("CONTENT")
        # Managed by puppet
        # ${desc}
        ${rulesets['base'].join("\n")}
        | CONTENT

        $filename = sprintf('/etc/nftables/input/%02d_%s.nft', $prio, $title)
        @file { $filename:
            ensure  => $ensure,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => $content,
            require => $file_require,
            tag     => 'nft',
        }
    }

    if $notrack and $rulesets['notrack'] != [] {
        $notrack_content = @("CONTENT")
        # Managed by puppet
        # ${desc}
        ${rulesets['notrack'].join("\n")}
        | CONTENT

        $notrack_filename = sprintf('/etc/nftables/notrack/%02d_%s.nft', $prio, $title)
        @file { $notrack_filename:
            ensure  => $ensure,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => $notrack_content,
            require => $file_require,
            tag     => 'nft',
        }
    }

    if $qos != undef and $rulesets['dscp'] != [] {
        $postrouting_content = @("POST_CONTENT")
        # Managed by puppet
        # ${desc}
        ${rulesets['dscp'].join("\n")}
        | POST_CONTENT

        $postrouting_filename = sprintf('/etc/nftables/postrouting/%02d_%s_service_%s.nft', $prio, $title, $qos)
        @file { $postrouting_filename:
            ensure  => $ensure,
            mode    => '0444',
            content => $postrouting_content,
            require => $file_require,
            tag     => 'nft',
        }
    }
}