Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Sep 20, 2025

✨ 개요

취약점 스캐닝, 크롤링 방지 장기 대응 작업

  • 취약점 스캐닝, 크롤링 방지 장기 대응 작업으로 ALB 앞단에 WAF 설정하였습니다.
  • WAF에 CloudWatch 로그 그룹을 연동하여, 허용 / 차단된 요청들을 기록하게 하였습니다.
  • WAF 설정 후 3시간 모니터링 결과 무차별 로그인 시도, 설정 파일 탈취 시도, 취약점 탐지 시도등 71건의 비정상적인 요청들을 차단하였습니다.
image

기타 버그 수정 작업

  • Datadog AMP Prod 환경에서 Infrastructure Metrics가 정상적으로 보이지 않는 현상을 수정하였습니다.

🧾 관련 이슈

Close #199

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • New Features
    • 웹 애플리케이션 방화벽(WAF) 도입으로 보안 강화: 관리형 규칙 세트 적용, IP별 요청 속도 제한 지원
    • 보안 이벤트 로그를 CloudWatch로 수집해 가시성 향상
  • Chores
    • 운영 모니터링 개선: Datadog 에이전트를 데몬형으로 전환하고 EC2 메타데이터/태그 수집 활성화

@coderabbitai
Copy link

coderabbitai bot commented Sep 20, 2025

Walkthrough

이 변경은 Terraform에 WAF 모듈을 추가하고 ALB에 연동했으며, WAF 로그를 위한 CloudWatch Log Group과 로깅 구성을 생성했다. WAF 규칙과 변수를 포함한 신규 모듈 디렉터리가 추가되었고, 공통 locals에 변수들이 보강되었다. Prod tfvars에서 Datadog ECS 서비스 설정과 환경 변수가 수정되었다.

Changes

