I am trying to block connection from a same ip to an endpoint ,i am doing this for 100 connection but this behaves strange
When i am trying to reach my endpoint {{URL}}/connect/token from postman for the first time i am able to connect to the endpoint as much time as possible (for example even 300 time) , for the second time when i hit the same endpoint i get 403 which is correct , not sure what makes this strange behavior
Any help much appreciated
resource "aws_wafv2_regex_pattern_set" "url_pattern" {
name = "url_pattern-regex"
description = "A regex that matches Account api Token and Authorize endpoints"
scope = "REGIONAL"
regular_expression {
regex_string = "/connect/token"
}
regular_expression {
regex_string = "/connect/authorize"
}
}
locals {
name = "${var.environment}-${var.stack}-acl"
}
resource "aws_wafv2_web_acl" "x-account-acl" {
name = local.name
description = "rate based statement."
scope = "REGIONAL"
default_action {
allow {}
}
rule {
name = "rule-1"
priority = 1
action {
count {}
}
statement {
rate_based_statement {
aggregate_key_type = "IP" //Count number of calls from IP
limit = 100
scope_down_statement {
regex_pattern_set_reference_statement {
arn = aws_wafv2_regex_pattern_set.url_pattern.arn
field_to_match {
uri_path {}
}
text_transformation {
priority = 1
type = "NONE"
}
}
}
}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "friendly-rule-metric-name"
sampled_requests_enabled = false
}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "friendly-metric-name"
sampled_requests_enabled = false
}
}
resource "aws_wafv2_web_acl_association" "web_acl_association_loadbalancer" {
resource_arn = module.alb.alb_arn
web_acl_arn = aws_wafv2_web_acl.x-account-acl.arn
}
my postman code :
const postRequest = {
url: pm.environment.get("URL") + '/connect/token',
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
mode: 'urlencoded',
urlencoded:
[
{key: "client_id",value: pm.environment.get("Client_Id_userApi")},
{key: "grant_type",value: "client_credentials"},
{key: "client_secret",value: pm.environment.get("Client_Secret_userApi")},
]
}
};
for (let i = 0; i < 300; i++) {
pm.sendRequest(postRequest, (error, response) => {
if (error) {
console.log(error,i);
}
});
}
for me the code or configuration seems ok but it is seems a strange behavior ,