snapshot-web: remove AWS block
[mirror/dsa-puppet.git] / modules / roles / manifests / snapshot_web.pp
1 # web service for snapshot.debian.org
2 #
3 class roles::snapshot_web {
4   include roles::snapshot_secondary
5
6   include apache2
7   include apache2::rewrite
8
9   # snapshot abusers
10   #  61.69.254.110 - 20180705, mirroring with wget
11   # 20180821 large amount of requests way too fast from some amazon AWS instances
12   #  18.185.157.46
13   #  18.194.174.202
14   #  18.184.181.169
15   #  18.184.5.230
16   #  18.194.137.96
17   #  18.197.147.183
18   #  3.120.39.137
19   #  3.120.41.69
20   #  35.158.129.130
21   #  52.59.199.25
22   #  52.59.228.158
23   #  52.59.245.42
24   #  52.59.253.41
25   #  52.59.71.13
26   # 20180821 mirroring
27   #  99.137.191.34
28   # 20181110 crawler
29   #  51.15.215.91
30   # 20181222, excessive number of requests
31   #  208.91.68.213
32   # 198.11.128.0/18
33   # running jigdo against snapshot
34   #  159.226.95.0/24
35   #  84.204.194.0/24
36   #  211.13.205.0/24
37   # 20190512 tens of thousands of queries
38   #  63.32.0.0/14
39   #  54.72.0.0/15
40   #  95.115.66.23
41   #  52.192.0.0/11
42   #  54.72.0.0/15
43   #  34.192.0.0/10
44   #  34.240.0.0/13
45   #  52.192.0.0/11
46   #  90.44.107.223
47   #  195.154.173.12
48   #  74.121.137.108
49   ferm::rule { 'dsa-snapshot-abusers':
50     prio => '005',
51     rule => 'saddr (61.69.254.110 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 95.115.66.23 90.44.107.223 195.154.173.12 74.121.137.108) DROP',
52   }
53
54   # rate limit accesses.  The chain is set up by the apache module and allow happens at prio 90.
55   ferm::rule { 'dsa-http-snapshot-limit':
56     prio        => '22',
57     description => 'rate limit for snapshot',
58     chain       => 'http',
59     domain      => '(ip ip6)',
60     rule        => '
61         mod hashlimit hashlimit-name HTTPDOSPRE hashlimit-mode srcip hashlimit-burst 10 hashlimit 6/minute jump ACCEPT;
62         mod recent name HTTPDOS update seconds 900 jump log_or_drop;
63         mod hashlimit hashlimit-name HTTPDOS hashlimit-mode srcip hashlimit-burst 200 hashlimit 30/minute jump ACCEPT;
64         mod recent name HTTPDOS set jump log_or_drop'
65   }
66
67   ensure_packages ( [
68     'libapache2-mod-wsgi',
69     ], {
70     ensure => 'installed',
71   })
72
73   apache2::site { '020-snapshot.debian.org':
74     site    => 'snapshot.debian.org',
75     content => template('roles/snapshot/snapshot.debian.org.conf.erb')
76   }
77
78   case $::hostname {
79     'lw07': {
80       $ipv4addr        = '185.17.185.185'
81       $ipv6addr        = '2001:1af8:4020:b030:deb::185'
82       $ipv6addr_apache = '2001:1af8:4020:b030:deb::187'
83     }
84     'sallinen': {
85       $ipv4addr        = '193.62.202.27'
86       $ipv6addr        = '2001:630:206:4000:1a1a:0:c13e:ca1b'
87       $ipv6addr_apache = '2001:630:206:4000:1a1a:0:c13e:ca1a'
88     }
89     default: {
90       fail ( "unknown host ${::hostname} for snapshot_web." )
91     }
92   }
93
94   ferm::rule { 'dsa-snapshot-connlimit':
95     domain => '(ip ip6)',
96     prio   => '005',
97     rule   => "proto tcp mod state state (NEW) interface ! lo daddr (${ipv4addr} ${ipv6addr})  mod multiport destination-ports (80 443) mod connlimit connlimit-above 3 DROP;
98                proto tcp mod state state (NEW) interface ! lo                                                dport 6081                 mod connlimit connlimit-above 3 DROP
99                ",
100   }
101
102   # varnish cache
103   ###############
104   ferm::rule { 'dsa-nat-snapshot-varnish-v4':
105     table => 'nat',
106     chain => 'PREROUTING',
107     rule  => "proto tcp daddr ${ipv4addr} dport 80 REDIRECT to-ports 6081",
108   }
109
110   varnish::config { 'default':
111     listen  => [
112       ':6081',
113       "[${ipv6addr}]:80"
114       ],
115     backend => 'file,/var/lib/varnish/varnish_storage.bin,8G',
116     content => template('roles/snapshot/snapshot.debian.org.vcl.erb'),
117   }
118
119   # the ipv6 port 80 is owned by varnish
120   file { '/etc/apache2/ports.conf':
121     content => @("EOF"),
122       Listen 0.0.0.0:80
123       Listen [${ipv6addr_apache}]:80
124       | EOF
125     require => Package['apache2'],
126     notify  => Service['apache2'],
127   }
128
129   # haproxy ssl termination
130   #########################
131   include haproxy
132   file { '/etc/haproxy/haproxy.cfg':
133     content => template('roles/snapshot/haproxy.cfg.erb'),
134     require => Package['haproxy'],
135     notify  => Service['haproxy'],
136   }
137   ssl::service { 'snapshot.debian.org':
138     notify => Service['haproxy'],
139     key    => true,
140   }
141 }