summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/roundcube.pp
blob: ffc1ea852b7ae0b7496ba6d0a2891e6eeca78a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# Class: profiles::roundcube
# ==========================
#
# This class installs and configures the roundcube webmail system.
#
# Parameters
# ----------
#
# @param additional_names    Additional host names for the Apache VirtualHost
#
# @param des_key             Key to encrypt the the client cookies, must be
#                            exactly 24 characters long
#
# @param email_host          Hostname of the email server
#
# @param email_host_ip       IP address of the email server
#
# @param external_name       External host name used for the Apache VirtualHost
#
# @param mail_domain         Mail domain used to find matching user names from
#                            client certificate Email SubjectAlternativeName
#                            extensions
#
# @param master_password     IMAP server master password used for client
#                            certificate authentication
#
# @param mail_debug          php boolean string used to toggle mail debugging
#
# Examples
# --------
#
# @example
#   class roles::myhost {
#     include profiles::roundcube
#   }
#
# Authors
# -------
#
# Jan Dittberner <jandd@cacert.org>
#
# Copyright
# ---------
#
# Copyright 2019-2020 Jan Dittberner
class profiles::roundcube (
  String $des_key,
  String $master_password,
  String $email_host = 'email.cacert.org',
  String $email_host_ip = '10.0.0.19',
  String $mail_domain = 'cacert.org',
  String $mail_debug = 'false',
  String $external_name = 'webmail.cacert.org',
  Array[String] $additional_names = ['community.cacert.org'],
) {
  include profiles::cacert_debrepo
  include profiles::x509cert_common

  package { 'mariadb-server':
    ensure => latest,
  }

  package { [
      'dbconfig-mysql',
      'php-zip',
      'php-gd',
      'libapache2-mod-php',
      'roundcube',
      'roundcube-plugins',
      'roundcube-mysql',
      'roundcube-plugin-clientcert-authentication',
    ]:
    ensure => latest,
  }

  host { $email_host:
    ensure       => 'present',
    ip           => $email_host_ip,
    host_aliases => ['email.infra.cacert.org'],
    target       => '/etc/hosts',
  }

  $cacert_cert_bundle = '/etc/ssl/certs/cacert.org.pem'

  concat { $cacert_cert_bundle:
    ensure => present,
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }
  concat::fragment { 'bundle-cacert-class3-ca':
    order  => 10,
    target => $cacert_cert_bundle,
    source => 'puppet:///modules/profiles/base/cacert_class3_X0E.crt',
  }
  concat::fragment { 'bundle-cacert-class1-ca':
    order  => 20,
    target => $cacert_cert_bundle,
    source => 'puppet:///modules/profiles/base/cacert_class1_X0F.crt',
  }

  file { '/etc/roundcube/config.inc.php':
    ensure  => file,
    owner   => 'root',
    group   => 'www-data',
    mode    => '0640',
    content => epp('profiles/roundcube/config.inc.php.epp', {
      des_key      => $des_key,
      email_host   => $email_host,
      plugins      => ['clientcert_authentication', 'managesieve', 'dovecot_impersonate', 'twofactor_gauthenticator'],
      skin         => 'larry',
      smtp_port    => 587,
      support_url  => 'https://bugs.cacert.org/set_project.php?project_id=18;30',
      mail_domain  => 'cacert.org',
      debug        => $mail_debug,
      cacert_certs => $cacert_cert_bundle,
    }),
    require => [
      Package['roundcube'],
      Package['roundcube-plugins'],
      Package['roundcube-plugin-clientcert-authentication'],
    ],
  }

  file { '/etc/roundcube/plugins/managesieve/config.inc.php':
    ensure  => file,
    owner   => 'root',
    group   => 'www-data',
    mode    => '0640',
    content => epp('profiles/roundcube/managesieve-config.inc.php.epp', {
      cacert_certs => $cacert_cert_bundle,
    }),
    require => Package['roundcube-plugins'],
  }

  file { '/etc/roundcube/plugins/clientcert_authentication/config.inc.php':
    ensure  => file,
    owner   => 'root',
    group   => 'www-data',
    mode    => '0640',
    content => epp('profiles/roundcube/clientcert_authentication-config.inc.php.epp', {
      mail_domain     => $mail_domain,
      master_password => $master_password,
    }),
    require => Package['roundcube-plugin-clientcert-authentication'],
  }

  $roundcube_local_plugins = '/usr/local/share/roundcube'

  file { $roundcube_local_plugins:
    ensure => directory,
    owner  => 'root',
    group  => 'staff',
    mode   => '2755',
  }

  $dovecot_impersonate_archive = 'dovecot_impersonate-2.1.tar.gz'

  archive { $dovecot_impersonate_archive:
    path         => "/tmp/${dovecot_impersonate_archive}",
    source       => "puppet:///modules/profiles/roundcube/${dovecot_impersonate_archive}",
    extract      => true,
    extract_path => $roundcube_local_plugins,
    creates      => "${roundcube_local_plugins}/dovecot_impersonate-2.1",
    require      => File[$roundcube_local_plugins],
  }

  $twofactor_gauthenticator_archive = 'twofactor_gauthenticator-1.3.9-version.tar.gz'

  archive { $twofactor_gauthenticator_archive:
    path         => "/tmp/${twofactor_gauthenticator_archive}",
    source       => "puppet:///modules/profiles/roundcube/${twofactor_gauthenticator_archive}",
    extract      => true,
    extract_path => $roundcube_local_plugins,
    creates      => "${roundcube_local_plugins}/twofactor_gauthenticator-1.3.9-version",
    require      => File[$roundcube_local_plugins],
  }

  file { '/var/lib/roundcube/plugins/dovecot_impersonate':
    ensure  => link,
    owner   => 'root',
    group   => 'root',
    target  => "${roundcube_local_plugins}/dovecot_impersonate-2.1",
    require => Archive[$dovecot_impersonate_archive],
  }

  file { '/var/lib/roundcube/plugins/twofactor_gauthenticator':
    ensure  => link,
    owner   => 'root',
    group   => 'root',
    target  => "${roundcube_local_plugins}/twofactor_gauthenticator-1.3.9-version",
    require => Archive[$twofactor_gauthenticator_archive],
  }

  # These certificates should be removed when the switch to x509cert_common
  # has been applied
  file { '/etc/apache2/ssl':
    ensure => directory,
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }
  file { '/etc/apache2/ssl/certs':
    ensure  => directory,
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    require => File['/etc/apache2/ssl'],
  }
  file { '/etc/apache2/ssl/private':
    ensure  => directory,
    owner   => 'root',
    group   => 'root',
    mode    => '0750',
    require => File['/etc/apache2/ssl'],
  }

  $apache_ssl_cert = "/etc/apache2/ssl/certs/${external_name}.crt.pem"
  $apache_ssl_key = "/etc/apache2/ssl/private/${external_name}.key.pem"

  #file { $apache_ssl_cert:
  #  ensure  => file,
  #  owner   => 'root',
  #  group   => 'root',
  #  mode    => '0644',
  #  content => $server_certificate,
  #  require => File['/etc/apache2/ssl/certs'],
  #}
  #file { $apache_ssl_key:
  #  ensure  => file,
  #  owner   => 'root',
  #  group   => 'root',
  #  mode    => '0640',
  #  content => $server_private_key,
  #  require => File['/etc/apache2/ssl/private'],
  #}

  class { 'apache':
    default_vhost     => false,
    default_ssl_vhost => false,
    mpm_module        => 'prefork',
    server_signature  => 'Off',
  }
  class { 'apache::mod::php': }
  class { 'apache::mod::ssl':
    ssl_sessiontickets => false,
    stapling_cache     => 'shmcb:logs/ssl_stapling(32768)',
  }
  apache::vhost { "${external_name}-http":
    vhost_name        => '*',
    port              => 80,
    access_log        => true,
    access_log_format => 'combined',
    error_log         => true,
    log_level         => 'warn',
    serveradmin       => 'webmail-admin@cacert.org',
    docroot           => false,
    manage_docroot    => false,
    protocols         => ['h2c', 'http/1.1'],
    redirect_source   => ['/'],
    redirect_dest     => ["https://${external_name}/"],
    redirect_status   => ['permanent'],
  }
  apache::vhost { "${external_name}-https":
    vhost_name           => '*',
    servername           => $external_name,
    docroot              => '/var/lib/roundcube',
    port                 => 443,
    access_log           => true,
    access_log_format    => 'combined',
    error_log            => true,
    protocols            => ['h2', 'http/1.1'],
    serveradmin          => 'webmail-admin@cacert.org',
    serveraliases        => $additional_names,
    ssl                  => true,
    ssl_cert             => "/etc/ssl/public/${external_name}.chain.pem",
    ssl_key              => "/etc/ssl/private/${external_name}.key.pem",
    ssl_ca               => $cacert_cert_bundle,
    ssl_verify_client    => 'optional',
    ssl_verify_depth     => 2,
    ssl_options          => ['+StdEnvVars'],
    ssl_protocol         => 'all -SSLv3 -TLSv1 -TLSv1.1',
    ssl_cipher           => join([
      'ECDHE-ECDSA-AES128-GCM-SHA256',
      'ECDHE-RSA-AES128-GCM-SHA256',
      'ECDHE-ECDSA-AES256-GCM-SHA384',
      'ECDHE-RSA-AES256-GCM-SHA384',
      'ECDHE-ECDSA-CHACHA20-POLY1305',
      'ECDHE-RSA-CHACHA20-POLY1305',
      'DHE-RSA-AES128-GCM-SHA256',
      'DHE-RSA-AES256-GCM-SHA384',
    ], ':'),
    ssl_honorcipherorder => 'on',
    ssl_stapling         => true,
    directories          => [
      {
        path    => '/var/lib/roundcube',
        options => ['Indexes', 'FollowSymLinks']
      },
    ],
    redirect_source      => ['/password.php', '/staff.php'],
    redirect_dest        => [
      'https://selfservice.cacert.org/password-reset', 'https://selfservice.cacert.org/staff'],
    redirect_status      => ['permanent', 'permanent'],
    # rewrites can be removed when DNS is changed
    rewrites             => [
      {
        rewrite_cond => ['%{REQUEST_URI} ^/board/motions.php', '%{QUERY_STRING} motion=(.*)$'],
        rewrite_rule => ['^/board/motions.php https://motion.cacert.org/motions/%1? [L,R=permanent]'],
      },
      { rewrite_rule => ['^/board/motions.php https://motion.cacert.org/motions/? [L,R=permanent]'] },
      { rewrite_rule => ['^/board/vote.php https://motion.cacert.org/vote/? [L,R=permanent]'] },
      { rewrite_rule => ['^/board/proxy.php https://motion.cacert.org/proxy/? [L,R=permanent]'] },
      { rewrite_rule => ['^/board https://motion.cacert.org/? [L,R=permanent]'] },
    ],
  }
}