Skip to content

Commit 14a3da6

Browse files
committed
updated WAF instructions to use new rule builder and managed rules
1 parent ea5fe7d commit 14a3da6

21 files changed

+41
-100
lines changed

docs/06-waf/README.md

Lines changed: 41 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -68,142 +68,83 @@ If you have completed **Module 3: Input validation on API Gateway**, your API no
6868

6969
</details>
7070

71-
### Module 6A: Create a WAF ACL
71+
### Module 6A: Describe a Web ACL
7272

7373
Now let's start creating an AWS WAF to give us additional protection:
7474

7575
1. Go to the [AWS WAF Console](https://console.aws.amazon.com/wafv2/home#/wafhome)
7676

77-
1. The AWS WAF console has recently released a new version: see [Introducing AWS Managed Rules for AWS WAF
78-
](https://aws.amazon.com/about-aws/whats-new/2019/11/introducing-aws-managed-rules-for-aws-waf/). However, this workshop has not been yet adapted to the new version. Therefore, we will be using the classic version of the WAF console. You can use the **Switch to AWS WAF Classic** button to switch to classic:
7977

80-
![](images/switch-waf-classic.png)
81-
82-
1. Click on **Create web ACL** on the WAF Classic console
78+
1. Click on **Create web ACL**
8379

80+
![](images/6A-create-web-acl.png)
8481
![](images/classifc-waf-opening.png)
8582

8683
1. In Step 1 of the ACL creation wizard, fill in:
8784

8885
* **Web ACL Name**: `ProtectUnicorn`
8986
* **CloudWatch metric name**: this should be automatically populated for you
9087
* **Region**: select the AWS region you chose for previous steps of the workshop
91-
* **Resource type to associate with web ACL**: Pick `API Gateway`
92-
* **Amazon API Gateway API**: Pick the API Gateway we deployed previously, `CustomizeUnicorns`
93-
* **Stage**: select `dev`
94-
95-
![screenshot](images/web-acl-name.png)
96-
97-
and click **Next**
9888

99-
### Module 6B: Create WAF conditions
89+
1. To associate the WAF with your API Gateway resources, click **add AWS resources** and select the API Gateway we deployed previously, `CustomizeUnicorns`
90+
![screenshot](images/6A-associate-resources.png)
91+
click **Add**
92+
![screenshot](images/6A-web-acl-step-1.png)
93+
and then **Next**
10094

101-
1. Next you will create 2 different conditions. Let's start with a condition to restrict the maximum size of request body:
10295

103-
* Go to **Size constraint conditions** section, click **Create condition**
104-
* Give the condition a name, like `LargeBodyMatch`
105-
* In Filter settings, add a filer on
106-
* **Part of the request to filter on**: body
107-
* **Comparison operator**: Greater than
108-
* **Size (Bytes)**: 3000
109-
* Click **Add filter**
110-
* After the filter is added to the condition, click **Create**
96+
### Module 6B: Add web ACL rules
11197

112-
![screenshot](images/large-body-condition.png)
113-
98+
1. Next you will create 3 different rules. Let's start with a rule to restrict the maximum size of request body:
11499

115-
1. Next, let's add a SQL injection condition.
116-
117-
* Go to **SQL injection match conditions** section, click **Create condition**
118-
* Give the condition a name, like `SQLinjectionMatch`
119-
* Here, we want to add multiple rules to inspect multiple aspects of the request: request body, request URI and query strings
120-
* In the **Filter settings**, add 4 filters:
121-
122-
<table>
123-
<tr>
124-
<th></th>
125-
<th>Part of the request to filter on</th>
126-
<th>Transformation</th>
127-
</tr>
128-
<tr>
129-
<td>1</td>
130-
<td>Body</td>
131-
<td>None</td>
132-
</tr>
133-
<tr>
134-
<td>2</td>
135-
<td>Body</td>
136-
<td>URL decode</td>
137-
</tr>
138-
<tr>
139-
<td>3</td>
140-
<td>URI</td>
141-
<td>URL decode</td>
142-
</tr>
143-
<tr>
144-
<td>4</td>
145-
<td>Query string</td>
146-
<td>URL decode</td>
147-
</tr>
148-
</table>
149-
* Click **Create**
100+
![screenshot](images/6B-own-rule.png)
101+
* **Rule Type** select **Rule Builder**
102+
* **Rule Name** Give the rulle a name, like `LargeBodyMatch`
103+
* **Type** Regular rule
104+
* **If a request** matches the statement
105+
* **Inspect** Body
106+
* **Content Type** Plain text
107+
* **Match type** Size greater than
108+
* **Size** `3000`
109+
* **Action** Block
110+
![screenshot](images/6B-large-body-rule.png)
111+
* Then click **Add Rule**
150112

151-
![screenshot](images/sql-condition.png)
152-
153-
1. Click **Next** to advance to the **Create rules** page
154-
155-
156-
### Module 6C: Create WAF rules
157113

114+
1. Next, let's add a SQL injection rule.
158115

159-
1. Next, we create **Rules** that are composed of one or more **Conditions**. Let's start by creating a rule based on the request body size condition:
160-
161-
* Click **Create Rule**
162-
* Give it a name, like `LargeBodyMatchRule`
163-
* For **Rule type**, keep `Regular rule`
164-
* In Add conditions section, select
165-
* `does`
166-
* `match at least one of the filters in the size constraint condition `
167-
* `LargeBodyMatch` -- the name of the condition we created for large request body in 6B
168-
169-
* Then click **Create**
116+
![screenshot](images/6B-managed-rule.png)
117+
* Expand the **AWS managed rule groups** section
118+
* toggle the **SQL database** option
119+
![screenshot](images/6B-sql-managed-rule.png)
120+
* Then click **Add Rule**
170121

171-
![screenshot](images/large-body-rule.png)
172-
173-
1. Next, we create the rule for SQL injection.
174-
175-
* Click **Create Rule**
176-
* Give it a name, like `SQLinjectionRule`
177-
* For **Rule type**, keep `Regular rule`
178-
* In Add conditions section, select
179-
* `does`
180-
* `match at least one of the filters in the SQL injection match condition `
181-
* `SQlInjectionMatch` -- the name of the condition we created for SQL injection in 6B
182-
* Then click **Create**
183-
184-
![screenshot](images/sql-rule.png)
185122

186123
1. Lastly, we can create a rate-based rule that prevents an overwhelming number of requests (either valid or invalid) from flooding our API:
187124

188-
* Click **Create Rule**
189-
* Give it a name, like `RequestFloodRule`
125+
![screenshot](images/6B-own-rule.png)
126+
* Give it a **Name**, like `RequestFloodRule`
190127
* For **Rule type**, select `Rate-based rule`
191128
* For **Rate limit**, use `2000`
129+
* **IP address to use for rate limiting** Source IP address
130+
* **Criteria to count request towards rate limit** Consider all requests
131+
* **Action** Block
192132
* Then click **Create**
193133

194-
![screenshot](images/request-flood-rule.png)
134+
![screenshot](images/6B-request-flood-rule.png)
195135

196136
1. You should now see 3 rules in like below. Ensure you select `Block` if the request matches any of the rules.
197137

198138
For **Default action**, select `Allow all requests that don't match any rules`
199139

200-
![screenshot](images/list-rules.png)
201-
202-
1. Click **Review and create**
140+
![screenshot](images/6B-three-rules.png)
141+
### Modules 6C: Rule priorities, metrics and review
142+
1. Frome here you can use the default selected options,
143+
144+
![screenshot](images/6B-rule-priorities.png)
203145

204-
1. In the next page, review the configuration and click **Confirm and Create**
205-
206-
![screenshot](images/review-acl.png)
146+
![screenshot](images/6B-metrics.png)
147+
1. and now you can **Create Web ACL**
207148

208149
You have now added a WAF to our API gateway stage!
209150

36.2 KB
Loading
56.3 KB
Loading
78.6 KB
Loading
124 KB
Loading
15.3 KB
Loading

docs/06-waf/images/6B-metrics.png

39.9 KB
Loading

docs/06-waf/images/6B-own-rule.png

15.3 KB
Loading
104 KB
Loading
22.9 KB
Loading
11.3 KB
Loading

docs/06-waf/images/6B-three-rules.png

40.7 KB
Loading
-122 KB
Binary file not shown.
-114 KB
Binary file not shown.

docs/06-waf/images/list-rules.png

-143 KB
Binary file not shown.
-137 KB
Binary file not shown.

docs/06-waf/images/review-acl.png

-177 KB
Binary file not shown.

docs/06-waf/images/sql-condition.png

-147 KB
Binary file not shown.

docs/06-waf/images/sql-rule.png

-129 KB
Binary file not shown.
-351 KB
Binary file not shown.

docs/06-waf/images/web-acl-name.png

-157 KB
Binary file not shown.

0 commit comments

Comments
 (0)