Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Sep 19, 2025

✨ 개요

  • Datadog SLO 알람에서 지속적으로 레이턴시가 감소하고 있다는 경고가 발생해 임시 조치를 적용했습니다.
  • ALB에서 서버 도메인으로만 접근이 가능하게 리스너 규칙을 수정합니다.
  • 임시적으로 스캐닝과 크롤링을 줄일수 있지만 시간이 지나고, 도메인이 노출되면 다시 공격이 들어올 가능성이 높기에 반드시 추가 조치가 필요합니다.
  • 공격자를 차단하도록 로깅 정책을 변경하여 요청자의 IP 정보를 Hash로 암호화하여 저장하는 추가 작업이 필요합니다.

🧾 관련 이슈

#196

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • 신기능
    • ALB HTTPS 리스너의 기본 동작이 유효하지 않은/미지정 호스트 요청에 대해 대상 그룹 전달 대신 HTTP 403과 “Access Denied: Invalid Host” 메시지를 반환합니다. 잘못된 도메인 접근 시 사용자에게 명확한 거부 사유가 안내됩니다.

- 취약점 스캐닝, 크롤링이 확인되어 임시 조치함
@coderabbitai
Copy link

coderabbitai bot commented Sep 19, 2025

Walkthrough

ALB HTTPS 리스너의 default_action이 대상 그룹 포워드에서 고정 응답(HTTP 403, text/plain, “Access Denied: Invalid Host”)으로 변경되었습니다. 다른 리소스 변화는 없습니다.

Changes

Cohort / File(s) Summary of Changes
ALB HTTPS Listener Default Action
terraform/common/alb/https-listener/main.tf
default_action을 forward(var 기반)에서 fixed-response로 변경. 고정 응답: content_type "text/plain", message_body "Access Denied: Invalid Host", status_code "403". 대상 그룹 ARN 포워딩 제거.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant C as Client
    participant L as ALB HTTPS Listener
    participant TG as Target Group
    participant R as Response

    rect rgb(240,248,255)
    note over L: 이전(default_action = forward)
    C->>L: HTTPS Request (Host Mismatch 등)
    L->>TG: Forward to default target group
    TG-->>L: Generate Response
    L-->>C: Response (varies by TG)
    end
Loading
sequenceDiagram
    autonumber
    participant C as Client
    participant L as ALB HTTPS Listener
    participant R as Response

    rect rgb(245,255,250)
    note over L: 현재(default_action = fixed-response)
    C->>L: HTTPS Request (default action 경로)
    L-->>C: HTTP 403<br/>Content-Type: text/plain<br/>Body: "Access Denied: Invalid Host"
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

