In my previous article i have discussed about why there is a need to protect our application from certain types of attacks. If you have not checked it yet, i would encourage you reading that article to and get more insights on why and when should we think of using WAF. You can find that link here.
In this section of the article i am going to directly dive into how we can actually configure WAF in AWS.
The service that we are going to use in AWS is AWS Firewall Manager
. Once you are logged into the aws console, head to services dropdown and type in the AWS Firewall Manager
and upon click, that should redirect you to AWS WAF page which looks like this.
Recently aws has introduced their new user-interface for WAF hence we will go with the same. If you want to check out the older one you can navigate the through the option provided on the side bar.
To get started with you need to create a WebACLs for your site. Now if you are wondering what is WebACLs here is the definition from the aws documentation.
A web access control list (web ACL) gives you fine-grained control over the web requests that your Amazon CloudFront distribution, Amazon API Gateway API, or Application Load Balancer responds to.
You can use criteria like the following to allow or block requests:
- IP address origin of the request.
- Country of origin of the request.
- String match or regular expression (regex) match in a part of the request.
- Size of a particular part of the request.
- Detection of malicious SQL code or scripting.
To be more precise WebACLs are the bunch of configurations that we require to achieve our ultimate task.In order to create this, click on WebACLs that is available in the left side nav bar and it should take you to the Create WebACL page. Here it is how its looks like
There are 5 steps needed to configure and we will go through each of them.
This is one of the prominent steps out of all and you need to fill in the details according to your need.
Here is the sample view.
In this step, you actually set the list of rules and based on which your application allows or blocks the traffic. Basically aws does give some of their managed list of rules by default. If your application expects any of those then you could directly go with those option else you have to manually create list of rules using the rule type of options. you can find list of managed rules from their documentation here.
For better understanding as a demo i have created a sample rule which sees if a API has some header called X-API-KEY which is having a length of 60 . If it matches the criteria then it allows the traffic else it is going to block the traffic to your application.
Here is a screenshot of how it looks like.
You can find more about custom rules over here.
Once you are done with this step you task is almost over. Lets go to other steps now
This is place where you set the priority of your rules. What this means is that if you have more than one rules that you have defined , then you need specify which rule will take the precedence over other.
By default WAF uses cloudwatch to monitor the logs . But if you are not satisfied with those you can configure others monitoring and metrics over here.
Thats it.!!! Review what you have configured and make sure that all are good to go.
I hope you found this article useful. If it did please help others spreading the word.😊 For any suggestions or feeedbacks 👉 Contact