Projet

Général

Profil

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

root / spec / acceptance / all_rules_spec.rb @ 7f74df2e

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

    
111
    describe package('nftables') do
112
      it { is_expected.to be_installed }
113
    end
114

    
115
    describe service('nftables') do
116
      it { is_expected.to be_running }
117
      it { is_expected.to be_enabled }
118
    end
119

    
120
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
121
      it { is_expected.to be_file }
122
    end
123

    
124
    describe file('/etc/nftables/puppet') do
125
      it { is_expected.to be_directory }
126
    end
127
  end
128
end