Projet

Général

Profil

Révision c8092701

IDc80927013a38bb0c50947e14cf09b79fe8476b46
Parent c8894978
Enfant c02d1b07

Ajouté par tr il y a plus de 4 ans

Split init class

Voir les différences:

manifests/inet_filter.pp
1
# manage basic chains in table inet filter
2
class nftables::inet_filter inherits nftables {
3

  
4
  nftables::config{
5
    'inet-filter':
6
      source => 'puppet:///modules/nftables/config/puppet-filter.nft';
7
  }
8

  
9
  nftables::chain{
10
    [
11
      'INPUT',
12
      'OUTPUT',
13
      'FORWARD',
14
    ]:;
15
  }
16

  
17
  nftables::chain{
18
    'default_in':
19
      inject => '10-INPUT';
20
    'default_out':
21
      inject => '10-OUTPUT';
22
    'default_fwd':
23
      inject => '10-FORWARD';
24
  }
25

  
26
  # inet-filter-chain-INPUT
27
  nftables::rule{
28
    'INPUT-type':
29
      order   => '01',
30
      content => 'type filter hook input priority 0';
31
    'INPUT-policy':
32
      order   => '02',
33
      content => 'policy drop';
34
    'INPUT-lo':
35
      order   => '03',
36
      content => 'iifname lo accept';
37
    'INPUT-jump_global':
38
      order   => '04',
39
      content => 'jump global';
40
    'INPUT-log_rejected':
41
      order   => '98',
42
      content => 'log prefix "[nftables] INPUT Rejected: " flags all counter reject with icmpx type port-unreachable';
43
  }
44

  
45
  # inet-filter-chain-OUTPUT
46
  nftables::rule{
47
    'OUTPUT-type':
48
      order   => '01',
49
      content => 'type filter hook output priority 0';
50
    'OUTPUT-policy':
51
      order   => '02',
52
      content => 'policy drop';
53
    'OUTPUT-lo':
54
      order   => '03',
55
      content => 'oifname lo accept';
56
    'OUTPUT-jump_global':
57
      order   => '04',
58
      content => 'jump global';
59
    'OUTPUT-log_rejected':
60
      order   => '98',
61
      content => 'log prefix "[nftables] OUTPUT Rejected: " flags all counter reject with icmpx type port-unreachable';
62
  }
63

  
64
  # inet-filter-chain-FORWARD
65
  nftables::rule{
66
    'FORWARD-type':
67
      order   => '01',
68
      content => 'type filter hook forward priority 0';
69
    'FORWARD-policy':
70
      order   => '02',
71
      content => 'policy drop';
72
    'FORWARD-jump_global':
73
      order   => '03',
74
      content => 'jump global';
75
    'FORWARD-log_rejected':
76
      order   => '98',
77
      content => 'log prefix "[nftables] FORWARD Rejected: " flags all counter reject with icmpx type port-unreachable';
78
  }
79

  
80
  # basic ingoing rules
81
  if $nftables::in_ssh {
82
    include nftables::rules::ssh
83
  }
84
}
manifests/init.pp
33 33
    enable => true,
34 34
  }
35 35

  
36
  nftables::config{
37
    'inet-filter':
38
      source => 'puppet:///modules/nftables/config/puppet-filter.nft';
39
    'ip-nat':
40
      source => 'puppet:///modules/nftables/config/puppet-ip-nat.nft';
41
  }
42

  
43
  nftables::chain{
44
    [
45
      'INPUT',
46
      'OUTPUT',
47
      'FORWARD',
48
    ]:;
49
  }
50

  
51
  nftables::chain{
52
    [
53
      'PREROUTING',
54
      'POSTROUTING',
55
    ]:
56
      table => 'ip-nat';
57
  }
58

  
59
  nftables::chain{
60
    'default_in':
61
      inject => '10-INPUT';
62
    'default_out':
63
      inject => '10-OUTPUT';
64
    'default_fwd':
65
      inject => '10-FORWARD';
66
  }
67

  
68
  # inet-filter-chain-INPUT
69
  nftables::rule{
70
    'INPUT-type':
71
      order   => '01',
72
      content => 'type filter hook input priority 0';
73
    'INPUT-policy':
74
      order   => '02',
75
      content => 'policy drop';
76
    'INPUT-lo':
77
      order   => '03',
78
      content => 'iifname lo accept';
79
    'INPUT-jump_global':
80
      order   => '04',
81
      content => 'jump global';
82
    'INPUT-log_rejected':
83
      order   => '98',
84
      content => 'log prefix "[nftables] INPUT Rejected: " flags all counter reject with icmpx type port-unreachable';
85
  }
