Skip to content

Commit 9f765dd

Browse files
chore: Add 5xx to lb query for waf_ip_blocklist (#688)
1 parent 7a349b4 commit 9f765dd

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

waf_ip_blocklist/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ No modules.
6464
| <a name="input_billing_tag_key"></a> [billing\_tag\_key](#input\_billing\_tag\_key) | (Optional, default 'CostCentre') The name of the billing tag | `string` | `"CostCentre"` | no |
6565
| <a name="input_billing_tag_value"></a> [billing\_tag\_value](#input\_billing\_tag\_value) | (Required) The value of the billing tag | `string` | n/a | yes |
6666
| <a name="input_lb_status_code_skip"></a> [lb\_status\_code\_skip](#input\_lb\_status\_code\_skip) | (Optional, default []) A list of Load Balancer status codes to ignore when adding an IP address to the blocklist | `list(string)` | `[]` | no |
67-
| <a name="input_query_lb"></a> [query\_lb](#input\_query\_lb) | (Optional, default true) Should the Load Balancer logs be queried for 4xx responses? | `bool` | `true` | no |
67+
| <a name="input_query_lb"></a> [query\_lb](#input\_query\_lb) | (Optional, default true) Should the Load Balancer logs be queried for 4xx and 5xx responses? | `bool` | `true` | no |
6868
| <a name="input_query_waf"></a> [query\_waf](#input\_query\_waf) | (Optional, default true) Should the WAF logs be queried for BLOCK responses? | `bool` | `true` | no |
6969
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | (Required) The name of the service | `string` | n/a | yes |
7070
| <a name="input_waf_block_threshold"></a> [waf\_block\_threshold](#input\_waf\_block\_threshold) | (Optional, default 20) The threshold of blocked requests for adding an IP address to the blocklist | `number` | `20` | no |

waf_ip_blocklist/input.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ variable "lb_status_code_skip" {
5656
}
5757

5858
variable "query_lb" {
59-
description = "(Optional, default true) Should the Load Balancer logs be queried for 4xx responses?"
59+
description = "(Optional, default true) Should the Load Balancer logs be queried for 4xx and 5xx responses?"
6060
type = bool
6161
default = true
6262
}

waf_ip_blocklist/lambda/blocklist_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_handler_with_ips_to_block(mock_waf_client, mock_athena_client, capsys):
5656
mock_athena_client.start_query_execution.assert_has_calls(
5757
[
5858
call(
59-
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
59+
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n OR target_status_code LIKE '5__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
6060
QueryExecutionContext={"Database": "access_logs"},
6161
ResultConfiguration={"OutputLocation": "s3://test_bucket/"},
6262
WorkGroup="test_workgroup",
@@ -117,7 +117,7 @@ def test_handler_with_no_ips_to_block(mock_waf_client, mock_athena_client):
117117
mock_athena_client.start_query_execution.assert_has_calls(
118118
[
119119
call(
120-
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
120+
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n OR target_status_code LIKE '5__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
121121
QueryExecutionContext={"Database": "access_logs"},
122122
ResultConfiguration={"OutputLocation": "s3://test_bucket/"},
123123
WorkGroup="test_workgroup",
@@ -163,7 +163,7 @@ def test_handler_with_only_lb_query(mock_waf_client, mock_athena_client):
163163
mock_athena_client.start_query_execution.assert_has_calls(
164164
[
165165
call(
166-
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
166+
QueryString="-- List of IP addresses that have triggered 4xx HTTP responses\nSELECT\n client_ip,\n COUNT(*) as count\nFROM\n lb_logs\nWHERE\n (\n elb_status_code = 403\n OR target_status_code LIKE '4__'\n OR target_status_code LIKE '5__'\n )\n AND target_status_code NOT IN ('')\n AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)\nGROUP BY\n client_ip\nHAVING COUNT(*) > 20\nORDER BY count DESC",
167167
QueryExecutionContext={"Database": "access_logs"},
168168
ResultConfiguration={"OutputLocation": "s3://test_bucket/"},
169169
WorkGroup="test_workgroup",

waf_ip_blocklist/lambda/query_lb.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ WHERE
88
(
99
elb_status_code = 403
1010
OR target_status_code LIKE '4__'
11+
OR target_status_code LIKE '5__'
1112
)
1213
AND target_status_code NOT IN ({skip_list})
1314
AND from_iso8601_timestamp(time) >= date_add('day', -1, current_timestamp)

0 commit comments

Comments
 (0)