Projet

Général

Profil

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

root / manifests / rules / docker_ce.pp @ c3515492

Historique | Voir | Annoter | Télécharger (3,49 ko)

1 6be2adf7 Luis Fernández Álvarez
# @summary Default firewall configuration for Docker-CE
2
#
3
# The configuration distributed in this class represents the default firewall
4
# configuration done by docker-ce when the iptables integration is enabled.
5
#
6
# This class is needed as the default docker-ce rules added to ip-filter conflict
7
# with the inet-filter forward rules set by default in this module.
8
#
9
# When using this class 'docker::iptables: false' should be set.
10
#
11
# @param docker_interface
12
#   Interface name used by docker. It defaults to docker0.
13
# @param docker_prefix
14
#   The address space used by docker. It defaults to 172.17.0.0/16.
15
#
16
class nftables::rules::docker_ce (
17
  String[1]                     $docker_interface = 'docker0',
18
  Stdlib::IP::Address::V4::CIDR $docker_prefix    = '172.17.0.0/16',
19
) {
20
  #
21
  # inet-filter
22
  #
23
24
  nftables::chain {
25
    'DOCKER': ;
26
    'DOCKER_ISOLATION_STAGE_1': ;
27
    'DOCKER_ISOLATION_STAGE_2': ;
28
    'DOCKER_USER': ;
29
  }
30
31
  nftables::rule {
32
    'DOCKER_ISOLATION_STAGE_1-iifname':
33
      order   => '01',
34
      content => "iifname \"${docker_interface}\" oifname != \"${docker_interface}\" counter jump DOCKER_ISOLATION_STAGE_2";
35
    'DOCKER_ISOLATION_STAGE_1-counter':
36
      order   => '02',
37
      content => 'counter return';
38
    'DOCKER_ISOLATION_STAGE_2-drop':
39
      order   => '01',
40
      content => "oifname \"${docker_interface}\" counter drop";
41
    'DOCKER_ISOLATION_STAGE_2-counter':
42
      order   => '02',
43
      content => 'counter return';
44
    'DOCKER_USER-counter':
45
      order   => '01',
46
      content => 'counter return',
47
  }
48
49
  nftables::rule {
50
    'default_fwd-jump_docker_user':
51
      order   => '40',
52
      content => 'counter jump DOCKER_USER';
53
    'default_fwd-jump_docker_isolation_stage_1':
54
      order   => '41',
55
      content => 'counter jump DOCKER_ISOLATION_STAGE_1';
56
    'default_fwd-out_docker_accept':
57
      order   => '42',
58
      content => "oifname \"${docker_interface}\" ct state established,related counter accept";
59
    'default_fwd-jump_docker':
60
      order   => '43',
61
      content => "oifname \"${docker_interface}\" counter jump DOCKER";
62
    'default_fwd-idocker_onot_accept':
63
      order   => '44',
64
      content => "iifname \"${docker_interface}\" oifname != \"${docker_interface}\" counter accept";
65
    'default_fwd-idocker_odocker_accept':
66
      order   => '45',
67
      content => "iifname \"${docker_interface}\" oifname \"${docker_interface}\" counter accept";
68
  }
69
70
  #
71
  # ip-nat
72
  #
73
74
  nftables::chain {
75
    'DOCKER-nat':
76
      table => 'ip-nat',
77
      chain => 'DOCKER';
78
    'OUTPUT-nat':
79
      table => 'ip-nat',
80
      chain => 'OUTPUT';
81
    'INPUT-nat':
82
      table => 'ip-nat',
83
      chain => 'INPUT';
84
  }
85
86
  nftables::rule {
87
    'POSTROUTING-docker':
88
      table   => 'ip-nat',
89
      content => "oifname != \"${docker_interface}\" ip saddr ${docker_prefix} counter masquerade";
90
    'PREROUTING-docker':
91
      table   => 'ip-nat',
92
      content => 'fib daddr type local counter jump DOCKER';
93
    'OUTPUT-jump_docker@ip-nat':
94 c3515492 Luis Fernández Álvarez
      rulename => 'OUTPUT-jump_docker',
95
      table    => 'ip-nat',
96
      content  => 'ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER';
97 6be2adf7 Luis Fernández Álvarez
    'DOCKER-counter':
98
      table   => 'ip-nat',
99
      content => "iifname \"${docker_interface}\" counter return";
100
    'INPUT-type@ip-nat':
101
      rulename => 'INPUT-type',
102
      table    => 'ip-nat',
103
      order    => '01',
104
      content  => 'type nat hook input priority 100';
105
    'INPUT-policy@ip-nat':
106
      rulename => 'INPUT-policy',
107
      table    => 'ip-nat',
108
      order    => '02',
109
      content  => 'policy accept';
110
  }
111
}