86

  
87
  # inet-filter-chain-OUTPUT
88
  nftables::rule{
89
    'OUTPUT-type':
90
      order   => '01',
91
      content => 'type filter hook output priority 0';
92
    'OUTPUT-policy':
93
      order   => '02',
94
      content => 'policy drop';
95
    'OUTPUT-lo':
96
      order   => '03',
97
      content => 'oifname lo accept';
98
    'OUTPUT-jump_global':
99
      order   => '04',
100
      content => 'jump global';
101
    'OUTPUT-log_rejected':
102
      order   => '98',
103
      content => 'log prefix "[nftables] OUTPUT Rejected: " flags all counter reject with icmpx type port-unreachable';
104
  }
105

  
106
  # inet-filter-chain-FORWARD
107
  nftables::rule{
108
    'FORWARD-type':
109
      order   => '01',
110
      content => 'type filter hook forward priority 0';
111
    'FORWARD-policy':
112
      order   => '02',
113
      content => 'policy drop';
114
    'FORWARD-jump_global':
115
      order   => '03',
116
      content => 'jump global';
117
    'FORWARD-log_rejected':
118
      order   => '98',
119
      content => 'log prefix "[nftables] FORWARD Rejected: " flags all counter reject with icmpx type port-unreachable';
120
  }
121

  
122
  # ip-nat-chain-PREROUTING
123
  nftables::rule{
124
    default:
125
      table   => 'ip-nat';
126
    'PREROUTING-type':
127
      order   => '01',
128
      content => 'type nat hook prerouting priority -100';
129
    'PREROUTING-policy':
130
      order   => '02',
131
      content => 'policy accept';
132
  }
133

  
134
  # ip-nat-chain-POSTROUTING
135
  nftables::rule{
136
    default:
137
      table   => 'ip-nat';
138
    'POSTROUTING-type':
139
      order   => '01',
140
      content => 'type nat hook postrouting priority 100';
141
    'POSTROUTING-policy':
142
      order   => '02',
143
      content => 'policy accept';
144
  }
145

  
146
  # basic ingoing rules
147
  if $in_ssh {
148
    include nftables::rules::ssh
149
  }
150

  
151
  # basic outgoing rules
152
  if $out_ntp {
153
    include nftables::rules::out::chrony
154
  }
155
  if $out_dns {
156
    include nftables::rules::out::dns
157
  }
158
  if $out_http {
159
    include nftables::rules::out::http
160
  }
161
  if $out_https {
162
    include nftables::rules::out::https
163
  }
36
  include nftables::inet_filter
37
  include nftables::ip_nat
164 38
}
manifests/ip_nat.pp
1
# manage basic chains in table ip nat
2
class nftables::ip_nat inherits nftables {
3

  
4
  nftables::config{
5
    'ip-nat':
6
      source => 'puppet:///modules/nftables/config/puppet-ip-nat.nft';
7
  }
8

  
9
  nftables::chain{
10
    [
11
      'PREROUTING',
12
      'POSTROUTING',
13
    ]:
14
      table => 'ip-nat';
15
  }
16

  
17
  # ip-nat-chain-PREROUTING
18
  nftables::rule{
19
    default:
20
      table   => 'ip-nat';
21
    'PREROUTING-type':
22
      order   => '01',
23
      content => 'type nat hook prerouting priority -100';
24
    'PREROUTING-policy':
25
      order   => '02',
26
      content => 'policy accept';
27
  }
28

  
29
  # ip-nat-chain-POSTROUTING
30
  nftables::rule{
31
    default:
32
      table   => 'ip-nat';
33
    'POSTROUTING-type':
34
      order   => '01',
35
      content => 'type nat hook postrouting priority 100';
36
    'POSTROUTING-policy':
37
      order   => '02',
38
      content => 'policy accept';
39
  }
40

  
41
  # basic outgoing rules
42
  if $nftables::out_ntp {
43
    include nftables::rules::out::chrony
44
  }
45
  if $nftables::out_dns {
46
    include nftables::rules::out::dns
47
  }
48
  if $nftables::out_http {
49
    include nftables::rules::out::http
50
  }
51
  if $nftables::out_https {
52
    include nftables::rules::out::https
53
  }
54
}

Formats disponibles : Unified diff