Defined Type: firewall::service

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

Summary

a shim define to support a common interface between ferm::service and nft::service

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • proto (Wmflib::Protocol) —

    the protocol to use

  • port (Any) (defaults to: undef) —

    a single port or an array of ports to configure

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

    the ensurable parameter

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

    a description to add as a comment

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

    the priority

  • srange (Any) (defaults to: undef) —

    the source range to configure

  • drange (Any) (defaults to: undef) —

    the destination range to configure

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

    An optional array of predefined sets of hosts FROM which incoming traffic is allowed (defined in profile::firewall::nftables_base_sets).

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

    An optional array of predefined sets of hosts TO which incoming traffic is allowed (defined in profile::firewall::nftables_base_sets).

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

    set the rule with no state tracking

  • unrestricted_access (Optional[Boolean]) (defaults to: false) —

    if enabled, it designates that access to this service happens intentionally w/o range restrictions in form of src_sets/dst_sets/srange/drange Initially this parameter doesn't have any effect, but once all firewall::service annotations are backfilled, we can enforce it through a new check

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

    specify a traffic class for DSCP marking (low/normal/high/control)

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


18
19
20
21
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
# File 'modules/firewall/manifests/service.pp', line 18

define firewall::service(
    Wmflib::Protocol              $proto,
                                  $port   = undef,
    Wmflib::Ensure                $ensure = present,
    Optional[String]              $desc = '',
    Integer[0,99]                 $prio = 10,
    Optional[Firewall::Portrange] $port_range = undef,
                                  $srange = undef,
                                  $drange = 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,
) {
    if $srange =~ String {
        fail('The srange needs to be passed as an array of hosts or IPs')
    }

    if $drange =~ String {
        fail('The drange needs to be passed as an array of hosts or IPs')
    }

    if $port =~ Pattern[/\d{1,5}:\d{1,5}/] {
        fail('The port needs to be converted to use a port_range')
    }

    if $port =~ String {
        fail('The port needs to be converted to an array; use a port or port_range')
    }

    $escaped_title = regsubst($title, '\W', '_', 'G')

    # Declare resources for both providers. Both types use virtual resources
    # so they will not have any effect if that firewall provider is not in
    # use on that host.
    # This approach works on hosts with a firewall, instances with P:firewall
    # with type => none applied, and on hosts without P:firewall at all.

    ferm::service { $escaped_title:
        * => wmflib::resource::dump_params(),
    }

    nftables::service { $title:
        *       => wmflib::resource::filter_params('drange', 'srange'),
        src_ips => $srange.then |$range| { wmflib::hosts2ips($range) },
        dst_ips => $drange.then |$range| { wmflib::hosts2ips($range) },
    }
}