Projet

Général

Profil

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

root / manifests / init.pp @ bbc93ede

Historique | Voir | Annoter | Télécharger (4,71 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 sets
39
#   Allows sourcing set definitions directly from Hiera.
40
#
41
# @param log_prefix
42
#   String that will be used as prefix when logging packets. It can contain
43
#   two variables using standard sprintf() string-formatting:
44
#    * chain: Will be replaced by the name of the chain.
45
#    * comment: Allows chains to add extra comments.
46
#
47
# @param log_limit
48
#  String with the content of a limit statement to be applied
49
#  to the rules that log discarded traffic. Set to false to
50
#  disable rate limiting.
51
#
52
# @param reject_with
53
#   How to discard packets not matching any rule. If `false`, the
54
#   fate of the packet will be defined by the chain policy (normally
55
#   drop), otherwise the packet will be rejected with the REJECT_WITH
56
#   policy indicated by the value of this parameter.
57
#
58
# @param in_out_conntrack
59
#   Adds INPUT and OUTPUT rules to allow traffic that's part of an
60
#   established connection and also to drop invalid packets.
61
#
62
# @param firewalld_enable
63
#   Configures how the firewalld systemd service unit is enabled. It might be
64
#   useful to set this to false if you're externaly removing firewalld from
65
#   the system completely.
66
#
67
class nftables (
68
  Boolean $in_ssh                = true,
69
  Boolean $in_icmp               = true,
70
  Boolean $out_ntp               = true,
71
  Boolean $out_dns               = true,
72
  Boolean $out_http              = true,
73
  Boolean $out_https             = true,
74
  Boolean $out_icmp              = true,
75
  Boolean $out_all               = false,
76
  Boolean $in_out_conntrack      = true,
77
  Boolean $nat                   = true,
78
  Hash $rules                    = {},
79
  Hash $sets                     = {},
80
  String $log_prefix             = '[nftables] %<chain>s %<comment>s',
81
  Variant[Boolean[false], String]
82
    $log_limit                   = '3/minute burst 5 packets',
83
  Variant[Boolean[false], Pattern[
84
    /icmp(v6|x)? type .+|tcp reset/]]
85
    $reject_with                 = 'icmpx type port-unreachable',
86
  Variant[Boolean[false], Enum['mask']]
87
    $firewalld_enable            = 'mask',
88
) {
89

    
90
  package{'nftables':
91
    ensure => installed,
92
  } -> file_line{
93
    'enable_nftables':
94
      line   => 'include "/etc/nftables/puppet.nft"',
95
      path   => '/etc/sysconfig/nftables.conf',
96
      notify => Service['nftables'],
97
  } -> file{
98
    default:
99
      owner => 'root',
100
      group => 'root',
101
      mode  => '0640';
102
    '/etc/nftables/puppet-preflight':
103
      ensure  => directory,
104
      mode    => '0750',
105
      purge   => true,
106
      force   => true,
107
      recurse => true;
108
    '/etc/nftables/puppet-preflight.nft':
109
      ensure  => file,
110
      content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat });
111
  } ~> exec{
112
    'nft validate':
113
      refreshonly => true,
114
      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)';
115
  } -> file{
116
    default:
117
      owner => 'root',
118
      group => 'root',
119
      mode  => '0640';
120
    '/etc/nftables/puppet.nft':
121
      ensure  => file,
122
      content => epp('nftables/config/puppet.nft.epp', { 'nat' => $nat });
123
    '/etc/nftables/puppet':
124
      ensure  => directory,
125
      mode    => '0750',
126
      purge   => true,
127
      force   => true,
128
      recurse => true;
129
  } ~> service{'nftables':
130
    ensure     => running,
131
    enable     => true,
132
    hasrestart => true,
133
    restart    => '/usr/bin/systemctl reload nftables',
134
  }
135

    
136
  systemd::dropin_file{'puppet_nft.conf':
137
    ensure => present,
138
    unit   => 'nftables.service',
139
    source => 'puppet:///modules/nftables/systemd/puppet_nft.conf',
140
    notify => Service['nftables'],
141
  }
142

    
143
  service{'firewalld':
144
    ensure => stopped,
145
    enable => $firewalld_enable,
146
  }
147

    
148
  include nftables::inet_filter
149
  if $nat {
150
    include nftables::ip_nat
151
  }
152

    
153
  # inject custom rules e.g. from hiera
154
  $rules.each |$n,$v| {
155
    nftables::rule{
156
      $n:
157
        * => $v
158
    }
159
  }
160

    
161
  # inject custom sets e.g. from hiera
162
  $sets.each |$n,$v| {
163
    nftables::set{
164
      $n:
165
        * => $v
166
    }
167
  }
168
}