16
17
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
|
# File 'manifests/rules/nomad.pp', line 16
class nftables::rules::nomad (
Stdlib::Port $http = 4646,
Stdlib::Port $rpc = 4647,
Stdlib::Port $serf = 4648,
Array[Stdlib::IP::Address,1] $cluster_elements = ['127.0.0.1','::1'],
) {
# Open http api port to everything.
#
nftables::rule { 'default_in-nomad_http':
content => "tcp dport ${http} accept",
}
['ip','ip6'].each | $_family | {
$_ip_type = $_family ? {
'ip' => Stdlib::IP::Address::V4,
default => Stdlib::IP::Address::V6,
}
$_set_type = $_family ? {
'ip' => 'ipv4_addr',
default => 'ipv6_addr',
}
$_elements = $cluster_elements.filter | $_ip | { $_ip =~ $_ip_type }
if $_elements.length > 0 {
nftables::set { "nomad_${_family}":
elements => $_elements,
type => $_set_type,
}
nftables::rule { "default_in-nomad_rpc_${_family}":
content => "tcp dport ${rpc} ${_family} saddr @nomad_${_family} accept",
}
nftables::rule { "default_in-nomad_serf_udp_${_family}":
content => "udp dport ${serf} ${_family} saddr @nomad_${_family} accept",
}
nftables::rule { "default_in-nomad_serf_tcp_${_family}":
content => "tcp dport ${serf} ${_family} saddr @nomad_${_family} accept",
}
}
}
}
|