37e17114760604d944fa4f9b1febedb5fbca943e
[mirror/dsa-puppet.git] / modules / roles / manifests / snapshot_web.pp
1 class roles::snapshot_web {
2         include apache2
3         include apache2::headers
4         include apache2::rewrite
5
6         # snapshot abusers
7         #  61.69.254.110 - 20180705, mirroring with wget
8         # 20180821 large amount of requests way too fast from some amazon AWS instances
9         #  18.185.157.46
10         #  18.194.174.202
11         #  18.184.181.169
12         #  18.184.5.230
13         #  18.194.137.96
14         #  18.197.147.183
15         #  3.120.39.137
16         #  3.120.41.69
17         #  35.158.129.130
18         #  52.59.199.25
19         #  52.59.228.158
20         #  52.59.245.42
21         #  52.59.253.41
22         #  52.59.71.13
23         # 20180821 mirroring
24         #  99.137.191.34
25         # 20181110 crawler
26         #  51.15.215.91
27         # 20181222, excessive number of requests
28         #  208.91.68.213
29         # 198.11.128.0/18
30         # running jugdo against snapshot
31         #  159.226.95.0/24
32         #  84.204.194.0/24
33         #  211.13.205.0/24
34         @ferm::rule { 'dsa-snapshot-abusers':
35                 prio  => "005",
36                 rule  => "saddr (61.69.254.110 18.128.0.0/9 3.120.0.0/14 35.156.0.0/14 52.58.0.0/15 99.137.191.34 51.15.215.91 208.91.68.213 198.11.128.0/18 159.226.95.0/24 84.204.194.0/24 211.13.205.0/24) DROP",
37         }
38
39         ensure_packages ( [
40                 "libapache2-mod-wsgi",
41                 ], {
42                 ensure => 'installed',
43         })
44
45         apache2::site { '020-snapshot.debian.org':
46                 site   => 'snapshot.debian.org',
47                 content => template('roles/snapshot/snapshot.debian.org.conf.erb')
48         }
49
50         case $::hostname {
51                 'lw07': {
52                         $ipv4addr        = '185.17.185.185'
53                         $ipv6addr        = '2001:1af8:4020:b030:deb::185'
54                         $ipv6addr_apache = '2001:1af8:4020:b030:deb::187'
55                 }
56                 'sallinen': {
57                         $ipv4addr        = '193.62.202.27'
58                         $ipv6addr        = '2001:630:206:4000:1a1a:0:c13e:ca1b'
59                         $ipv6addr_apache = '2001:630:206:4000:1a1a:0:c13e:ca1a'
60                 }
61                 default: {
62                         fail ( "unknown host $::hostname for snapshot_web." )
63                 }
64         }
65
66         @ferm::rule { 'dsa-snapshot-connlimit':
67                 domain => '(ip ip6)',
68                 prio  => "005",
69                 rule  => "proto tcp mod state state (NEW) interface ! lo daddr (${ipv4addr} ${ipv6addr})  mod multiport destination-ports (80 443) mod connlimit connlimit-above 3 DROP;
70                           proto tcp mod state state (NEW) interface ! lo                                                dport 6081                 mod connlimit connlimit-above 3 DROP
71                            ",
72         }
73
74         # varnish cache
75         ###############
76         @ferm::rule { 'dsa-nat-snapshot-varnish-v4':
77                 table => 'nat',
78                 chain => 'PREROUTING',
79                 rule  => "proto tcp daddr ${ipv4addr} dport 80 REDIRECT to-ports 6081",
80         }
81
82         varnish::config { 'default':
83                 listen  => [
84                         ':6081',
85                         "[$ipv6addr]:80"
86                         ],
87                 backend => 'file,/var/lib/varnish/varnish_storage.bin,8G',
88                 content => template('roles/snapshot/snapshot.debian.org.vcl.erb'),
89         }
90
91         # the ipv6 port 80 is owned by varnish
92         file { '/etc/apache2/ports.conf':
93                 content  => @("EOF"),
94                         Listen 0.0.0.0:80
95                         Listen [$ipv6addr_apache]:80
96                         | EOF
97                 require => Package['apache2'],
98                 notify  => Service['apache2'],
99         }
100
101         # haproxy ssl termination
102         #########################
103         include haproxy
104         file { '/etc/haproxy/haproxy.cfg':
105                 content => template('roles/snapshot/haproxy.cfg.erb'),
106                 require => Package['haproxy'],
107                 notify  => Service['haproxy'],
108         }
109         ssl::service { 'snapshot.debian.org':
110                 notify  => Service['haproxy'],
111                 key => true,
112         }
113 }