Cohort / File(s) Change Summary
WAF 모듈 추가
terraform/common/waf/*
신규 WAFv2 Web ACL 리소스 정의(aws_wafv2_web_acl), 변수(project_name, request_threshold, tags)와 출력(web_acl_arn) 추가. 여러 AWS 관리형 규칙과 IP rate-limit 규칙 구성.
공통 구성에 WAF 연동
terraform/common/main.tf
module "waf" 추가, aws_wafv2_web_acl_association으로 ALB와 연결, aws_cloudwatch_log_group 생성, aws_wafv2_web_acl_logging_configuration으로 로그 전송 설정.
공통 로컬 변수 보강
terraform/common/locals.tf
admin_email 로컬 변수 추가, 별도 locals 블록에 request_threshold = 200 추가.
프로덕션 변수 업데이트
terraform/prod/terraform.tfvars
Datadog ECS 서비스 scheduling_strategyDAEMON으로 변경. Datadog 태스크 정의에 DD_EC2_USE_IMDSV2, DD_COLLECT_EC2_TAGS, DD_COLLECT_EC2_METADATA 환경 변수 추가(모두 "true").

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant TF as Terraform
  participant WAF as AWS WAFv2
  participant ALB as AWS ALB
  participant CW as CloudWatch Logs

  Dev->>TF: terraform apply
  TF->>WAF: Create Web ACL (rules + visibility_config)
  TF->>ALB: Ensure ALB exists (pre-existing)
  TF->>WAF: Associate Web ACL with ALB
  TF->>CW: Create Log Group for WAF
  TF->>WAF: Configure Logging to CW Log Group

  rect rgba(230,245,255,0.6)
    note over WAF,ALB: Runtime traffic filtering
    ALB->>WAF: HTTP(S) requests
    alt Rate limit exceeded
      WAF-->>ALB: Block
    else Allowed by rules
      WAF-->>ALB: Allow
    end
    WAF-->>CW: Emit logs
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

귀가 쫑긋, 코드밭에 발자국 남기네 🐇
방패를 들고, WAF를 세워 문을 지키고,
로그의 강물 따라 구름에 흔적 남기네.
톡톡, 임계치로 발걸음 수를 세고,
데몬처럼 달리는 개토깅 친구와 함께,
오늘도 인프라 정원은 평온하도다.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning 이 PR에 링크된 이슈 [199]의 범위(장기적 WAF 도입)와 직접 관련이 없는 변경사항들이 포함되어 있습니다; 특히 terraform/prod/terraform.tfvars의 Datadog 관련 수정(데몬 스케줄링으로 변경 및 DD_EC2_* 환경변수 추가)과 terraform/common/locals.tf의 admin_email 로컬 변수 추가는 WAF 도입 요구와 무관한 것으로 보입니다. 이러한 항목은 범위 밖 변경으로 간주되어 별도 처리 필요합니다. 해결: Datadog 관련 변경은 별도 PR로 분리하거나 PR 본문에 해당 수정의 이유와 연관 이슈를 명확히 기재하고, admin_email 추가의 목적을 설명하거나 관련 변경을 분리해 주세요.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 제목 "[Fix] 취약점 스캐닝, 크롤링 방지 장기 대응 작업"은 ALB 앞단 WAF 추가 및 크롤링/스캐닝 차단을 핵심으로 명확히 요약하고 있어 변경사항과 직접적으로 연관됩니다. 제목은 간결하고 주된 목적을 잘 표현하여 동료가 히스토리를 훑을 때 주요 변경을 파악할 수 있습니다.
Linked Issues Check ✅ Passed 이 PR은 WAF 모듈(aws_wafv2_web_acl), ALB 연동(aws_wafv2_web_acl_association), WAF 로그 그룹 및 로깅 구성, rate-limit 룰과 request_threshold 변수 추가 등으로 링크된 이슈 [199]이 요구한 "WAF 또는 자체 파이프라인을 통한 장기 대응"을 코드 측면에서 충족합니다; 또한 web_acl_arn 출력이 연동에 필요한 값을 제공합니다. Datadog 관련 수정은 이슈 핵심 요구와 별개이나 WAF 구현의 충족 여부에는 영향이 없습니다.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/PRODUCT-283

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure


No plan summary

Status: ✅ No Changes


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70c9f87 and f1355b0.

📒 Files selected for processing (6)
  • terraform/common/locals.tf (2 hunks)
  • terraform/common/main.tf (1 hunks)
  • terraform/common/waf/main.tf (1 hunks)
  • terraform/common/waf/outputs.tf (1 hunks)
  • terraform/common/waf/variables.tf (1 hunks)
  • terraform/prod/terraform.tfvars (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (14)
terraform/prod/terraform.tfvars (2)

14-14: Datadog 에이전트 스케줄링 전략 변경을 확인합니다.

REPLICA에서 DAEMON으로 변경하면 각 EC2 인스턴스마다 하나씩의 Datadog 에이전트가 실행되어 인프라 메트릭 수집이 개선됩니다. 이는 PR 목표에서 언급한 "Datadog AMP Prod 환경에서 Infrastructure Metrics가 정상적으로 보이지 않는 현상"을 해결하는 데 적절한 변경입니다.


52-54: Datadog EC2 메타데이터 수집 설정을 승인합니다.

추가된 환경 변수들이 인프라 메트릭 문제 해결에 도움이 될 것입니다:

  • DD_EC2_USE_IMDSV2: IMDSv2 사용으로 보안 강화
  • DD_COLLECT_EC2_TAGS, DD_COLLECT_EC2_METADATA: EC2 태그 및 메타데이터 수집 활성화
terraform/common/waf/variables.tf (1)

1-12: WAF 모듈 변수 정의가 적절합니다.

변수들이 명확하게 정의되어 있고, request_threshold의 한국어 설명도 이해하기 쉽습니다. 타입 정의도 올바르게 되어 있습니다.

terraform/common/waf/outputs.tf (1)

1-3: WAF ACL ARN 출력이 올바르게 정의되었습니다.

WAF 웹 ACL의 ARN을 출력하여 다른 모듈에서 참조할 수 있도록 하는 표준적인 패턴입니다.

terraform/common/locals.tf (2)

7-7: 관리자 이메일 추가를 승인합니다.

WAF 관련 알림이나 관리 목적으로 사용될 것으로 보이며, 적절한 위치에 정의되어 있습니다.


253-255: 요청 임계값 설정을 확인합니다.

5분당 IP별 200 요청 제한은 일반적인 웹 애플리케이션에 적절한 수준입니다. 그러나 실제 트래픽 패턴에 따라 조정이 필요할 수 있습니다.

실제 운영 환경의 트래픽 패턴을 모니터링하여 이 임계값이 적절한지 확인하시기 바랍니다. 정상적인 사용자가 차단되지 않도록 주의가 필요합니다.

terraform/common/main.tf (4)

55-60: WAF 모듈 설정을 승인합니다.

WAF 모듈이 적절한 변수들과 함께 올바르게 구성되어 있습니다.


62-65: ALB와 WAF 연결이 올바르게 구성되었습니다.

ALB ARN과 WAF ACL ARN을 사용한 연결 설정이 정확합니다.


67-72: WAF 로그 그룹 설정을 승인합니다.

7일 보존 기간은 디버깅과 분석에 적절하며, 비용 효율적입니다.


74-77: WAF 로깅 구성을 승인합니다.

trimsuffix를 사용하여 CloudWatch 로그 그룹 ARN에서 :* 접미사를 제거하는 것이 올바른 패턴입니다.

terraform/common/waf/main.tf (4)

1-7: WAF 웹 ACL 기본 설정을 승인합니다.

지역 범위(REGIONAL)와 기본 허용 동작이 ALB와 함께 사용하기에 적절합니다.


9-27: Rate-based 규칙 설정을 승인합니다.

IP당 5분간 200 요청 제한과 차단 동작이 적절하게 구성되어 있습니다. 우선순위 1로 설정하여 다른 규칙보다 먼저 평가되도록 한 것도 좋은 설계입니다.


29-47: AWS 관리형 규칙 세트가 포괄적으로 설정되었습니다.

다음과 같은 보안 위협에 대한 적절한 보호를 제공합니다:

  • 공통 웹 공격 (OWASP Top 10)
  • 악성 입력 및 스캐닝 시도
  • IP 평판 기반 차단
  • 익명 IP 차단
  • SQL 인젝션 공격

각 규칙의 우선순위가 논리적으로 설정되어 있고, CloudWatch 메트릭도 활성화되어 모니터링이 가능합니다.

Also applies to: 49-67, 69-87, 109-127, 129-147


149-156: 전체 WAF ACL 가시성 설정을 승인합니다.

CloudWatch 메트릭과 샘플 요청이 활성화되어 있어 모니터링과 디버깅에 도움이 됩니다. 태그 적용도 적절합니다.

Comment on lines +89 to +107
# Bad Bot Protection
rule {
name = "AWS-Managed-Bot-Control-Rule-Set"
priority = 40
override_action {
none {}
}
statement {
managed_rule_group_statement {
vendor_name = "AWS"
name = "AWSManagedRulesBotControlRuleSet"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "aws-managed-bot-control"
sampled_requests_enabled = true
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

❓ Verification inconclusive

Bot Control 규칙의 비용 영향을 고려하세요.

Bot Control은 추가 비용이 발생하는 기능으로, 월 $1의 구독료 외에도 요청당 추가 요금이 부과됩니다. Common Bot Control은 첫 1천만 요청이 무료이지만, Targeted Bot Control은 첫 100만 요청만 무료입니다.

Bot Control 기능의 필요성과 예상 비용을 검토하시기 바랍니다. 트래픽 볼륨에 따라 상당한 비용이 발생할 수 있습니다:


🌐 Web query:

AWS WAF Bot Control pricing 2025 common vs targeted costs

💡 Result:

Short answer — pricing (as of AWS pricing page):

  • Monthly subscription: Bot Control rule group = $10.00 per Web ACL (prorated hourly). [1]
  • Common Bot Control: first 10 million requests per month free; additional requests billed at $1.00 per million requests. [1]
  • Targeted Bot Control: first 1 million requests per month free; additional requests billed at $10.00 per million requests. [1]

Practical notes:

  • Use a scope‑down statement to limit what Bot Control inspects to reduce costs (e.g., apply to login paths only). [2]
  • Region pricing may vary — always confirm the AWS WAF pricing page for your region and month. [1][2]

Sources: AWS WAF pricing and AWS WAF cost guidance. [1][2]


Bot Control 규칙 비용 검토

File: terraform/common/waf/main.tf (Lines 89–107)

AWS WAF Bot Control은 Web ACL당 월 구독료 $10(시간 단위 비례 청구)과 다음 요청당 요금을 부과합니다:

  • Common Bot Control: 매월 첫 1천만 요청 무료, 초과분은 백만 요청당 $1
  • Targeted Bot Control: 매월 첫 100만 요청 무료, 초과분은 백만 요청당 $10

트래픽 규모에 따라 비용이 크게 증가할 수 있으므로 scope-down statement를 도입해 검사 대상을 제한하는 등 Bot Control 기능의 필요성과 예상 비용을 꼼꼼히 검토하세요.

🤖 Prompt for AI Agents
In terraform/common/waf/main.tf around lines 89 to 107, the
AWSManagedRulesBotControlRuleSet is added without a scope-down statement or
limiting conditions which may incur significant Bot Control subscription and
per-request costs; update the managed_rule_group_statement to include an
appropriate scope_down_statement (e.g., a statement that restricts inspection to
specific paths, IP sets, or headers) to limit which requests are evaluated,
and/or add a variable to toggle Bot Control on/off and document expected
usage/costs so the rule is only enabled for intended traffic patterns.

Copy link
Member

@leegwichan leegwichan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 앞으로도 개선점이 보인다면 추가 부탁드려요!

@lvalentine6 lvalentine6 merged commit 813a4be into develop Sep 20, 2025
12 checks passed
@lvalentine6 lvalentine6 deleted the fix/PRODUCT-283 branch September 20, 2025 16:10
@github-actions
Copy link

🎉 This PR is included in version 1.8.0-develop.14 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.9.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PRODUCT-283] [Fix] 취약점 스캐닝, 크롤링 방지 장기 대응 작업

3 participants