]> WPIA git - infra.git/blob - environments/production/manifests/root.pp
fix: accept dp to work with current gigi and others
[infra.git] / environments / production / manifests / root.pp
1 class my_fw::post {
2   package { 'iptables-persistent':
3     ensure => 'installed'
4   }
5   resources { 'firewall':
6       purge => true,
7   }
8   Package['iptables-persistent'] ->
9   firewall { '80 dnat':
10     proto  => 'tcp',
11     dport  => '80',
12     jump => 'DNAT',
13     todest => "${$ips[front-nginx]}:80",
14     iniface => $internet_iface,
15     table    => 'nat',
16     chain    => 'PREROUTING',
17   } ->
18   firewall { '80 dnat-https':
19     proto  => 'tcp',
20     dport  => '443',
21     jump => 'DNAT',
22     todest => "${$ips[front-nginx]}:443",
23     iniface => $internet_iface,
24     table    => 'nat',
25     chain    => 'PREROUTING',
26   } ->
27   firewall {'80 dnatv6':
28     provider => 'ip6tables',
29     proto  => 'tcp',
30     dport => '80',
31     jump => 'DNAT',
32     todest => "[${$ipsv6[front-nginx]}]:80",
33     iniface => $internet_iface,
34     table => 'nat',
35     chain => 'PREROUTING'
36   } ->
37   firewall {'80 dnatv6-https':
38     provider => 'ip6tables',
39     proto  => 'tcp',
40     dport => '443',
41     jump => 'DNAT',
42     todest => "[${$ipsv6[front-nginx]}]:443",
43     iniface => $internet_iface,
44     table => 'nat',
45     chain => 'PREROUTING'
46   } ->
47   firewall {'80 dnatv6-hop-ssh':
48     provider => 'ip6tables',
49     proto  => 'tcp',
50     dport => '2222',
51     jump => 'DNAT',
52     todest => "[${$ipsv6[hop]}]:22",
53     iniface => $internet_iface,
54     table => 'nat',
55     chain => 'PREROUTING'
56   } ->
57   firewall {'80 MASQ-v6':
58     provider => 'ip6tables',
59     chain => 'POSTROUTING',
60     table => 'nat',
61     proto  => 'all',
62     jump => 'MASQUERADE',
63     source => "[fc00:1::]/64",
64     outiface => $internet_iface,
65   } ->
66   firewall { '80 dnat-git':
67     proto  => 'tcp',
68     dport  => '9418',
69     jump => 'DNAT',
70     todest => "${$ips[gitweb]}:9418",
71     iniface => $internet_iface,
72     table    => 'nat',
73     chain    => 'PREROUTING',
74   } ->
75   firewall { '80 dnat-htop-ssh':
76     proto  => 'tcp',
77     dport  => '2222',
78     jump => 'DNAT',
79     todest => "${$ips[hop]}:22",
80     iniface => $internet_iface,
81     table    => 'nat',
82     chain    => 'PREROUTING',
83   } ->
84   firewall { '80 MASQ':
85     chain => 'POSTROUTING',
86     table => 'nat',
87     jump => 'MASQUERADE',
88     proto => 'all',
89     outiface => $internet_iface,
90     source => '10.0.3.0/24',
91   }
92 }
93
94
95 node host01 {
96     include my_fw::post
97     include lxc
98     exec { "enable forwarding on $hostname":
99       user    => "root",
100       command => "/bin/echo 1 > /proc/sys/net/ipv4/ip_forward",
101       unless  => "/bin/grep -q 1 /proc/sys/net/ipv4/ip_forward",
102       require => Class['lxc']
103     } -> exec { "enable v6 forwarding on $hostname":
104       user    => "root",
105       command => "/bin/echo 1 > /proc/sys/net/ipv6/conf/all/forwarding",
106       unless  => "/bin/grep -q 1 /proc/sys/net/ipv6/conf/all/forwarding"
107     }->
108       file_line {"root-resolv1":
109       path   => "/etc/resolv.conf",
110       ensure => 'absent',
111       match_for_absence => "true",
112       match  => '^domain ',
113       line   => ''
114     }->
115       file_line {"root-resolv2":
116       path   => "/etc/resolv.conf",
117       ensure => 'absent',
118       match_for_absence => "true",
119       match  => '^search ',
120       line   => ''
121     }
122 if $signerLocation == 'self' {
123     exec {"create cassiopeia-comm-keys":
124       command => '/etc/puppet/code/modules/cassiopeia/mkcassiopeia',
125       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
126     }
127 } else {
128     exec {"create cassiopeia-comm-keys":
129       command => '/bin/false',
130       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
131     }
132 }
133     exec {"gigi keystore.pkcs12":
134       command => '/bin/bash -c \'keystorepw=$(/usr/bin/head -c 15 /dev/urandom | base64); /usr/bin/openssl pkcs12 -export -name "mail" -in /etc/puppet/code/modules/gigi/files/client.crt -inkey /etc/puppet/code/modules/gigi/client.key -CAfile /etc/puppet/codemodules/nre/files/config/ca/root.crt -password file:<(echo $keystorepw) > /etc/puppet/code/modules/gigi/files/keystore.pkcs12; /usr/bin/printf "%s" "$keystorepw" > /etc/puppet/code/modules/gigi/files/keystorepw\'',
135       unless => '/usr/bin/[  /etc/puppet/code/modules/gigi/files/keystore.pkcs12 -nt /etc/puppet/code/modules/gigi/files/client.crt ] || ! /usr/bin/[ -f /etc/puppet/code/modules/gigi/files/client.crt ]'
136     }
137     lxc::container { 'front-nginx':
138         contname => 'front-nginx',
139         ip => $ips[front-nginx],
140         require => File['/data/crl/htdocs']
141     }
142     lxc::container_bind{ '/data/nginx':
143       container => 'front-nginx',
144       target => 'data',
145       option => ',ro'
146     }
147     lxc::container_bind{ '/data/crl':
148       container => 'front-nginx',
149       target => 'data-crl',
150       option => ',ro'
151     }
152     lxc::container_bind{ '/data/gigi-crl':
153       container => 'front-nginx',
154       target => 'data-crl-gigi',
155       option => ',ro'
156     }
157     lxc::container_bind{ '/run/gitweb-socket':
158       container => 'front-nginx',
159       target => 'gitweb-socket',
160     }
161     lxc::container_bind{ '/run/git-smart-http-socket':
162       container => 'front-nginx',
163       target => 'git-smart-http-socket',
164     }
165     lxc::container_bind{ '/data/git':
166       container => 'front-nginx',
167       target => 'srv/git',
168       option => ',ro'
169     }
170     file { '/data':
171        ensure => 'directory',
172     }
173     file { '/data/nginx':
174       ensure => 'directory',
175     }
176     file { '/data/crl':
177       ensure => 'directory',
178       owner => $administrativeUser
179     }
180     file { '/data/git':
181       ensure => 'directory',
182       owner => $administrativeUser,
183     }
184     file { '/data/gigi-crl':
185       ensure => 'directory',
186       owner => $administrativeUser
187     }
188     file { '/data/crl/htdocs':
189       ensure => 'directory',
190       owner => $administrativeUser
191     }
192     file { '/data/postgres/conf':
193       ensure => 'directory',
194     }
195     file { '/data/postgres/data':
196       ensure => 'directory',
197     }
198     file { '/data/postgres':
199       ensure => 'directory',
200     }
201     file { '/data/gigi':
202       ensure => 'directory',
203     }
204     lxc::container { 'postgres-primary':
205         contname => 'postgres-primary',
206         ip => $ips[postgres],
207         dir => ["/var/lib/postgresql", "/etc/postgresql"],
208         bind => {
209           "/data/postgres/data" => { target => "var/lib/postgresql"},
210           "/data/postgres/conf" => { target => "etc/postgresql"}
211         },
212     }
213     $gigi_serial_conf= $signerLocation ? {
214       'self'          => [],
215       '/dev/ttyS0'    => ["lxc.cgroup.devices.allow = c 4:64 rwm"]
216     }
217
218     lxc::container { 'gigi':
219         contname => 'gigi',
220         ip => $ips[gigi],
221         dir => ["/var/lib/wpia-gigi", "/var/lib/wpia-gigi/keys", '/var/lib/cassiopeia', '/var/lib/cassiopeia/ca'],
222         bind => {
223           "/data/gigi" => { target => "var/lib/wpia-gigi/keys"},
224           "/data/gigi-crl" => { target => "var/lib/cassiopeia/ca"}
225         },
226         confline => $gigi_serial_conf,
227     }
228     if $signerLocation == 'self' {
229       lxc::container { 'cassiopeia':
230         contname => 'cassiopeia',
231         ip => $ips[cassiopeia]
232       }
233     }
234     lxc::container { 'exim':
235         contname => 'exim',
236         ip => $ips[exim]
237     }
238     lxc::container { 'hop':
239         contname => 'hop',
240         ip => $ips[hop]
241     }
242     lxc::container { 'quiz':
243         contname => 'quiz',
244         ip => $ips[quiz]
245     }
246     File <| tag == root |>
247     Lxc::Container <| tag == root |>
248     Lxc::Container_bind <| tag == root |>
249     file{'/run/gitweb-socket':
250         ensure => 'directory'
251     }
252     file{'/run/git-smart-http-socket':
253         ensure => 'directory'
254     }
255     lxc::container { 'gitweb':
256         contname => 'gitweb',
257         dir => ['/gitweb-socket', '/git-smart-http-socket', '/srv/git'],
258         bind => {
259           "/run/gitweb-socket" => { 'target' => "gitweb-socket"},
260           "/run/git-smart-http-socket" => { 'target' => "git-smart-http-socket"},
261           "/data/git" => { 'target' => "srv/git", option => ",ro"}
262         },
263         ip => $ips[gitweb]
264     }
265     # Required for bootstrap-user
266     package {'acl':
267         ensure => 'installed'
268     }
269 }
270