The App Engine Denial of Service (DoS) Protection Service enables you to protect your application from running out of quota when subjected to denial of service attacks or similar forms of abuse. You can blacklist IP addresses or subnets, and requests routed from those addresses or subnets will be dropped before your application code is called. No resource allocations, billed or otherwise, are consumed for these requests.
By default, App Engine serves a generic error page to blacklisted addresses. You can configure your app to serve a custom response instead.Before you begin
Create a dos.yaml file in the root directory of your
application. You will specify your blacklisted IP addresses and networks in this
file.
Defining blacklists of IP addresses for your App Engine app
To specify a single IP address should be blocked from you can add an IP address in either IPv4 or IPv6 format:
blacklist:
- subnet: 192.0.2.1
description: A single IPv4 address
- subnet: abcd::123:4567
description: A single IPv6 address
In a distributed denial of service (DDoS) attack, you will likely need to block entire subnets rather than by individual IP address.
After creating your dos.yaml, you must upload it to your app.
Defining blacklists of IP subnets for your App Engine app
The dos.yaml is limited to 100 entries, so blocking entire subnets
might be necessary if you are facing a DDoS attack. This is also an efficient
way to protect yourself if you find that multiple IP addresses from the same
network are part of a DoS attack on your app.
The IP subnets are specified in CIDR format. The IP to CIDR tool can help you define your CIDR notation for ranges of IP addresses.
blacklist:
- subnet: 1.2.3.4/24
description: an IPv4 subnet
- subnet: abcd::123:4567/48
description: an IPv6 subnet
After creating your dos.yaml, you must upload it to your app.
Creating custom error messages for blacklisted requests
By default, a generic error page is served to requests that are blocked by the DoS protection service. Distributed denial of service attacks could involve an infected machine from a legitimate user and this page could provide explanation for why their access was denied.
-
Create a static file in your application directory for serving to requests that are blocked by the DoS protection service.
-
In your
app.yamlfile, specify an error handler for DoS responses by providing the path to your static file and adding theerror_handlerstype ofdos_api_denial:error_handlers: - error_code: dos_api_denial file: dos-response.html
Deleting all blacklist entries
To delete all blacklist entries, change the dos.yaml file to just contain:
blacklist:
Viewing DoS denial errors in the console
You can view a graph of the number of requests that are being denied:
-
Go to the App Engine dashboard in the Google Cloud Platform Console:
-
Adjust the graph time frame as necessary to see the results.
Upload your DOS blacklist
You can useappcfg.py to upload DoS configs. When you upload
your application to App Engine using appcfg.py
update, the DoS
Protection Service is updated with the contents of dos.yaml.
To update just the DoS configuration without uploading the rest of the application use the following command:
appcfg.py update_dos <directory>
What's next
- Set up Stackdriver Monitoring to quickly identify problems and alert you.
- Read a customer's experience on how they responded to a distributed denial of service (DDoS) attack (Jan, 2013).