]> WPIA git - infra.git/blob - environments/production/manifests/root.pp
9adaee13767d6152e3f55e235247cfb506bb779d
[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 MASQ-v6':
48     provider => 'ip6tables',
49     chain => 'POSTROUTING',
50     table => 'nat',
51     proto  => 'all',
52     jump => 'MASQUERADE',
53     source => "[fc00:1::]/64",
54     outiface => $internet_iface,
55   } ->
56   firewall { '80 dnat-git':
57     proto  => 'tcp',
58     dport  => '9418',
59     jump => 'DNAT',
60     todest => "${$ips[gitweb]}:9418",
61     iniface => $internet_iface,
62     table    => 'nat',
63     chain    => 'PREROUTING',
64   } ->
65   firewall { '80 dnat-htop-ssh':
66     proto  => 'tcp',
67     dport  => '2222',
68     jump => 'DNAT',
69     todest => "${$ips[hop]}:22",
70     iniface => $internet_iface,
71     table    => 'nat',
72     chain    => 'PREROUTING',
73   } ->
74   firewall { '80 MASQ':
75     chain => 'POSTROUTING',
76     table => 'nat',
77     jump => 'MASQUERADE',
78     proto => 'all',
79     outiface => $internet_iface,
80     source => '10.0.3.0/24',
81   }
82 }
83
84
85 node host01 {
86     include my_fw::post
87     include lxc
88     exec { "enable forwarding on $hostname":
89       user    => "root",
90       command => "/bin/echo 1 > /proc/sys/net/ipv4/ip_forward",
91       unless  => "/bin/grep -q 1 /proc/sys/net/ipv4/ip_forward",
92       require => Class['lxc']
93     } -> exec { "enable v6 forwarding on $hostname":
94       user    => "root",
95       command => "/bin/echo 1 > /proc/sys/net/ipv6/conf/all/forwarding",
96       unless  => "/bin/grep -q 1 /proc/sys/net/ipv6/conf/all/forwarding"
97     }->
98       file_line {"root-resolv1":
99       path   => "/etc/resolv.conf",
100       ensure => 'absent',
101       match_for_absence => "true",
102       match  => '^domain ',
103       line   => ''
104     }->
105       file_line {"root-resolv2":
106       path   => "/etc/resolv.conf",
107       ensure => 'absent',
108       match_for_absence => "true",
109       match  => '^search ',
110       line   => ''
111     }
112 if $signerLocation == 'self' {
113     exec {"create cassiopeia-comm-keys":
114       command => '/etc/puppet/code/modules/cassiopeia/mkcassiopeia',
115       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
116     }
117 } else {
118     exec {"create cassiopeia-comm-keys":
119       command => '/bin/false',
120       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
121     }
122 }
123     exec {"gigi keystore.pkcs12":
124       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\'',
125       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 ]'
126     }
127     lxc::container { 'front-nginx':
128         contname => 'front-nginx',
129         ip => $ips[front-nginx],
130         require => File['/data/crl/htdocs']
131     }
132     lxc::container_bind{ '/data/nginx':
133       container => 'front-nginx',
134       target => 'data',
135       option => ',ro'
136     }
137     lxc::container_bind{ '/data/crl':
138       container => 'front-nginx',
139       target => 'data-crl',
140       option => ',ro'
141     }
142     lxc::container_bind{ '/data/gigi-crl':
143       container => 'front-nginx',
144       target => 'data-crl-gigi',
145       option => ',ro'
146     }
147     lxc::container_bind{ '/run/gitweb-socket':
148       container => 'front-nginx',
149       target => 'gitweb-socket',
150     }
151     lxc::container_bind{ '/run/git-smart-http-socket':
152       container => 'front-nginx',
153       target => 'git-smart-http-socket',
154     }
155     lxc::container_bind{ '/data/git':
156       container => 'front-nginx',
157       target => 'srv/git',
158       option => ',ro'
159     }
160     file { '/data':
161        ensure => 'directory',
162     }
163     file { '/data/nginx':
164       ensure => 'directory',
165     }
166     file { '/data/crl':
167       ensure => 'directory',
168       owner => $administrativeUser
169     }
170     file { '/data/git':
171       ensure => 'directory',
172       owner => $administrativeUser,
173     }
174     file { '/data/gigi-crl':
175       ensure => 'directory',
176       owner => $administrativeUser
177     }
178     file { '/data/crl/htdocs':
179       ensure => 'directory',
180       owner => $administrativeUser
181     }
182     file { '/data/postgres/conf':
183       ensure => 'directory',
184     }
185     file { '/data/postgres/data':
186       ensure => 'directory',
187     }
188     file { '/data/postgres':
189       ensure => 'directory',
190     }
191     file { '/data/gigi':
192       ensure => 'directory',
193     }
194     lxc::container { 'postgres-primary':
195         contname => 'postgres-primary',
196         ip => $ips[postgres],
197         dir => ["/var/lib/postgresql", "/etc/postgresql"],
198         bind => {
199           "/data/postgres/data" => { target => "var/lib/postgresql"},
200           "/data/postgres/conf" => { target => "etc/postgresql"}
201         },
202     }
203     $gigi_serial_conf= $signerLocation ? {
204       'self'          => [],
205       '/dev/ttyS0'    => ["lxc.cgroup.devices.allow = c 4:64 rwm"]
206     }
207
208     lxc::container { 'gigi':
209         contname => 'gigi',
210         ip => $ips[gigi],
211         dir => ["/var/lib/wpia-gigi", "/var/lib/wpia-gigi/keys", '/var/lib/cassiopeia', '/var/lib/cassiopeia/ca'],
212         bind => {
213           "/data/gigi" => { target => "var/lib/wpia-gigi/keys"},
214           "/data/gigi-crl" => { target => "var/lib/cassiopeia/ca"}
215         },
216         confline => $gigi_serial_conf,
217     }
218     if $signerLocation == 'self' {
219       lxc::container { 'cassiopeia':
220         contname => 'cassiopeia',
221         ip => $ips[cassiopeia]
222       }
223     }
224     lxc::container { 'exim':
225         contname => 'exim',
226         ip => $ips[exim]
227     }
228     lxc::container { 'hop':
229         contname => 'hop',
230         ip => $ips[hop]
231     }
232     lxc::container { 'quiz':
233         contname => 'quiz',
234         ip => $ips[quiz]
235     }
236     File <| tag == root |>
237     Lxc::Container <| tag == root |>
238     Lxc::Container_bind <| tag == root |>
239     file{'/run/gitweb-socket':
240         ensure => 'directory'
241     }
242     file{'/run/git-smart-http-socket':
243         ensure => 'directory'
244     }
245     lxc::container { 'gitweb':
246         contname => 'gitweb',
247         dir => ['/gitweb-socket', '/git-smart-http-socket', '/srv/git'],
248         bind => {
249           "/run/gitweb-socket" => { 'target' => "gitweb-socket"},
250           "/run/git-smart-http-socket" => { 'target' => "git-smart-http-socket"},
251           "/data/git" => { 'target' => "srv/git", option => ",ro"}
252         },
253         ip => $ips[gitweb]
254     }
255     # Required for bootstrap-user
256     package {'acl':
257         ensure => 'installed'
258     }
259 }
260