Projet

Général

Profil

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

root / spec / acceptance / all_rules_spec.rb @ a1f09048

Historique | Voir | Annoter | Télécharger (4,67 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
      include nftables::rules::out::hkp
58
      class{'nftables::rules::out::puppet':
59
        puppetserver => '127.0.0.1',
60
      }
61
      class{'nftables::rules::out::pxp_agent':
62
        broker => '127.0.0.1',
63
      }
64
      include nftables::rules::out::all
65
      include nftables::rules::out::tor
66
      include nftables::rules::out::ospf3
67
      include nftables::rules::out::mysql
68
      include nftables::rules::out::ceph_client
69
      include nftables::rules::out::https
70
      include nftables::rules::out::dhcp
71
      include nftables::rules::out::nfs
72
      include nftables::rules::out::smtp
73
      include nftables::rules::out::smtp_client
74
      include nftables::rules::out::imap
75
      include nftables::rules::out::pop3
76
      include nftables::rules::out::chrony
77
      include nftables::rules::out::wireguard
78
      include nftables::rules::out::whois
79
      include nftables::rules::wireguard
80
      include nftables::services::dhcpv6_client
81
      include nftables::services::openafs_client
82
      nftables::set{'my_test_set':
83
        type       => 'ipv4_addr',
84
        elements   => ['192.168.0.1', '10.0.0.2'],
85
        table      => ['inet-filter', 'ip-nat'],
86
      }
87
      $config_path = $facts['os']['family'] ? {
88
        'Archlinux' => '/etc/nftables.conf',
89
        'Debian' => '/etc/nftables.conf',
90
        default => '/etc/sysconfig/nftables.conf',
91
      }
92
      $nft_path = $facts['os']['family'] ? {
93
        'Archlinux' => '/usr/bin/nft',
94
        default => '/usr/sbin/nft',
95
      }
96
      # nftables cannot be started in docker so replace service with a validation only.
97
      systemd::dropin_file{"zzz_docker_nft.conf":
98
        ensure  => present,
99
        unit    => "nftables.service",
100
        content => [
101
          "[Service]",
102
          "ExecStart=",
103
          "ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
104
          "ExecReload=",
105
          "ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
106
          "",
107
          ].join("\n"),
108
        notify  => Service["nftables"],
109
      }
110
      EOS
111
      # Run it twice and test for idempotency
112
      apply_manifest(pp, catch_failures: true)
113
      apply_manifest(pp, catch_changes: true)
114
    end
115

    
116
    describe package('nftables') do
117
      it { is_expected.to be_installed }
118
    end
119

    
120
    describe service('nftables') do
121
      it { is_expected.to be_running }
122
      it { is_expected.to be_enabled }
123
    end
124

    
125
    describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
126
      it { is_expected.to be_file }
127
    end
128

    
129
    describe file('/etc/nftables/puppet') do
130
      it { is_expected.to be_directory }
131
    end
132
  end
133
end