Projet

Général

Profil

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

root / manifests / init.pp @ ea96d5db

Historique | Voir | Annoter | Télécharger (2,67 ko)

1 e17693e3 Steve Traylen
# @summary Configure nftables
2
#
3
# @example
4
#   class{'nftables:
5
#     out_ntp = false,
6
#     out_dns = true,
7 b3a7a6dd tr
#   }
8 e17693e3 Steve Traylen
#
9 b3a7a6dd tr
# @param out_all
10 e17693e3 Steve Traylen
#   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 in_ssh
27
#   Allow inbound to ssh servers.
28
#
29 ac0af4aa Nacho Barrientos
# @param log_prefix
30
#   String that will be used as prefix when logging packets. It can contain
31
#   two variables using standard sprintf() string-formatting:
32
#    * chain: Will be replaced by the name of the chain.
33
#    * comment: Allows chains to add extra comments.
34
#
35 70727742 Nacho Barrientos
# @param reject_with
36
#   How to discard packets not matching any rule. If `false`, the
37
#   fate of the packet will be defined by the chain policy (normally
38
#   drop), otherwise the packet will be rejected with the REJECT_WITH
39
#   policy indicated by the value of this parameter.
40
#
41 ea96d5db Nacho Barrientos
# @param in_out_conntrack
42
#   Adds INPUT and OUTPUT rules to allow traffic that's part of an
43
#   established connection and also to drop invalid packets.
44
#
45 be0b08e1 tr
class nftables (
46 70727742 Nacho Barrientos
  Boolean $in_ssh                = true,
47
  Boolean $out_ntp               = true,
48
  Boolean $out_dns               = true,
49
  Boolean $out_http              = true,
50
  Boolean $out_https             = true,
51
  Boolean $out_all               = false,
52 ea96d5db Nacho Barrientos
  Boolean $in_out_conntrack      = true,
53 70727742 Nacho Barrientos
  Hash $rules                    = {},
54 ac0af4aa Nacho Barrientos
  String $log_prefix             = '[nftables] %<chain>s %<comment>s',
55 70727742 Nacho Barrientos
  Variant[Boolean[false], Pattern[
56
    /icmp(v6|x)? type .+|tcp reset/]]
57
    $reject_with                 = 'icmpx type port-unreachable',
58 be0b08e1 tr
) {
59
60 0ba57c66 mh
  package{'nftables':
61
    ensure => installed,
62
  } -> file_line{
63
    'enable_nftables':
64
      line   => 'include "/etc/nftables/puppet.nft"',
65
      path   => '/etc/sysconfig/nftables.conf',
66
      notify => Service['nftables'],
67
  } -> file{
68
    default:
69 e140adff tr
      owner => 'root',
70
      group => 'root',
71
      mode  => '0640';
72 0ba57c66 mh
    '/etc/nftables/puppet.nft':
73 5acb554a tr
      ensure => file,
74 0ba57c66 mh
      source => 'puppet:///modules/nftables/config/puppet.nft';
75
    '/etc/nftables/puppet':
76
      ensure  => directory,
77 5acb554a tr
      mode    => '0750',
78 0ba57c66 mh
      purge   => true,
79
      force   => true,
80
      recurse => true;
81
  } ~> service{'nftables':
82 e140adff tr
    ensure => running,
83
    enable => true,
84 0ba57c66 mh
  }
85
86 f02562f2 tr
  service{'firewalld':
87
    ensure => stopped,
88
    enable => mask,
89
  }
90
91 c8092701 tr
  include nftables::inet_filter
92
  include nftables::ip_nat
93 b3a7a6dd tr
94
  # inject custom rules e.g. from hiera
95 66ed7f61 mh
  $rules.each |$n,$v| {
96
    nftables::rule{
97
      $n:
98
        * => $v
99
    }
100
  }
101 0ba57c66 mh
}