Projet

Général

Profil

Révision fd0eaeca

IDfd0eaeca0ae49894d698a47671455c990760b78a
Parent c1224db5
Enfant 66b1a7a9

Ajouté par tr il y a plus de 4 ans

Add class bridges

Allow traffic from any bridge to itself by default

Voir les différences:

manifests/bridges.pp
1
# allow forwarding traffic on bridges
2
class nftables::bridges(
3
  Enum['present','absent']
4
    $ensure = 'present',
5
  Regexp
6
    $bridgenames = /br+/
7
) {
8
  if $ensure == 'present' {
9
    $interfaces = keys($facts['networking']['interfaces'])
10
    $bridges = $interfaces.filter |$items| { $items =~ $bridgenames }
11

  
12
    $bridges.each |String $bridge| {
13
      nftables::rule { "default_fwd-bridge_${bridge}_${bridge}":
14
        order   => '08',
15
        content => "iifname ${bridge} oifname ${bridge} accept",
16
      }
17
    }
18
  }
19
}
manifests/inet_filter.pp
95 95
    }
96 96
  }
97 97

  
98
  # allow forwarding traffic on bridges
99
  include nftables::bridges
100

  
98 101
  # basic ingoing rules
99 102
  if $nftables::in_ssh {
100 103
    include nftables::rules::ssh
spec/classes/bridges_spec.rb
1
require 'spec_helper'
2

  
3
describe 'nftables' do
4
  let(:pre_condition) { 'Exec{path => "/bin"}' }
5

  
6
  on_supported_os.each do |os, os_facts|
7
    context "on #{os}" do
8
      let(:facts) { os_facts }
9

  
10
      it { is_expected.to compile }
11

  
12
      it {
13
        is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
14
          path:           '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
15
          owner:          'root',
16
          group:          'root',
17
          mode:           '0640',
18
          ensure_newline: true,
19
        )
20
      }
21
      it {
22
        is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
23
          target:  'nftables-inet-filter-chain-default_fwd',
24
          content: %r{^chain default_fwd \{$},
25
          order:   '00',
26
        )
27
      }
28
      it {
29
        is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-bridge_br0_br0').with(
30
          target:  'nftables-inet-filter-chain-default_fwd',
31
          content: %r{^  iifname br0 oifname br0 accept$},
32
          order:   '08',
33
        )
34
      }
35
      it {
36
        is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-bridge_br1_br1').with(
37
          target:  'nftables-inet-filter-chain-default_fwd',
38
          content: %r{^  iifname br1 oifname br1 accept$},
39
          order:   '08',
40
        )
41
      }
42
      it { is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-bridge_br0_br1') }
43
      it { is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-bridge_br1_br0') }
44
      it {
45
        is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
46
          target:  'nftables-inet-filter-chain-default_fwd',
47
          content: %r{^\}$},
48
          order:   '99',
49
        )
50
      }
51
    end
52
  end
53
end
spec/default_module_facts.yml
1
---
2
networking:
3
  dhcp: 192.0.2.1
4
  domain: example.com
5
  fqdn: centos8.example.com
6
  hostname: centos8
7
  interfaces:
8
    ens3:
9
      bindings:
10
      - address: 192.0.2.2
11
        netmask: 255.255.255.0
12
        network: 192.0.2.0
13
      bindings6:
14
      - address: 2001:db8::2
15
        netmask: 'ffff:ffff:ffff:ffff::'
16
        network: '2001:db8::'
17
      dhcp: 192.0.2.1
18
      ip: 192.0.2.2
19
      ip6: 2001:db8::1
20
      mac: 00:00:00:00:00:00
21
      mtu: 1500
22
      netmask: 255.255.255.0
23
      netmask6: 'ffff:ffff:ffff:ffff::'
24
      network: 192.0.2.0
25
      network6: '2001:db8::'
26
      scope6: global
27
    br0:
28
      bindings:
29
      - address: 198.51.100.1
30
        netmask: 255.255.255.224
31
        network: 198.51.100.0
32
      bindings6:
33
      - address: 2001:db8:1::1
34
        netmask: 'ffff:ffff:ffff:ffff:ffff::'
35
        network: '2001:db8:1::'
36
      ip: 198.51.100.1
37
      ip6: 2001:db8:1::1
38
      mac: AA:AA:AA:AA:AA:AA
39
      mtu: 1500
40
      netmask: 255.255.255.224
41
      netmask6: 'ffff:ffff:ffff:ffff:ffff::'
42
      network: 198.51.100.0
43
      network6: '2001:db8:1::'
44
      scope6: global
45
    br1:
46
      bindings:
47
      - address: 198.51.100.33
48
        netmask: 255.255.255.224
49
        network: 198.51.100.32
50
      bindings6:
51
      - address: 2001:db8:2::1
52
        netmask: 'ffff:ffff:ffff:ffff:ffff::'
53
        network: '2001:db8:2::'
54
      ip: 198.51.100.33
55
      ip6: 2001:db8:2::1
56
      mac: BB:BB:BB:BB:BB:BB
57
      mtu: 1500
58
      netmask: 255.255.255.224
59
      netmask6: 'ffff:ffff:ffff:ffff:ffff::'
60
      network: 198.51.100.32
61
      network6: '2001:db8:2::'
62
      scope6: global
63
    lo:
64
      bindings:
65
      - address: 127.0.0.1
66
        netmask: 255.0.0.0
67
        network: 127.0.0.0
68
      bindings6:
69
      - address: "::1"
70
        netmask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
71
        network: "::1"
72
      ip: 127.0.0.1
73
      ip6: "::1"
74
      mtu: 65536
75
      netmask: 255.0.0.0
76
      netmask6: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
77
      network: 127.0.0.0
78
      network6: "::1"
79
      scope6: host
80
  ip: 192.0.2.2
81
  ip6: 2001:db8::2
82
  mac: 00:00:00:00:00:00
83
  mtu: 1500
84
  netmask: 255.255.255.0
85
  netmask6: 'ffff:ffff:ffff:ffff::'
86
  network: 192.0.2.0
87
  network6: '2001:db8::'
88
  primary: ens3
89
  scope6: global

Formats disponibles : Unified diff