Projet

Général

Profil

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

root / spec / acceptance / all_rules_spec.rb @ 8bc8fe98

Historique | Voir | Annoter | Télécharger (5,19 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 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::podman
30
      include nftables::rules::http
31
      include nftables::rules::puppet
32
      include nftables::rules::pxp_agent
33
      include nftables::rules::icinga2
34
      include nftables::rules::ldap
35
      include nftables::rules::tor
36
      include nftables::rules::ospf3
37
      include nftables::rules::ceph_mon
38
      include nftables::rules::smtp_submission
39
      include nftables::rules::https
40
      include nftables::rules::nfs
41
      include nftables::rules::smtps
42
      include nftables::rules::smtp
43
      include nftables::rules::ceph
44
      include nftables::rules::samba
45
      include nftables::rules::activemq
46
      include nftables::rules::docker_ce
47
      include nftables::rules::qemu
48
      include nftables::rules::out::postgres
49
      include nftables::rules::out::icmp
50
      include nftables::rules::out::dns
51
      include nftables::rules::out::nfs3
52
      include nftables::rules::out::ssh
53
      include nftables::rules::out::kerberos
54
      include nftables::rules::out::dhcpv6_client
55
      include nftables::rules::out::ospf
56
      include nftables::rules::out::openafs_client
57
      include nftables::rules::out::http
58
      include nftables::rules::out::ssh::remove
59
      include nftables::rules::out::hkp
60
      class{'nftables::rules::out::puppet':
61
        puppetserver => '127.0.0.1',
62
      }
63
      class{'nftables::rules::out::pxp_agent':
64
        broker => '127.0.0.1',
65
      }
66
      class{'nftables::rules::out::ldap':
67
        ldapserver => '127.0.0.1',
68
      }
69
      class{'nftables::rules::out::active_directory':
70
        adserver => '127.0.0.1',
71
      }
72
      include nftables::rules::out::all
73
      include nftables::rules::out::tor
74
      include nftables::rules::out::ospf3
75
      include nftables::rules::out::mysql
76
      include nftables::rules::out::ceph_client
77
      include nftables::rules::out::https
78
      include nftables::rules::out::dhcp
79
      include nftables::rules::out::nfs
80
      include nftables::rules::out::smtp
81
      include nftables::rules::out::smtp_client
82
      include nftables::rules::out::imap
83
      include nftables::rules::out::pop3
84
      include nftables::rules::out::chrony
85
      include nftables::rules::out::wireguard
86
      include nftables::rules::out::whois
87
      include nftables::rules::wireguard
88
      include nftables::rules::multicast
89
      include nftables::rules::spotify
90
      include nftables::rules::llmnr
91
      include nftables::rules::ssdp
92
      include nftables::rules::mdns
93
      include nftables::rules::igmp
94
      include nftables::rules::wsd
95
      include nftables::rules::ftp
96
      include nftables::rules::out::igmp
97
      include nftables::rules::out::mldv2
98
      include nftables::rules::out::mdns
99
      include nftables::rules::out::ssdp
100
      include nftables::services::dhcpv6_client
101
      include nftables::services::openafs_client
102
      $config_path = $facts['os']['family'] ? {
103
        'Archlinux' => '/etc/nftables.conf',
104
        'Debian' => '/etc/nftables.conf',
105
        default => '/etc/sysconfig/nftables.conf',
106
      }
107
      $nft_path = $facts['os']['family'] ? {
108
        'Archlinux' => '/usr/bin/nft',
109
        default => '/usr/sbin/nft',
110
      }
111
      # nftables cannot be started in docker so replace service with a validation only.
112
      systemd::dropin_file{"zzz_docker_nft.conf":
113
        ensure  => present,
114
        unit    => "nftables.service",
115
        content => [
116
          "[Service]",
117
          "ExecStart=",
118
          "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
119
          "ExecReload=",
120
          "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
121
          "",
122
          ].join("\n"),
123
        notify  => Service["nftables"],
124
      }
125
      EOS
126
      # Run it twice and test for idempotency
127
      apply_manifest(pp, catch_failures: true)
128
      apply_manifest(pp, catch_changes: true)
129
    end
130

    
131
    describe package('nftables') do
132
      it { is_expected.to be_installed }
133
    end
134

    
135
    describe service('nftables') do
136
      it { is_expected.to be_running }
137
      it { is_expected.to be_enabled }
138
    end
139

    
140
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
141
      it { is_expected.to be_file }
142
    end
143

    
144
    describe file('/etc/nftables/puppet') do
145
      it { is_expected.to be_directory }
146
    end
147
  end
148
end