Skip to content

[Feat] WAF 설정 변경 prod 적용#206

Merged
lvalentine6 merged 8 commits intomainfrom
develop
Oct 1, 2025
Merged

[Feat] WAF 설정 변경 prod 적용#206
lvalentine6 merged 8 commits intomainfrom
develop

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Sep 30, 2025

✨ 개요

  • dev에서 적용되어 검증된 WAF 관련 설정등을 prod에 적용합니다.

🧾 관련 이슈

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • New Features
    • 서버 간 요청에 출처 검증을 도입해 신뢰된 서버 트래픽만 허용하고 위변조 위험을 낮췄습니다.
    • 브라우저 요청 패턴을 인식하여 정상 사용자 트래픽의 통과율을 높였습니다.
    • 보안 로그에서 민감한 요청 헤더를 마스킹해 노출을 최소화했습니다.
  • Chores
    • WAF 기본 동작을 차단 우선으로 전환하고 규칙 우선순위를 재조정해 보호를 강화했습니다.
    • 트래픽 임계값을 상향해 합법적 급증 트래픽의 오탐 차단을 완화했습니다.

@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

WAF 구성이 확장되었습니다: 기본 동작을 block으로 전환하고, 검증 헤더 기반 허용 규칙과 브라우저 요청 허용 규칙을 추가했으며, 기존 규칙의 우선순위를 재배치했습니다. 로깅에는 특정 헤더의 마스킹이 도입되었고, 로컬 변수의 임계값이 상향 조정되었습니다.

Changes

Cohort / File(s) Summary
Terraform Locals 조정
terraform/common/locals.tf
admin_email 로컬 제거, request_threshold 200 → 2000 상향
WAF 로깅 마스킹 추가
terraform/common/main.tf
aws_wafv2_web_acl_logging_configurationredacted_fields.single_header(name="x-origin-verify") 추가
WAF ACL 규칙 및 흐름 개편
terraform/common/waf/main.tf
SSM 파라미터 data.aws_ssm_parameter.x_origin_verify 추가, ACL 기본 동작 allow → block, 신규 규칙 추가(검증된 서버 요청 허용, 브라우저 요청 허용), 기존/관리형 규칙 우선순위 전반 재정렬, rate-based 규칙 우선순위 1 → 20

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant E as Edge/ALB
  participant W as WAF Web ACL
  participant R as Rules Engine
  participant L as WAF Logging
  participant S as SSM Parameter Store

  Note over W: 기본 동작: Block (변경됨)
  C->>E: HTTP(S) 요청
  E->>W: 요청 검사 위임
  par 초기화(계획/적용 시)
    W->>S: /common/CLIENT_HEADER_SECRET 조회
    S-->>W: x-origin-verify 시크릿
  end
  W->>R: 규칙 평가 시작 (우선순위 재정렬 반영)
  alt 서버 검증 허용 규칙
    R->>R: User-Agent(node/Vercel) AND x-origin-verify 매치
    R-->>W: Allow
  else 브라우저 허용 규칙
    R->>R: header size constraints (origin/referer)
    R-->>W: Allow
  else 기타 규칙/관리형 그룹
    R-->>W: Match? → Block / Count / Allow
  else 매치 없음
    Note over W: Default Block
    W-->>E: Block
  end
  W-->>L: 로그 전송 (x-origin-verify 헤더 마스킹)
  E-->>C: 응답
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

작은 발로 규칙을 톡톡, 밤하늘에 점프 셋!
헤더를 살짝 가리고, 비밀은 쏙 감췄지.
문지기는 이제 말해요: “증표 없인 못 지나!”
브라우저엔 길을 열고, 나쁜 봇엔 “넘어가.”
깡총—WAF는 단단히, 로그는 살포시. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 제목은 개발 환경에서 테스트된 WAF 구성 변경을 프로덕션(prod) 환경에 적용하는 주된 의도를 명확하게 전달합니다. 핵심 변경사항과 대상 환경이 간결하게 드러나 있어 동료가 히스토리를 스캔할 때도 빠르게 이해할 수 있습니다.
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 develop

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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


🚀 Production 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

🧹 Nitpick comments (2)
terraform/common/waf/main.tf (2)

13-77: User-Agent 기반 검증의 보안 취약점을 고려하세요.

이 규칙은 User-Agent에 "node" 또는 "Vercel"이 포함되어 있고 x-origin-verify 헤더가 일치하는 경우 요청을 허용합니다. User-Agent는 쉽게 위조 가능하므로 실질적인 보안은 x-origin-verify 헤더 검증에서만 제공됩니다.

