root / spec / acceptance / all_rules_spec.rb @ 53aa1fa8
Historique | Voir | Annoter | Télécharger (5,82 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper_acceptance'
|
4 |
|
5 |
describe 'nftables class' do |
6 |
context 'configure all nftables rules' do |
7 |
it 'works idempotently with no errors' do |
8 |
pp = <<-EOS |
9 |
# Default ArchLinux rules contain "destroy" that requires kernel >= 6.3
|
10 |
# https://gitlab.archlinux.org/archlinux/packaging/packages/nftables/-/commit/f26a7145b2885d298925819782a5302905332dbe
|
11 |
# When running on docker this may not be the case.
|
12 |
if $facts['os']['family'] == 'Archlinux' and versioncmp($facts['kernelrelease'],'6.3') < 0 {
|
13 |
$_clobber_default_config = true
|
14 |
} else {
|
15 |
$_clobber_default_config = undef
|
16 |
}
|
17 |
|
18 |
# default mask of firewalld service fails if service is not installed.
|
19 |
# https://tickets.puppetlabs.com/browse/PUP-10814
|
20 |
# Disable all default rules and include below explicitly
|
21 |
class { 'nftables':
|
22 |
firewalld_enable => false,
|
23 |
out_ntp => false,
|
24 |
out_http => false,
|
25 |
out_https => false,
|
26 |
out_icmp => false,
|
27 |
in_ssh => false,
|
28 |
in_icmp => false,
|
29 |
clobber_default_config => $_clobber_default_config,
|
30 |
}
|
31 |
include nftables::rules::icmp
|
32 |
include nftables::rules::dns
|
33 |
include nftables::rules::node_exporter
|
34 |
include nftables::rules::nfs3
|
35 |
include nftables::rules::ssh
|
36 |
include nftables::rules::dhcpv6_client
|
37 |
include nftables::rules::afs3_callback
|
38 |
include nftables::rules::ospf
|
39 |
include nftables::rules::podman
|
40 |
include nftables::rules::http
|
41 |
include nftables::rules::puppet
|
42 |
include nftables::rules::pxp_agent
|
43 |
include nftables::rules::icinga2
|
44 |
include nftables::rules::ldap
|
45 |
include nftables::rules::tor
|
46 |
include nftables::rules::ospf3
|
47 |
include nftables::rules::ceph_mon
|
48 |
include nftables::rules::smtp_submission
|
49 |
include nftables::rules::https
|
50 |
include nftables::rules::nfs
|
51 |
include nftables::rules::smtps
|
52 |
include nftables::rules::smtp
|
53 |
include nftables::rules::ceph
|
54 |
include nftables::rules::samba
|
55 |
include nftables::rules::activemq
|
56 |
include nftables::rules::docker_ce
|
57 |
include nftables::rules::qemu
|
58 |
include nftables::rules::out::postgres
|
59 |
include nftables::rules::out::icmp
|
60 |
include nftables::rules::out::dns
|
61 |
include nftables::rules::out::nfs3
|
62 |
include nftables::rules::out::ssh
|
63 |
include nftables::rules::out::kerberos
|
64 |
include nftables::rules::out::dhcpv6_client
|
65 |
include nftables::rules::out::ospf
|
66 |
include nftables::rules::out::openafs_client
|
67 |
include nftables::rules::out::http
|
68 |
include nftables::rules::out::ssh::remove
|
69 |
include nftables::rules::out::hkp
|
70 |
class{'nftables::rules::out::puppet':
|
71 |
puppetserver => '127.0.0.1',
|
72 |
}
|
73 |
class{'nftables::rules::out::pxp_agent':
|
74 |
broker => '127.0.0.1',
|
75 |
}
|
76 |
class{'nftables::rules::out::ldap':
|
77 |
ldapserver => '127.0.0.1',
|
78 |
}
|
79 |
class{'nftables::rules::out::active_directory':
|
80 |
adserver => '127.0.0.1',
|
81 |
}
|
82 |
include nftables::rules::out::all
|
83 |
include nftables::rules::out::tor
|
84 |
include nftables::rules::out::ospf3
|
85 |
include nftables::rules::out::mysql
|
86 |
include nftables::rules::out::ceph_client
|
87 |
include nftables::rules::out::https
|
88 |
include nftables::rules::out::dhcp
|
89 |
include nftables::rules::out::nfs
|
90 |
include nftables::rules::out::smtp
|
91 |
include nftables::rules::out::smtp_client
|
92 |
include nftables::rules::out::imap
|
93 |
include nftables::rules::out::pop3
|
94 |
include nftables::rules::out::chrony
|
95 |
include nftables::rules::out::wireguard
|
96 |
include nftables::rules::out::whois
|
97 |
include nftables::rules::wireguard
|
98 |
include nftables::rules::multicast
|
99 |
include nftables::rules::spotify
|
100 |
include nftables::rules::llmnr
|
101 |
include nftables::rules::ssdp
|
102 |
include nftables::rules::mdns
|
103 |
include nftables::rules::igmp
|
104 |
include nftables::rules::wsd
|
105 |
include nftables::rules::ftp
|
106 |
include nftables::rules::rsync
|
107 |
include nftables::rules::out::igmp
|
108 |
include nftables::rules::out::mldv2
|
109 |
include nftables::rules::out::mdns
|
110 |
include nftables::rules::out::ssdp
|
111 |
include nftables::rules::out::icinga2
|
112 |
include nftables::services::dhcpv6_client
|
113 |
include nftables::services::openafs_client
|
114 |
$config_path = $facts['os']['family'] ? {
|
115 |
'Archlinux' => '/etc/nftables.conf',
|
116 |
'Debian' => '/etc/nftables.conf',
|
117 |
default => '/etc/sysconfig/nftables.conf',
|
118 |
}
|
119 |
$nft_path = $facts['os']['family'] ? {
|
120 |
'Archlinux' => '/usr/bin/nft',
|
121 |
default => '/usr/sbin/nft',
|
122 |
}
|
123 |
# nftables cannot be started in docker so replace service with a validation only.
|
124 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
125 |
ensure => present,
|
126 |
unit => "nftables.service",
|
127 |
content => [
|
128 |
"[Service]",
|
129 |
"ExecStart=",
|
130 |
"ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
131 |
"ExecReload=",
|
132 |
"ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
133 |
"",
|
134 |
].join("\n"),
|
135 |
notify => Service["nftables"],
|
136 |
}
|
137 |
EOS
|
138 |
# Run it twice and test for idempotency
|
139 |
apply_manifest(pp, catch_failures: true) |
140 |
apply_manifest(pp, catch_changes: true) |
141 |
end
|
142 |
|
143 |
describe package('nftables') do |
144 |
it { is_expected.to be_installed } |
145 |
end
|
146 |
|
147 |
describe service('nftables') do |
148 |
it { is_expected.to be_running } |
149 |
it { is_expected.to be_enabled } |
150 |
end
|
151 |
|
152 |
describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
153 |
it { is_expected.to be_file } |
154 |
end
|
155 |
|
156 |
describe file('/etc/nftables/puppet') do |
157 |
it { is_expected.to be_directory } |
158 |
end
|
159 |
end
|
160 |
end
|