Also make setting timezone work on debian 9 (stretch)
[mirror/dsa-puppet.git] / modules / debian_org / manifests / init.pp
1 # == Class: debian_org
2 #
3 # Stuff common to all debian.org servers
4 #
5 class debian_org {
6         include debian_org::apt
7
8         if $systemd {
9                 include systemd
10                 $servicefiles = 'present'
11         } else {
12                 $servicefiles = 'absent'
13         }
14
15         # the virtual facter needs virt-what on jessie to work
16         if versioncmp($::lsbmajdistrelease, '9') < 0 {
17                 package { 'virt-what': ensure => installed }
18         } else {
19                 package { 'virt-what': ensure => purged }
20         }
21
22         $samhain_recipients = hiera('samhain_recipients')
23         $root_mail_alias = hiera('root_mail_alias')
24
25         package { [
26                         'klogd',
27                         'sysklogd',
28                         'rsyslog',
29                         'os-prober',
30                         'apt-listchanges',
31                         'mlocate',
32                 ]:
33                 ensure => purged,
34         }
35         package { [
36                         'debian.org',
37                         'debian.org-recommended',
38                         'dsa-munin-plugins',
39                         'userdir-ldap',
40                 ]:
41                 ensure => installed,
42                 tag    => extra_repo,
43         }
44
45         package { [
46                         'apt-utils',
47                         'bash-completion',
48                         'dnsutils',
49                         'less',
50                         'lsb-release',
51                         'ruby-filesystem',
52                         'mtr-tiny',
53                         'nload',
54                         'pciutils',
55                         'lldpd',
56                 ]:
57                 ensure => installed,
58         }
59
60         munin::check { [
61                         'cpu',
62                         'entropy',
63                         'forks',
64                         'interrupts',
65                         'iostat',
66                         'irqstats',
67                         'load',
68                         'memory',
69                         'open_files',
70                         'open_inodes',
71                         'processes',
72                         'swap',
73                         'uptime',
74                         'vmstat',
75                 ]:
76         }
77
78         if getfromhash($site::nodeinfo, 'broken-rtc') {
79                 package { 'fake-hwclock':
80                         ensure => installed,
81                         tag    => extra_repo,
82                 }
83         }
84
85         package { 'molly-guard':
86                 ensure => installed,
87         }
88         file { '/etc/molly-guard/run.d/10-check-kvm':
89                 mode    => '0755',
90                 source  => 'puppet:///modules/debian_org/molly-guard/10-check-kvm',
91                 require => Package['molly-guard'],
92         }
93         file { '/etc/molly-guard/run.d/15-acquire-reboot-lock':
94                 mode    => '0755',
95                 source  => 'puppet:///modules/debian_org/molly-guard/15-acquire-reboot-lock',
96                 require => Package['molly-guard'],
97         }
98
99         augeas { 'inittab_replicate':
100                 context => '/files/etc/inittab',
101                 changes => [
102                         'set ud/runlevels 2345',
103                         'set ud/action respawn',
104                         'set ud/process "/usr/bin/ud-replicated -d"',
105                 ],
106                 notify  => Exec['init q'],
107         }
108
109
110         file { '/etc/facter':
111                 ensure  => directory,
112                 purge   => true,
113                 force   => true,
114                 recurse => true,
115                 source  => 'puppet:///files/empty/',
116         }
117         file { '/etc/facter/facts.d':
118                 ensure => directory,
119         }
120         file { '/etc/facter/facts.d/debian_facts.yaml':
121                 content => template('debian_org/debian_facts.yaml.erb')
122         }
123         file { '/etc/timezone':
124                 content => "Etc/UTC\n",
125                 notify => Exec['dpkg-reconfigure tzdata -pcritical -fnoninteractive'],
126         }
127         if versioncmp($::lsbmajdistrelease, '9') >= 0 { # jessie has a regular file there, for instance
128                 file { '/etc/localtime':
129                         ensure => 'link',
130                         target => '/usr/share/zoneinfo/Etc/UTC',
131                         notify => Exec['dpkg-reconfigure tzdata -pcritical -fnoninteractive'],
132                 }
133         }
134         if $::hostname == handel {
135                 include puppetmaster::db
136                 $dbpassword = $puppetmaster::db::password
137         }
138         file { '/etc/puppet/puppet.conf':
139                 content => template('debian_org/puppet.conf.erb'),
140                 mode => '0440',
141                 group => 'puppet',
142         }
143         file { '/etc/default/puppet':
144                 source => 'puppet:///modules/debian_org/puppet.default',
145         }
146         file { '/etc/systemd':
147                 ensure  => directory,
148                 mode => '0755',
149         }
150         file { '/etc/systemd/system':
151                 ensure  => directory,
152                 mode => '0755',
153         }
154         file { '/etc/systemd/system/ud-replicated.service':
155                 ensure => $servicefiles,
156                 source => 'puppet:///modules/debian_org/ud-replicated.service',
157                 notify => Exec['systemctl daemon-reload'],
158         }
159         if $systemd {
160                 file { '/etc/systemd/system/multi-user.target.wants/ud-replicated.service':
161                         ensure => 'link',
162                         target => '../ud-replicated.service',
163                         notify => Exec['systemctl daemon-reload'],
164                 }
165         }
166         file { '/etc/systemd/system/puppet.service':
167                 ensure => 'link',
168                 target => '/dev/null',
169                 notify => Exec['systemctl daemon-reload'],
170         }
171         file { '/etc/systemd/system/proc-sys-fs-binfmt_misc.automount':
172                 ensure => 'link',
173                 target => '/dev/null',
174                 notify => Exec['systemctl daemon-reload'],
175         }
176
177         concat { '/etc/cron.d/dsa-puppet-stuff': }
178         concat::fragment { 'dsa-puppet-stuff---header':
179                 target => '/etc/cron.d/dsa-puppet-stuff',
180                 order  => '000',
181                 content  => @(EOF)
182                         ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
183                         SHELL=/bin/bash
184                         MAILTO=root
185                         PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/nagios/plugins
186                         | EOF
187         }
188         concat::fragment { 'dsa-puppet-stuff---all':
189                 target => '/etc/cron.d/dsa-puppet-stuff',
190                 order  => '010',
191                 content => template('debian_org/dsa-puppet-stuff.cron.erb'),
192                 require => Package['debian.org'],
193         }
194         file { '/etc/ldap/ldap.conf':
195                 require => Package['debian.org'],
196                 content  => template('debian_org/ldap.conf.erb'),
197         }
198         file { '/etc/pam.d/common-session':
199                 require => Package['debian.org'],
200                 content => template('debian_org/pam.common-session.erb'),
201         }
202         file { '/etc/pam.d/common-session-noninteractive':
203                 require => Package['debian.org'],
204                 content => template('debian_org/pam.common-session-noninteractive.erb'),
205         }
206         file { '/etc/rc.local':
207                 mode   => '0755',
208                 content => template('debian_org/rc.local.erb'),
209                 notify => Exec['service rc.local restart'],
210         }
211         file { '/etc/dsa':
212                 ensure => directory,
213                 mode   => '0755',
214         }
215         file { '/etc/dsa/cron.ignore.dsa-puppet-stuff':
216                 source  => 'puppet:///modules/debian_org/dsa-puppet-stuff.cron.ignore',
217                 require => Package['debian.org']
218         }
219         file { '/etc/nsswitch.conf':
220                 mode   => '0755',
221                 source => 'puppet:///modules/debian_org/nsswitch.conf',
222         }
223
224         file { '/etc/profile.d/timeout.sh':
225                 mode   => '0555',
226                 source => 'puppet:///modules/debian_org/etc.profile.d/timeout.sh',
227         }
228         file { '/etc/zsh':
229                 ensure => directory,
230         }
231         file { '/etc/zsh/zprofile':
232                 mode   => '0444',
233                 source => 'puppet:///modules/debian_org/etc.zsh/zprofile',
234         }
235         file { '/etc/environment':
236                 content => "",
237                 mode => '0440',
238         }
239         file { '/etc/default/locale':
240                 content => "",
241                 mode => '0444',
242         }
243
244         # set mmap_min_addr to 4096 to mitigate
245         # Linux NULL-pointer dereference exploits
246         site::sysctl { 'mmap_min_addr':
247                 ensure => absent
248         }
249         site::sysctl { 'perf_event_paranoid':
250                 key   => 'kernel.perf_event_paranoid',
251                 value => '2',
252         }
253         site::sysctl { 'puppet-vfs_cache_pressure':
254                 key   => 'vm.vfs_cache_pressure',
255                 value => '10',
256         }
257         site::alternative { 'editor':
258                 linkto => '/usr/bin/vim.basic',
259         }
260         site::alternative { 'view':
261                 linkto => '/usr/bin/vim.basic',
262         }
263         mailalias { 'samhain-reports':
264                 ensure    => present,
265                 recipient => $samhain_recipients,
266                 require   => Package['debian.org']
267         }
268         mailalias { 'root':
269                 ensure    => present,
270                 recipient => $root_mail_alias,
271                 require   => Package['debian.org']
272         }
273
274         file { '/usr/local/bin/check_for_updates':
275                 source => 'puppet:///modules/debian_org/check_for_updates',
276                 mode   => '0755',
277                 owner  => root,
278                 group  => root,
279         }
280         file { '/usr/local/bin/dsa-is-shutdown-scheduled':
281                 source  => 'puppet:///modules/debian_org/dsa-is-shutdown-scheduled',
282                 mode    => '0555',
283         }
284
285         exec { 'dpkg-reconfigure tzdata -pcritical -fnoninteractive':
286                 path        => '/usr/bin:/usr/sbin:/bin:/sbin',
287                 refreshonly => true
288         }
289         exec { 'service puppetmaster restart':
290                 refreshonly => true
291         }
292         exec { 'service rc.local restart':
293                 refreshonly => true
294         }
295         exec { 'init q':
296                 refreshonly => true
297         }
298
299         exec { 'systemctl daemon-reload':
300                 refreshonly => true,
301                 onlyif  => "test -x /bin/systemctl"
302         }
303
304         exec { 'systemd-tmpfiles --create --exclude-prefix=/dev':
305                 refreshonly => true,
306                 onlyif  => "test -x /bin/systemd-tmpfiles"
307         }
308
309         tidy { '/var/lib/puppet/clientbucket/':
310                 age      => '2w',
311                 recurse  => 9,
312                 type     => ctime,
313                 matches  => [ 'paths', 'contents' ],
314                 schedule => weekly
315         }
316
317         file { '/root/.bashrc':
318                 source => 'puppet:///modules/debian_org/root-dotfiles/bashrc',
319         }
320         file { '/root/.profile':
321                 source => 'puppet:///modules/debian_org/root-dotfiles/profile',
322         }
323         file { '/root/.selected_editor':
324                 source => 'puppet:///modules/debian_org/root-dotfiles/selected_editor',
325         }
326         file { '/root/.screenrc':
327                 source => 'puppet:///modules/debian_org/root-dotfiles/screenrc',
328         }
329         file { '/root/.tmux.conf':
330                 source => 'puppet:///modules/debian_org/root-dotfiles/tmux.conf',
331         }
332         file { '/root/.vimrc':
333                 source => 'puppet:///modules/debian_org/root-dotfiles/vimrc',
334         }
335
336         if versioncmp($::lsbmajdistrelease, '9') >= 0 { # older puppets do facts as strings.
337                 if $::processorcount > 1 {
338                         package { 'irqbalance': ensure => installed }
339                 }
340         }
341
342
343         # https://www.decadent.org.uk/ben/blog/bpf-security-issues-in-debian.html
344         site::sysctl { 'unprivileged_bpf_disabled':
345                 key   => 'kernel.unprivileged_bpf_disabled',
346                 value => '1',
347         }
348
349         # Disable kpartx udev rules
350         file { '/etc/udev/rules.d/60-kpartx.rules':
351                 ensure => $has_lib_udev_rules_d_60_kpartx_rules ? { true  => 'present', default => 'absent' },
352                 content => "",
353                 mode => '0444',
354         }
355
356         # this is only to avoid warnings, else puppet will complain that we
357         # have a symlink there, even if we're not replacing it anyhow.
358         if ! $has_etc_ssh_ssh_known_hosts {
359                 file { '/etc/ssh/ssh_known_hosts':
360                         ensure  => 'present',
361                         replace => 'no',
362                         content => inline_template('<%= open("/etc/ssh/ssh_known_hosts").read() %>'),
363                         notify  => Exec['ud-replicate'],
364                 }
365         }
366
367         exec { 'ud-replicate':
368                 path => '/usr/bin:/usr/sbin:/bin:/sbin',
369                 command => '/usr/bin/ud-replicate',
370                 refreshonly => true,
371                 require => Package['userdir-ldap']
372         }
373 }