summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/debarchive.pp
blob: ed9deaf1e6fdb3d95692aee346aa9c4bf7dee129 (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
# Class: profiles::debarchive
# ===========================
#
# This class defines a Debian package archive setup.
#
# Parameters
# ----------
#
# @param notification_email_address email address that will receive reports
#                                   from mini-dinstall
#
# @param release_signing_key        data of a GPG key that is used for
#                                   release file signing
#
# @param release_signing_keygrip    GPG keygrip of the release signing key
#
# @param release_signing_keyid      GPG key id of the release signing key
#
# @param uploaders                  a list of users that are allowed to dput
#                                   files to the Debian archive
#
# Examples
# --------
#
# @example
#   class 'roles::myhost' {
#     include profiles::debarchive
#   }
#
# Authors
# -------
#
# Jan Dittberner <jandd@cacert.org>
#
# Copyright
# ---------
#
# Copyright 2019 Jan Dittberner
#
class profiles::debarchive (
  String $notification_email_address,
  String $release_signing_key,
  String $release_signing_keygrip,
  String $release_signing_keyid,
  Array[String] $uploaders = [],
) {
  $debarchive_home = '/srv/debarchive'
  $gpg_home = "${debarchive_home}/.gnupg"
  $package_dir = "${debarchive_home}/packages"
  $trusted_keyring = "${debarchive_home}/cacert-keyring.gpg"
  $archive_public_key = "${package_dir}/cacert-debian-archive-2019.gpg"
  $release_signing_private_key_file = "${gpg_home}/private-keys-v1.d/${release_signing_keygrip}.key"

  $upload_chroot = '/srv/upload'
  $incoming_dir = "${upload_chroot}/incoming"
  $inoticoming_service = '/etc/systemd/system/debarchive-inoticoming.service'

  include profiles::base

  package{ ['rssh', 'reprepro', 'inoticoming']:
    ensure => latest,
  } ->
  file { 'ensure that suid bit on rssh_chroot_helper is set':
    path   => '/usr/lib/rssh/rssh_chroot_helper',
    ensure => present,
    owner  => 'root',
    group  => 'root',
    mode   => '4755',
  }
  exec { 'add rssh to list of valid shells':
    command => '/usr/sbin/add-shell /usr/bin/rssh',
    unless  => '/bin/grep -q rss /etc/shells',
    require => Package['rssh'],
  }

  # setup user, groups and directories
  group { 'debarchive':
    ensure => absent,
  }
  user { 'debarchive':
    ensure         => present,
    comment        => 'CAcert debian archive user',
    system         => true,
    gid            => 'nogroup',
    home           => $debarchive_home,
    shell          => '/usr/bin/rssh',
    purge_ssh_keys => true,
    require        => Package['rssh'],
  }
  file { $debarchive_home:
    ensure => directory,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0711',
  }
  file { $upload_chroot:
    ensure => directory,
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }
  file { $incoming_dir:
    ensure => directory,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0700',
  }
  exec { "/bin/bash /usr/share/doc/rssh/examples/mkchroot.sh ${upload_chroot}":
    creates => "${upload_chroot}/usr/bin/rssh",
    require => [Package['rssh'], File[$upload_chroot]],
  } ~>
  exec { "/bin/sed -n -i '/^root:/p; /^debarchive:/p' ${upload_chroot}/etc/passwd":
    refreshonly => true,
  }

  $rssh_conf = '/etc/rssh.conf'

  concat { $rssh_conf:
    ensure => present,
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }

  concat::fragment { 'rssh-global':
    target => $rssh_conf,
    order  => '01',
    source => 'puppet:///modules/profiles/debarchive/rssh.global.conf',
  }

  concat::fragment { 'rssh-debarchive':
    target  => $rssh_conf,
    order   => '10',
    content => "user = \"debarchive:022:000110:${upload_chroot}\"\n",
  }

  # setup ssh keys
  $uploaders.each |String $username| {
    $ssh_keys = $::profiles::base::users[$username]['ssh_keys']
    $ssh_keys.each |Hash[String, Data] $keydata| {
      $keyname = $keydata['name']
      ssh_authorized_key { "debarchive-${username}-${keyname}":
        ensure  => present,
        user    => 'debarchive',
        type    => $keydata['type'],
        key     => $keydata['key'],
        require => User['debarchive'],
      }
    }
  }

  file { $trusted_keyring:
    ensure => file,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0600',
    source => 'puppet:///modules/profiles/debarchive/cacert-keyring.gpg',
  }

  # setup GPG home for signing
  file { [$gpg_home, "${gpg_home}/private-keys-v1.d", "${debarchive_home}/log"]:
    ensure => directory,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0700',
  }
  file { $release_signing_private_key_file:
    ensure  => file,
    owner   => 'debarchive',
    group   => 'nogroup',
    mode    => '0600',
    content => $release_signing_key,
  }
  file { "${gpg_home}/gpg-agent.conf":
    ensure  => file,
    owner   => 'debarchive',
    group   => 'nogroup',
    mode    => '0600',
    content => "log-file ${debarchive_home}/log/gpg-agent.log",
  }
  file { "${gpg_home}/gpg.conf":
    ensure  => file,
    owner   => 'debarchive',
    group   => 'nogroup',
    mode    => '0600',
    content => "keyring ${trusted_keyring}\n",
  }
  file { "${gpg_home}/pubring.kbx":
    ensure => file,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0600',
    source => 'puppet:///modules/profiles/debarchive/gpg_pubring.kbx',
  }
  file { "${gpg_home}/trustdb.gpg":
    ensure => file,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0600',
    source => 'puppet:///modules/profiles/debarchive/gpg_trustdb.gpg',
  }
  exec { "export archive signing key":
    command => "/usr/bin/gpg --export --export-options export-minimal \"${release_signing_keyid}\" > ${archive_public_key}",
    creates => $archive_public_key,
    require => [
      File[$package_dir],
      File["${gpg_home}/gpg.conf"],
      File["${gpg_home}/gpg-agent.conf"],
      File[$release_signing_private_key_file],
      File["${gpg_home}/pubring.kbx"],
      File["${gpg_home}/trustdb.gpg"],
    ],
  }

  # setup reprepro
  file { $package_dir:
    ensure => directory,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0755',
  }
  file { "${package_dir}/conf":
    ensure => directory,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0700',
  }

  concat { "${package_dir}/conf/distributions":
    ensure  => present,
    owner   => 'debarchive',
    group   => 'nogroup',
    mode    => '0600',
  }

  concat::fragment { 'stretch-distribution':
    target  => "${package_dir}/conf/distributions",
    content => join([
      'Origin: CAcert Infrastructure Team',
      'Codename: stretch-cacert',
      'Architectures: amd64 source',
      'Components: main',
      'SignWith: yes',
      'DebIndices: Packages Release . .gz .xz',
      'Uploaders: uploaders',
      "Log: ${debarchive_home}/log/stretch-cacert-updates.log",
      '',
      ''], "\n"),
  }

  concat::fragment { 'buster-distribution':
    target  => "${package_dir}/conf/distributions",
    content => join([
      'Origin: CAcert Infrastructure Team',
      'Codename: buster-cacert',
      'Architectures: amd64 source',
      'Components: main',
      'SignWith: yes',
      'DebIndices: Packages Release . .gz .xz',
      'Uploaders: uploaders',
      "Log: ${debarchive_home}/log/buster-cacert-updates.log",
      '',
      ''], "\n"),
  }

  file { "${package_dir}/conf/incoming":
    ensure => file,
    owner  => 'debarchive',
    group  => 'nogroup',
    mode   => '0600',
    source => 'puppet:///modules/profiles/debarchive/reprepro_conf_incoming',
  }

  file { "${package_dir}/conf/uploaders":
    ensure  => file,
    owner   => 'debarchive',
    group   => 'nogroup',
    mode    => '0600',
    content => "allow * by any key\n",
  }

  file { $inoticoming_service:
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    source  => 'puppet:///modules/profiles/debarchive/inoticoming.service',
    require => [
      Package['inoticoming'],
      Concat["${package_dir}/conf/distributions"],
      File["${package_dir}/conf/incoming"],
      File["${package_dir}/conf/uploaders"],
      File[$trusted_keyring],
      User['debarchive'],
    ],
  } ~>
  exec { 'reload systemd configuration after changes to service file':
    command     => '/bin/systemctl daemon-reload',
    refreshonly => true,
  }

  service { 'debarchive-inoticoming':
    ensure  => running,
    enable  => true,
    require => File[$inoticoming_service],
  }
}