]> WPIA git - infra.git/blob - environments/production/manifests/root.pp
initial import
[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 dnat-htop-ssh':
28     proto  => 'tcp',
29     dport  => '2222',
30     jump => 'DNAT',
31     todest => "${$ips[hop]}:22",
32     iniface => $internet_iface,
33     table    => 'nat',
34     chain    => 'PREROUTING',
35   } ->
36   firewall { '80 MASQ':
37     chain => 'POSTROUTING',
38     table => 'nat',
39     jump => 'MASQUERADE',
40     proto => 'all',
41     outiface => $internet_iface,
42     source => '10.0.3.0/24',
43   }
44 }
45
46
47 node host01 {
48     include my_fw::post
49     include lxc
50     package {'bridge-utils':
51         ensure => 'installed'
52     } -> file {'/etc/network/interfaces.d/lxcbr0':
53         source => 'puppet:///modules/lxc/lxcbr0'
54     } -> exec {'ifup lxcbr0':
55       command => '/sbin/ifdown lxcbr0; /sbin/ifup lxcbr0',
56       refreshonly => true,
57       subscribe => File['/etc/network/interfaces.d/lxcbr0']
58     } -> exec { "enable forwarding on $hostname":
59       user    => "root",
60       command => "/bin/echo 1 > /proc/sys/net/ipv4/ip_forward",
61       unless  => "/bin/grep -q 1 /proc/sys/net/ipv4/ip_forward";
62     }->
63       file_line {"root-resolv1":
64       path   => "/etc/resolv.conf",
65       ensure => 'absent',
66       match_for_absence => "true",
67       match  => '^domain ',
68       line   => ''
69     }->
70       file_line {"root-resolv2":
71       path   => "/etc/resolv.conf",
72       ensure => 'absent',
73       match_for_absence => "true",
74       match  => '^search ',
75       line   => ''
76     }
77 if $signerLocation == 'self' {
78     exec {"create cassiopeia-comm-keys":
79       command => '/etc/puppet/code/modules/cassiopeia/mkcassiopeia',
80       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
81     }
82 } else {
83     exec {"create cassiopeia-comm-keys":
84       command => '/bin/false',
85       creates => '/etc/puppet/code/modules/cassiopeia/files/signer_client.crt'
86     }
87 }
88     exec {"gigi keystore.pkcs12":
89       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\'',
90       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 ]'
91     }
92     lxc::container { 'front-nginx':
93         contname => 'front-nginx',
94         ip => $ips[front-nginx],
95         dir => ["/data", "/data-crl", '/data-crl-gigi'],
96         bind => {
97           "/data/nginx" => {target => "data", option => ",ro"},
98           "/data/crl" => {target => "data-crl", option => ",ro"},
99           "/data/gigi-crl" => {target => "data-crl-gigi", option => ",ro"}
100         },
101         require => File['/data/nginx', '/data/crl/htdocs', '/data/gigi-crl']
102     }
103     file { '/data':
104        ensure => 'directory',
105     }
106     file { '/data/nginx':
107       ensure => 'directory',
108     }
109     file { '/data/crl':
110       ensure => 'directory',
111       owner => $administrativeUser
112     }
113     file { '/data/gigi-crl':
114       ensure => 'directory',
115       owner => $administrativeUser
116     }
117     file { '/data/crl/htdocs':
118       ensure => 'directory',
119       owner => $administrativeUser
120     }
121     file { '/data/postgres/conf':
122       ensure => 'directory',
123     }
124     file { '/data/postgres/data':
125       ensure => 'directory',
126     }
127     file { '/data/postgres':
128       ensure => 'directory',
129     }
130     file { '/data/gigi':
131       ensure => 'directory',
132     }
133     lxc::container { 'postgres-primary':
134         contname => 'postgres-primary',
135         ip => $ips[postgres],
136         dir => ["/var/lib/postgresql", "/etc/postgresql"],
137         bind => {
138           "/data/postgres/data" => { target => "var/lib/postgresql"},
139           "/data/postgres/conf" => { target => "etc/postgresql"}
140         },
141         require => File['/data/postgres']
142     }
143     $gigi_serial_conf= $signerLocation ? {
144       'self'          => [],
145       '/dev/ttyS0'    => ["lxc.cgroup.devices.allow = c 4:64 rwm"]
146     }
147
148     lxc::container { 'gigi':
149         contname => 'gigi',
150         ip => $ips[gigi],
151         dir => ["/var/lib/wpia-gigi", "/var/lib/wpia-gigi/keys", '/var/lib/cassiopeia', '/var/lib/cassiopeia/ca'],
152         bind => {
153           "/data/gigi" => { target => "var/lib/wpia-gigi/keys"},
154           "/data/gigi-crl" => { target => "var/lib/cassiopeia/ca"}
155         },
156         confline => $gigi_serial_conf,
157         require => File['/data/gigi', '/data/gigi-crl']
158     }
159     if $signerLocation == 'self' {
160       lxc::container { 'cassiopeia':
161         contname => 'cassiopeia',
162         ip => $ips[cassiopeia]
163       }
164     }
165     lxc::container { 'exim':
166         contname => 'exim',
167         ip => $ips[exim]
168     }
169     lxc::container { 'hop':
170         contname => 'hop',
171         ip => $ips[hop]
172     }
173     lxc::container { 'quiz':
174         contname => 'quiz',
175         ip => $ips[quiz]
176     }
177     # Required for bootstrap-user
178     package {'acl':
179         ensure => 'installed'
180     }
181 }
182