How can I prevent Denial of Wallet attacks against AWS Cloudfront?
Here's my specific situation: I have a Cloudfront distribution where Lambda#Edge functions serve web pages and API requests for my application. I need to rate-limit requests made to Cloudfront based on the IP address of the user. Without any kind of rate-limiting in place, it's possible for a malicious user to make millions of slow requests to the distribution that wouldn't be blocked by AWS's DDOS protections and which would lead to significant charges. This is especially important here since Lambda#Edge functions cost 3x as much as ordinary Lambda functions and don't come with a free tier.
It seemed practical to use AWS WAF in order to accomplish this. However, I recently found out that WAF charges for all incoming requests, regardless of if they are blocked or not. So a Denial of Wallet attack would still be possible here.
Is there a method or a general strategy that I can implement here that doesn't involve AWS WAF?
The limits need to be very tight. Even paying $50 per month for malicious requests would be considered too high.
AWS Shield Standard is free when you use Cloudfront and it automatically protects against common DDoS attacks. Source
If you want to use WAF to tighten the requests to your Lambda, you can setup caching for HTTP 403 responses in Cloudfront, so the attacker won't get their request past the Cloudfront cache.
You have to decide which one is on priority for you, your service being down or your bill going above your budget? If it's the first one, you can use WAF and AWS Shield Advanced.
If it's the second one, you can implement a request throttling method. For example, you can make use of incoming requests to EC2 instances are free. So you can implement a queue in a free tier EC2 instance that forwards the requests to your Lambda but drops the requests when the rate is higher than a defined threshold. Keep in mind that you get charged for outgoing requests from EC2 to your Lambda Edge.
OR you can implement another Lambda function before your Lambda Edge to keep track of which IP address sent how many requests. If it's past the threshold, respond with HTTP 403 and have that cached in Cloudfront. Then the next request from that IP address won't reach your Lambda. But again, keep in mind that you'll get charged for this additional Lambda.
The last resort is creating a billing alarm that notifies you when monthly charges reach $50 so that you can stop the costs before it goes high.
AWS Shield Advanced includes DDoS cost protection, a safeguard from scaling charges as a result of a DDoS attack that causes usage spikes on protected Amazon EC2, Elastic Load Balancing (ELB), Amazon CloudFront, AWS Global Accelerator, or Amazon Route 53. If any of the AWS Shield Advanced protected resources scale up in response to a DDoS attack, you can request credits via the regular AWS Support channel.
Please note that, at the time of writing, this service involves a monthly fee of $3,000 per account, plus data transfer fees starting at $0.050 per GB.
Related
I am using AWS CloudFront and I'm currently free-tier.
I am close to going over 2.000.000 HTTP/S requests that is max allowed for free-tier.
Will AWS automatically charge me for the traffic that goes over those 2.000.000 requests (per on-demand prices) or will CloudFront become unavailable and stop receiving more requests? How do I upgrade to on-demand?
Cloudfront will still be available, however, you will be charged requests for over the max allowed free tiers.
Yes AWS will automatically charge for any excess usage over the free tier quota. Any resource you created in your account will not affect and they will work without any interruption. You do not need to do any upgrades from your side to cater to increased requests.
If you are budget concerned, you can create AWS Budget and create an alert so AWS will notify you before you reach a pre-defined budget. From there you can also define what to do if you reach the budget. For example, you can shut down ec2 instances if this resource consumed more than the allocated budget.
I am building a website to carry out a survey and this would store some answers and user data. Obviously, I want to keep costs low and within what the free tier offers. I am trying to build a low-cost solution for mitigating DDoS attacks. Here is what I have come up with but not sure if I am going in the right direction. I plan to put my frontend as well backend service behind CloudFront. I would put AWS WAF and Shield on this CloudFront. Along with that, I plan to add two WAF rules:
Every request should have a "user-agent" header
Requests should originate only from a specific country i.e the one
with my target audience
Along with this, I plan to add a Recaptcha to ensure only human users interact with my application just as a deterrent from cost perspective. Any other suggestion or feedback is really appreciated. Please note: cost is a huge factor.
AWS Shield, CloudFront and WAF should be sufficient for your use case. Use the geo restrictions but I don’t think a header check will add any value as it’s so easy to spoof. Additionally you may think about using auto scaling for your backend to achieve more resilience but be careful with the scaling cost, have a proper scaling policy and set alarms (especially a billing alarm if you don’t have one already) and notifications for scaling events.
Check this whitepaper for more information: https://docs.aws.amazon.com/whitepapers/latest/aws-best-practices-ddos-resiliency/aws-best-practices-ddos-resiliency.pdf
FluxCDN, DDoS-Guard, Cloudflare, Stackpath would be an good option.
Use GEO restrictions (China, India ...) and Challenge the requests (Captcha).
Block empty user-agent and user agents from bots for example "python-requests" if you don't need them.
Block an IP from accessing your site if it reaches the Threshold (Rate limit).
Block bad ASN from accessing your site.
Use an JS challenge to challenge the legitmacy of the request.
Cache static files (pngs, htmls, ...)
Block HTTP/1.0 HTTP/1.1 HTTP/1.2 if not needed (Blocks 99% of all DDoS attacks)
I'm hosting a static website in Amazon S3 with CloudFront. Is there a way to set a limit for how many reads (for example per month) will be allowed for my Amazon S3 bucket in order to make sure I don't go above my allocated budget?
If you are concerned about going over a budget, I would recommend Creating a Billing Alarm to Monitor Your Estimated AWS Charges.
AWS is designed for large-scale organizations that care more about providing a reliable service to customers than staying within a particular budget. For example, if their allocated budget was fully consumed, they would not want to stop providing services to their customers. They might, however, want to tweak their infrastructure to reduce costs in future, such as changing the Price Class for a CloudFront Distribution or using AWS WAF to prevent bots from consuming too much traffic.
Your static website will be rather low-cost. The biggest factor will likely be Data Transfer rather than charges for Requests. Changing the Price Class should assist with this. However, the only true way to stop accumulating Data Transfer charges is to stop serving content.
You could activate CloudTrail data read events for the bucket, create a CloudWatch Event Rule to trigger an AWS Lambda Function that increments the number of reads per object in an Amazon DynamoDB table and restrict access to the objects once a certain number of reads has been reached.
What you're asking for is a very typical question in AWS. Unfortunately with near infinite scale, comes near infinite spend.
While you can put a WAF, that is actually meant for security rather than scale restrictions. From a cost-perspective, I'd be more worried about the bandwidth charges than I would be able S3 requests cost.
Plus once you put things like Cloudfront or Lambda, it gets hard to limit all this down.
The best way to limit, is to put Billing Alerts on your account -- and you can tier them, so you get a $10, $20, $100 alerts, up until the point you're uncomfortable with. And then either manually disable the website -- or setup a lambda function to disable it for you.
I am learning AWS , and came across hosting static websites using Amazon S3 and distributing to edge locations using Cloud Front and Route53.
I know that for Cloud front we pay for what we use. So my monthly bill will reflect the number of requests I get once the free tier is over.
My question is what if a hacker or someone sends a lots of requests like spamming, then will I be charged higher?
How to prevent this and does AWS has any security measures like limiting the number of requests to serve per minute or something for this ?
Pardon me if my question is very basic. I am just learning . Thanks
My question is what if a hacker or someone sends a lots of requests like spamming, then will I be charged higher?
Yes. You are charged a per-request price, as well as data transfer charges. The per-request charges are relatively low, but if they find a large file to download they can quickly run up the bandwidth charge.
does AWS has any security measures like limiting the number of requests to serve per minute or something for this ?
Yes, you want WAF, the Web Application Firewall. With it you can configure a rate-limited rule that will block an IP address after N requests within a five-minute period.
As I know you pay for Caches Invalidations on AWS but not for a number of requests done to your CloudFront distributions.
For a sake of HA I'm considering switching from self hosted solution (ZeroMQ) to AWS Simple Notification Service for pub/sub in an application. Which is a backend for an app, thus should be reasonably real-time.
What are latency and throughput I can expect of SNS?
Is the app going to be hosted on EC2? If so, the latency will be far diminished, as the communication channel will be going across Amazon's connection, rather than through the internet.
If you are going to call AWS services from boxes not hosted on EC2, here's a cool site that attempts to give you an idea of the amount of latency between you and various AWS services and locations.
How are you measuring the HTTP Ping Request Latency?
We are making a HTTP GET request to AWS Service Endpoints (like EC2,
SQS, SNS etc) for PING and measuring the observed latency for it
across all regions.
As for thoughput, that is left up to you. You can use various strategies to increase throughput, like multi-treading, batching messages, etc.
Keep in mind that you will have to code for some side effects, like possibly seeing the same message twice (At Least Once Delivery), and not being able to rely on FIFO.