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