Projet

Général

Profil

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

root / spec / acceptance / all_rules_spec.rb @ ffc8b86f

Historique | Voir | Annoter | Télécharger (5,29 ko)

1 c82b960a Steve Traylen
# frozen_string_literal: true
2
3 cfcafde5 Steve Traylen
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 mask of firewalld service fails if service is not installed.
10
      # https://tickets.puppetlabs.com/browse/PUP-10814
11
      # Disable all default rules and include below explicitly
12
      class { 'nftables':
13
        firewalld_enable => false,
14
        out_ntp          => false,
15
        out_http         => false,
16
        out_https        => false,
17
        out_icmp         => false,
18
        in_ssh           => false,
19
        in_icmp          => false,
20
      }
21
      include nftables::rules::icmp
22
      include nftables::rules::dns
23
      include nftables::rules::node_exporter
24
      include nftables::rules::nfs3
25
      include nftables::rules::ssh
26
      include nftables::rules::dhcpv6_client
27
      include nftables::rules::afs3_callback
28
      include nftables::rules::ospf
29
      include nftables::rules::http
30
      include nftables::rules::puppet
31 7f74df2e Tim Meusel
      include nftables::rules::pxp_agent
32 cfcafde5 Steve Traylen
      include nftables::rules::icinga2
33 ea29e235 Simon Hoenscheid
      include nftables::rules::ldap
34 cfcafde5 Steve Traylen
      include nftables::rules::tor
35
      include nftables::rules::ospf3
36
      include nftables::rules::ceph_mon
37
      include nftables::rules::smtp_submission
38
      include nftables::rules::https
39
      include nftables::rules::nfs
40
      include nftables::rules::smtps
41
      include nftables::rules::smtp
42
      include nftables::rules::ceph
43 1ee2f66b Giuseppe Lo Presti
      include nftables::rules::samba
44 771b3256 Nacho Barrientos
      include nftables::rules::activemq
45 6be2adf7 Luis Fernández Álvarez
      include nftables::rules::docker_ce
46 cd2a3cbf Nacho Barrientos
      include nftables::rules::qemu
47 cfcafde5 Steve Traylen
      include nftables::rules::out::postgres
48
      include nftables::rules::out::icmp
49
      include nftables::rules::out::dns
50
      include nftables::rules::out::nfs3
51
      include nftables::rules::out::ssh
52
      include nftables::rules::out::kerberos
53
      include nftables::rules::out::dhcpv6_client
54
      include nftables::rules::out::ospf
55
      include nftables::rules::out::openafs_client
56
      include nftables::rules::out::http
57
      include nftables::rules::out::ssh::remove
58 a1f09048 Tim Meusel
      include nftables::rules::out::hkp
59 cfcafde5 Steve Traylen
      class{'nftables::rules::out::puppet':
60 04176b0e mh
        puppetserver => '127.0.0.1',
61 cfcafde5 Steve Traylen
      }
62 194e05d5 Tim Meusel
      class{'nftables::rules::out::pxp_agent':
63
        broker => '127.0.0.1',
64
      }
65 ea29e235 Simon Hoenscheid
      class{'nftables::rules::out::ldap':
66
        ldapserver => '127.0.0.1',
67
      }
68
      class{'nftables::rules::out::active_directory':
69
        adserver => '127.0.0.1',
70
      }
71 cfcafde5 Steve Traylen
      include nftables::rules::out::all
72
      include nftables::rules::out::tor
73
      include nftables::rules::out::ospf3
74
      include nftables::rules::out::mysql
75
      include nftables::rules::out::ceph_client
76
      include nftables::rules::out::https
77
      include nftables::rules::out::dhcp
78
      include nftables::rules::out::nfs
79
      include nftables::rules::out::smtp
80 19908f41 mh
      include nftables::rules::out::smtp_client
81
      include nftables::rules::out::imap
82
      include nftables::rules::out::pop3
83 cfcafde5 Steve Traylen
      include nftables::rules::out::chrony
84
      include nftables::rules::out::wireguard
85 2b1896c1 Tim Meusel
      include nftables::rules::out::whois
86 cfcafde5 Steve Traylen
      include nftables::rules::wireguard
87 80b384c8 Tim Meusel
      include nftables::rules::multicast
88 8b131276 Tim Meusel
      include nftables::rules::spotify
89 3b26826f Tim Meusel
      include nftables::rules::llmnr
90 50a5be8b Tim Meusel
      include nftables::rules::ssdp
91 5ffd0328 Tim Meusel
      include nftables::rules::mdns
92 020842af Tim Meusel
      include nftables::rules::igmp
93 ffc8b86f Tim Meusel
      include nftables::rules::wsd
94 020842af Tim Meusel
      include nftables::rules::out::igmp
95 e499cece Tim Meusel
      include nftables::rules::out::mldv2
96 6b350264 Tim Meusel
      include nftables::rules::out::mdns
97 50a5be8b Tim Meusel
      include nftables::rules::out::ssdp
98 cfcafde5 Steve Traylen
      include nftables::services::dhcpv6_client
99
      include nftables::services::openafs_client
100 c94658e1 Nacho Barrientos
      nftables::set{'my_test_set':
101
        type       => 'ipv4_addr',
102
        elements   => ['192.168.0.1', '10.0.0.2'],
103
        table      => ['inet-filter', 'ip-nat'],
104
      }
105 8842a597 Tim Meusel
      $config_path = $facts['os']['family'] ? {
106
        'Archlinux' => '/etc/nftables.conf',
107 008c95d7 Kienan Stewart
        'Debian' => '/etc/nftables.conf',
108 8842a597 Tim Meusel
        default => '/etc/sysconfig/nftables.conf',
109
      }
110
      $nft_path = $facts['os']['family'] ? {
111
        'Archlinux' => '/usr/bin/nft',
112
        default => '/usr/sbin/nft',
113 0c9bc308 hashworks
      }
114 cfcafde5 Steve Traylen
      # nftables cannot be started in docker so replace service with a validation only.
115
      systemd::dropin_file{"zzz_docker_nft.conf":
116
        ensure  => present,
117
        unit    => "nftables.service",
118
        content => [
119
          "[Service]",
120
          "ExecStart=",
121 8842a597 Tim Meusel
          "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
122 cfcafde5 Steve Traylen
          "ExecReload=",
123 8842a597 Tim Meusel
          "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
124 cfcafde5 Steve Traylen
          "",
125
          ].join("\n"),
126
        notify  => Service["nftables"],
127
      }
128
      EOS
129
      # Run it twice and test for idempotency
130
      apply_manifest(pp, catch_failures: true)
131
      apply_manifest(pp, catch_changes: true)
132
    end
133
134
    describe package('nftables') do
135
      it { is_expected.to be_installed }
136
    end
137
138
    describe service('nftables') do
139
      it { is_expected.to be_running }
140
      it { is_expected.to be_enabled }
141
    end
142
143 b5874974 Steve Traylen
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
144 cfcafde5 Steve Traylen
      it { is_expected.to be_file }
145
    end
146
147
    describe file('/etc/nftables/puppet') do
148
      it { is_expected.to be_directory }
149
    end
150
  end
151
end