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