User-Agent 검증을 추가한 의도가 공격 표면을 줄이기 위한 것이라면 이해되지만, x-origin-verify 헤더만으로도 충분한 인증을 제공할 수 있습니다. User-Agent 검증이 정상 트래픽을 의도치 않게 차단할 가능성이 있는지 확인해주세요(예: Node.js 버전 업그레이드 시 User-Agent 문자열 변경).


1-272: WAF 설정 변경에 대한 단계적 배포 전략을 권장합니다.

이 PR은 WAF 구성을 전면적으로 변경하여 allow-by-default에서 block-by-default로 전환합니다. 이는 중요한 보안 변경사항이며 잘못 구성 시 서비스 장애로 이어질 수 있습니다.

배포 전 확인사항:

  1. dev 환경에서 충분한 기간 동안 테스트되었는지
  2. 모든 정상 트래픽 패턴이 allow 규칙으로 커버되는지
  3. /common/CLIENT_HEADER_SECRET SSM 파라미터가 prod 환경에 존재하는지
  4. CloudWatch 메트릭과 로그 모니터링 설정이 준비되었는지

배포 전략 제안:

  1. 먼저 WAF를 count 모드로 배포하여 차단될 트래픽 패턴 확인
  2. CloudWatch 메트릭 모니터링
  3. 문제 없음 확인 후 block 모드 활성화
  4. 롤백 계획 준비

특히 "Allow-Browser-Requests" 규칙의 보안 취약점을 수정하는 것을 강력히 권장합니다.

📜 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 f241c9e and f7539c6.

📒 Files selected for processing (3)
  • terraform/common/locals.tf (1 hunks)
  • terraform/common/main.tf (1 hunks)
  • terraform/common/waf/main.tf (7 hunks)
🧰 Additional context used
🪛 GitHub Actions: Notify Discord on `/noti` Comment
terraform/common/main.tf

[error] 1-1: No such file or directory

terraform/common/locals.tf

[error] 1-1: No such file or directory

terraform/common/waf/main.tf

[error] 1-1: No such file or directory

⏰ 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 (6)
terraform/common/locals.tf (1)

253-253: 프로덕션 환경의 트래픽 패턴에 대해 임계값을 검증하세요.

request_threshold를 200에서 2000으로 10배 증가시켰습니다. WAF의 기본 동작이 block으로 변경된 점을 고려할 때, 이 임계값이 프로덕션 트래픽 패턴에 적합한지 확인이 필요합니다. dev 환경에서 이 설정이 충분히 테스트되었는지, 그리고 정상적인 피크 트래픽이 이 제한에 걸리지 않는지 확인해주세요.

terraform/common/main.tf (1)

77-81: LGTM!

WAF 로그에서 x-origin-verify 헤더를 마스킹하는 설정이 올바르게 추가되었습니다. 인증 토큰이 로그에 노출되는 것을 방지하는 필수적인 보안 조치입니다.

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

126-143: LGTM!

Rate-Limit 규칙의 우선순위가 20으로 조정되어 allow 규칙들(우선순위 5, 10) 이후에 실행됩니다. 이는 올바른 순서입니다. 다만 IP당 2000 요청/5분 제한이 프로덕션 트래픽에 적합한지는 앞서 언급한 대로 검증이 필요합니다.


148-248: LGTM!

모든 AWS Managed Rule의 우선순위가 일관되게 조정되어 새로운 allow 규칙(우선순위 5, 10)과 rate-limit 규칙(우선순위 20) 이후에 실행됩니다. 상대적인 우선순위 순서는 유지되어 올바른 실행 순서를 보장합니다.


1-3: SSM 파라미터 존재 및 SecureString 타입 수동 확인 필요
/common/CLIENT_HEADER_SECRET SSM 파라미터가 AWS 콘솔 또는 권한 있는 CLI로 존재하며 SecureString으로 설정되어 있는지 수동으로 확인하세요. 누락되거나 타입이 올바르지 않으면 Terraform 배포가 실패합니다.


9-11: 기본 동작이 allow→block으로 변경된 주요 보안 변경입니다.

명시적 allow 규칙이 누락되면 정상 트래픽이 차단될 수 있으므로, dev 환경에서 브라우저 요청·서버 간 통신·외부 API 호출 등 모든 정상 트래픽이 허용되는지 반드시 검증하세요.

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 b01e5a4 into main Oct 1, 2025
24 of 26 checks passed
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

🎉 This PR is included in version 1.9.1 🎉

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants