Cloud Infra Architecture (AWS)/AWS Build
[AWS WAF] AWS WAF Label 활용 하여 규칙 생성 (JSON 기반 규칙) [T]
seongduck
2024. 11. 1. 16:22
[AWS WAF] AWS WAF JSON 기반 규칙 생성 [T]
AWS WAF에서 제공하는 Rule Visual Editor를 사용하면 간편하지만 복잡한 정책을 만들 때 JSON editor를 사용한다.혹은 AND 조건과 OR 조건의 중복 적용관련해서도 JSON으로 가능하다. 기본 WAF 규칙으로 생
seongduck.tistory.com
여기서 만든 JSON 정책에서 이어서 시작한다.
위의 정책 수정
{
"Name": "JSONRule",
"Priority": 0,
"Action": {
"Count": {}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "JSONRule"
},
"Statement": {
"AndStatement": {
"Statements": [
{
"GeoMatchStatement": {
"CountryCodes": [
"KR"
]
}
},
{
"OrStatement": {
"Statements": [
{
"SizeConstraintStatement": {
"FieldToMatch": {
"Body": {}
},
"ComparisonOperator": "GT",
"Size": 100,
"TextTransformations": [
{
"Priority": 0,
"Type": "NONE"
}
]
}
},
{
"ByteMatchStatement": {
"SearchString": "bot",
"FieldToMatch": {
"SingleHeader": {
"Name": "x-value"
}
},
"TextTransformations": [
{
"Priority": 0,
"Type": "LOWERCASE"
}
],
"PositionalConstraint": "EXACTLY"
}
}
]
}
}
]
}
}
}
curl -i -H "x-value: bot" $ALB_URL #접속 테스트
Label 기반 규칙 생성
1) 위의 ACLs 선택 -> Rules -> Add Rules -> Add my own rules and rule groups
2) Rule bulider
"""Rule"""
3) Block_CURL
Type = Regular rule
"""Statement"""
4) If a request matches the statement
Inspect = Has a label
Match scope = Label
Match Key = awswaf:managed:aws:bot-control:bot:name:curl
"""Action"""
5) Action = Block -> Add rule - Save
차단 확인
curl -i -H "x-value: bot" $ALB_URL