Projet

Général

Profil

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

root / manifests / init.pp @ 82d10659

Historique | Voir | Annoter | Télécharger (4,23 ko)

1
# @summary Configure nftables
2
#
3
# @example
4
#   class{'nftables:
5
#     out_ntp = false,
6
#     out_dns = true,
7
#   }
8
#
9
# @param out_all
10
#   Allow all outbound connections. If `true` then all other
11
#   out parameters `out_ntp`, `out_dns`, ... will be assuemed
12
#   false.
13
#
14
# @param out_ntp
15
#   Allow outbound to ntp servers.
16
#
17
# @param out_http
18
#   Allow outbound to http servers.
19
#
20
# @param out_https
21
#   Allow outbound to https servers.
22
#
23
# @param out_https
24
#   Allow outbound to https servers.
25
#
26
# @param out_icmp
27
#   Allow outbound ICMPv4/v6 traffic.
28
#
29
# @param in_ssh
30
#   Allow inbound to ssh servers.
31
#
32
# @param in_icmp
33
#   Allow inbound ICMPv4/v6 traffic.
34
#
35
# @param nat
36
#   Add default tables and chains to process NAT traffic.
37
#
38
# @param log_prefix
39
#   String that will be used as prefix when logging packets. It can contain
40
#   two variables using standard sprintf() string-formatting:
41
#    * chain: Will be replaced by the name of the chain.
42
#    * comment: Allows chains to add extra comments.
43
#
44
# @param reject_with
45
#   How to discard packets not matching any rule. If `false`, the
46
#   fate of the packet will be defined by the chain policy (normally
47
#   drop), otherwise the packet will be rejected with the REJECT_WITH
48
#   policy indicated by the value of this parameter.
49
#
50
# @param in_out_conntrack
51
#   Adds INPUT and OUTPUT rules to allow traffic that's part of an
52
#   established connection and also to drop invalid packets.
53
#
54
# @param firewalld_enable
55
#   Configures how the firewalld systemd service unit is enabled. It might be
56
#   useful to set this to false if you're externaly removing firewalld from
57
#   the system completely.
58
#
59
class nftables (
60
  Boolean $in_ssh                = true,
61
  Boolean $in_icmp               = true,
62
  Boolean $out_ntp               = true,
63
  Boolean $out_dns               = true,
64
  Boolean $out_http              = true,
65
  Boolean $out_https             = true,
66
  Boolean $out_icmp              = true,
67
  Boolean $out_all               = false,
68
  Boolean $in_out_conntrack      = true,
69
  Boolean $nat                   = true,
70
  Hash $rules                    = {},
71
  String $log_prefix             = '[nftables] %<chain>s %<comment>s',
72
  Variant[Boolean[false], Pattern[
73
    /icmp(v6|x)? type .+|tcp reset/]]
74
    $reject_with                 = 'icmpx type port-unreachable',
75
  Variant[Boolean[false], Enum['mask']]
76
    $firewalld_enable            = 'mask',
77
) {
78

    
79
  package{'nftables':
80
    ensure => installed,
81
  } -> file_line{
82
    'enable_nftables':
83
      line   => 'include "/etc/nftables/puppet.nft"',
84
      path   => '/etc/sysconfig/nftables.conf',
85
      notify => Service['nftables'],
86
  } -> file{
87
    default:
88
      owner => 'root',
89
      group => 'root',
90
      mode  => '0640';
91
    '/etc/nftables/puppet-preflight':
92
      ensure  => directory,
93
      mode    => '0750',
94
      purge   => true,
95
      force   => true,
96
      recurse => true;
97
    '/etc/nftables/puppet-preflight.nft':
98
      ensure  => file,
99
      content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat });
100
  } ~> exec{
101
    'nft validate':
102
      refreshonly => true,
103
      command     => '/usr/sbin/nft -I /etc/nftables/puppet-preflight -c -f /etc/nftables/puppet-preflight.nft || ( /usr/bin/echo "#CONFIG BROKEN" >> /etc/nftables/puppet-preflight.nft && /bin/false)';
104
  } -> file{
105
    default:
106
      owner => 'root',
107
      group => 'root',
108
      mode  => '0640';
109
    '/etc/nftables/puppet.nft':
110
      ensure  => file,
111
      content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat });
112
    '/etc/nftables/puppet':
113
      ensure  => directory,
114
      mode    => '0750',
115
      purge   => true,
116
      force   => true,
117
      recurse => true;
118
  } ~> service{'nftables':
119
    ensure     => running,
120
    enable     => true,
121
    hasrestart => true,
122
    restart    => '/usr/bin/systemctl reload nftables',
123
  }
124

    
125
  systemd::dropin_file{'puppet_nft.conf':
126
    ensure => present,
127
    unit   => 'nftables.service',
128
    source => 'puppet:///modules/nftables/systemd/puppet_nft.conf',
129
    notify => Service['nftables'],
130
  }
131

    
132
  service{'firewalld':
133
    ensure => stopped,
134
    enable => $firewalld_enable,
135
  }
136

    
137
  include nftables::inet_filter
138
  if $nat {
139
    include nftables::ip_nat
140
  }
141

    
142
  # inject custom rules e.g. from hiera
143
  $rules.each |$n,$v| {
144
    nftables::rule{
145
      $n:
146
        * => $v
147
    }
148
  }
149
}