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