작은 귀를 쫑긋 세워, 나는 말하죠:
잘못 온 길엔 403이죠—멈춰요, 살금살금!
타겟 풀로 달리던 날 접고,
고정 응답 한 줄로 길을 고쳤지요.
깡충! “Access Denied”라구요, 안전은 먼저니까. 🐇✨

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의 핵심 목적을 간결하게 요약하고 있습니다. 'HotFix'와 '임시 조치'라는 표현은 긴급 보안 완화 의도를 분명히 하며 '보안 취약점 스캐닝, 크롤링 방지'는 ALB 리스너를 이용해 비정상 호스트 접근에 403 응답을 반환하도록 변경한 실제 변경사항과 직접적으로 연관됩니다. 따라서 제목은 변경사항을 명확히 반영합니다.
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 hotfix/PRODUCT-282

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

  ~ update in-place
  ~ resource aws_alb_listener https {
Plan: 0 to add, 1 to change, 0 to destroy.

Status: 🔄 Changes Detected


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

@lvalentine6 lvalentine6 changed the title [HotFix] ALB 리스너 규칙으로 수정해 호스트 헤더로만 접근을 허용 [HotFix] 보안 취약점 스캐닝, 크롤링 방지 임시 조치 Sep 19, 2025
@lvalentine6
Copy link
Member Author

/noti

  • 새벽 시간이고, 보안 관련한 문제라 바로 Merge 하겠습니다.

@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: 0

🧹 Nitpick comments (4)
terraform/common/alb/https-listener/main.tf (4)

8-14: 불필요한 정보 노출 최소화(메시지 바디 축소/정규화) 제안

스캐너에 과한 힌트를 주지 않으려면 메시지 바디를 비우거나 일반화된 문구로 축소하는 것을 권장합니다. 미미하지만 응답 바이트 절감도 있습니다.

적용 예시:

   default_action {
     type = "fixed-response"

     fixed_response {
-      content_type = "text/plain"
-      message_body = "Access Denied: Invalid Host"
+      content_type = "text/plain; charset=utf-8"
+      message_body = ""
       status_code  = "403"
     }
   }

8-14: 상태 코드 정책 재검토(선택): 403 vs 404/421

운영 정책에 따라 403 대신 404(Not Found) 또는 421(Misdirected Request)도 고려 가능합니다. 404는 존재 유무를 흐리게 하고, 421은 호스트 불일치를 더 명확히 표현합니다. 현재 403도 충분히 타당하므로 필수 변경은 아닙니다.

적용 예시(한 가지 선택):

-      status_code  = "403"
+      status_code  = "404"

또는

-      status_code  = "403"
+      status_code  = "421"

23-27: 여러 호스트 도메인 지원을 위한 입력 스키마 확장 제안

현재 values = [each.value.host_header]는 단일 호스트만 허용합니다. apex/www/내부 도메인 등 복수 호스트를 한 규칙에서 처리할 수 있도록 리스트 입력을 허용하면 관리가 단순해집니다.

예시(단·복수 입력 모두 허용):

   condition {
     host_header {
-      values = [each.value.host_header]
+      values = try(each.value.host_headers, [each.value.host_header])
     }
   }

변수 정의에서도 host_headerslist(string)로 옵션 처리해 주세요.


8-14: 운영 관점: 403 스파이크 모니터링/예외 처리 및 WAF 연계

이번 변경으로 403 고정 응답이 증가합니다. 모니터링(SLO/알람)에서 4xx 급증에 대한 새로운 베이스라인/예외 규칙을 반영하고, ALB 수준에 WAF(Managed Rule) 적용도 병행 검토해 주세요. 크롤링이 재발할 때 방화벽 차단이 1차 완충이 됩니다.

  • Datadog에서 403 비율/절대치에 대한 신규 모니터를 추가하거나 기존 오류율 메트릭에서 제외 처리해 주세요.
  • 다중 도메인 인증서가 필요한 경우 aws_lb_listener_certificate로 추가 SAN 인증서 연결 여부도 확인 바랍니다.
📜 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 f7efd27 and b87f5c3.

📒 Files selected for processing (1)
  • terraform/common/alb/https-listener/main.tf (1 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 (2)
terraform/common/alb/https-listener/main.tf (2)

8-14: 기본 동작을 403 고정 응답으로 전환한 결정은 목적(Host 헤더 미일치 트래픽 차단)에 부합합니다.

규칙에 매칭되지 않는 요청은 이제 대상 그룹으로 포워딩되지 않고 즉시 403을 반환합니다. 의도대로 스캐너/크롤러 트래픽 비용과 레이턴시를 줄일 수 있습니다.

  • Terraform plan에서 리스너 교체 없이 in‑place 업데이트로 적용되는지 확인해 주세요. 교체(replacement) 시 순간적인 연결 리셋이 발생할 수 있습니다.
  • 80포트(HTTP) 리스너가 있다면 HTTPS 리다이렉트만 허용하도록 구성되어 있는지도 함께 점검해 주세요.

8-14: https_listener 필드 정리 검토 — 사용 여부 확인 필요

검증 결과: var.https_listener.type 및 var.https_listener.default_target_group_arn에 대한 참조는 검색되지 않음. 변수 선언은 남아 있음 (terraform/common/alb/https-listener/variables.tf:11). locals에서 default_target_group_arn 설정 존재 (terraform/common/alb/locals.tf:69).

  • 조치: https-listener 모듈 호출부에서 해당 필드가 전달되는지 확인; 사용처가 없으면 https-listener/variables.tf에서 필드 제거 및 locals/문서 정리.

@lvalentine6 lvalentine6 merged commit 70c9f87 into develop Sep 19, 2025
11 checks passed
@lvalentine6 lvalentine6 deleted the hotfix/PRODUCT-282 branch September 19, 2025 19:46
@github-actions
Copy link

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.8.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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants