Retire the apache_ratelimited role
[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   # running jugdo against snapshot
30   #  159.226.95.0/24
31   #  84.204.194.0/24
32   #  211.13.205.0/24
33   # 20190512 tens of thousands of queries
34   #  63.32.0.0/14
35   #  54.72.0.0/15
36   #  95.115.66.23
37   #  52.192.0.0/11
38   #  54.72.0.0/15
39   #  34.192.0.0/10
40   #  34.240.0.0/13
41   #  52.192.0.0/11
42   #  90.44.107.223
43   #  195.154.173.12
44   #  74.121.137.108
45   ferm::rule { 'dsa-snapshot-abusers':
46     prio => '005',
47     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 63.32.0.0/14 54.72.0.0/15 95.115.66.23 52.192.0.0/11 54.72.0.0/15 34.192.0.0/10 34.240.0.0/13 52.192.0.0/11 90.44.107.223 195.154.173.12 74.121.137.108) DROP',
48   }
49
50   # rate limit accesses.  The chain is set up by the apache module and allow happens at prio 90.
51   ferm::rule { 'dsa-http-snapshot-limit':
52     prio        => '22',
53     description => 'rate limit for snapshot',
54     chain       => 'http',
55     domain      => '(ip ip6)',
56     rule        => '
57         mod hashlimit hashlimit-name HTTPDOSPRE hashlimit-mode srcip hashlimit-burst 10 hashlimit 6/minute jump ACCEPT;
58         mod recent name HTTPDOS update seconds 900 jump log_or_drop;
59         mod hashlimit hashlimit-name HTTPDOS hashlimit-mode srcip hashlimit-burst 200 hashlimit 30/minute jump ACCEPT;
60         mod recent name HTTPDOS set jump log_or_drop'
61   }
62
63   ensure_packages ( [
64     'libapache2-mod-wsgi',
65     ], {
66     ensure => 'installed',
67   })
68
69   apache2::site { '020-snapshot.debian.org':
70     site    => 'snapshot.debian.org',
71     content => template('roles/snapshot/snapshot.debian.org.conf.erb')
72   }
73
74   case $::hostname {
75     'lw07': {
76       $ipv4addr        = '185.17.185.185'
77       $ipv6addr        = '2001:1af8:4020:b030:deb::185'
78       $ipv6addr_apache = '2001:1af8:4020:b030:deb::187'
79     }
80     'sallinen': {
81       $ipv4addr        = '193.62.202.27'
82       $ipv6addr        = '2001:630:206:4000:1a1a:0:c13e:ca1b'
83       $ipv6addr_apache = '2001:630:206:4000:1a1a:0:c13e:ca1a'
84     }
85     default: {
86       fail ( "unknown host ${::hostname} for snapshot_web." )
87     }
88   }
89
90   ferm::rule { 'dsa-snapshot-connlimit':
91     domain => '(ip ip6)',
92     prio   => '005',
93     rule   => "proto tcp mod state state (NEW) interface ! lo daddr (${ipv4addr} ${ipv6addr})  mod multiport destination-ports (80 443) mod connlimit connlimit-above 3 DROP;
94                proto tcp mod state state (NEW) interface ! lo                                                dport 6081                 mod connlimit connlimit-above 3 DROP
95                ",
96   }
97
98   # varnish cache
99   ###############
100   ferm::rule { 'dsa-nat-snapshot-varnish-v4':
101     table => 'nat',
102     chain => 'PREROUTING',
103     rule  => "proto tcp daddr ${ipv4addr} dport 80 REDIRECT to-ports 6081",
104   }
105
106   varnish::config { 'default':
107     listen  => [
108       ':6081',
109       "[${ipv6addr}]:80"
110       ],
111     backend => 'file,/var/lib/varnish/varnish_storage.bin,8G',
112     content => template('roles/snapshot/snapshot.debian.org.vcl.erb'),
113   }
114
115   # the ipv6 port 80 is owned by varnish
116   file { '/etc/apache2/ports.conf':
117     content => @("EOF"),
118       Listen 0.0.0.0:80
119       Listen [${ipv6addr_apache}]:80
120       | EOF
121     require => Package['apache2'],
122     notify  => Service['apache2'],
123   }
124
125   # haproxy ssl termination
126   #########################
127   include haproxy
128   file { '/etc/haproxy/haproxy.cfg':
129     content => template('roles/snapshot/haproxy.cfg.erb'),
130     require => Package['haproxy'],
131     notify  => Service['haproxy'],
132   }
133   ssl::service { 'snapshot.debian.org':
134     notify => Service['haproxy'],
135     key    => true,
136   }
137 }