Skip to content

πŸ”§ [ꡬ성 λ³€κ²½] HTTPS ALB μ„€μ • 및 CORS 도메인 μΆ”κ°€ - #109

Merged
moonjun1 merged 1 commit into
devfrom
feat/aws
Jul 21, 2025
Merged

πŸ”§ [ꡬ성 λ³€κ²½] HTTPS ALB μ„€μ • 및 CORS 도메인 μΆ”κ°€#109
moonjun1 merged 1 commit into
devfrom
feat/aws

Conversation

@moonjun1

@moonjun1 moonjun1 commented Jul 19, 2025

Copy link
Copy Markdown
Member

πŸ”§ HTTPS ALB μ„€μ • 및 ν”„λ‘œλ•μ…˜ 도메인 μ „ν™˜

κ°œμš”

AWS ALB(Application Load Balancer)λ₯Ό ν†΅ν•œ HTTPS μ „ν™˜ 및 ν”„λ‘œλ•μ…˜ 도메인 섀정을 μœ„ν•œ λ°±μ—”λ“œ ꡬ성 λ³€κ²½μž…λ‹ˆλ‹€.

λ³€κ²½ 사항

인프라 변경사항

  • ALB ν”„λ‘μ‹œ 헀더 처리 μ„€μ • μΆ”κ°€ - ALB λ’€μ—μ„œ 정상적인 λ¦¬λ‹€μ΄λ ‰νŠΈ λ™μž‘μ„ μœ„ν•¨
  • 카카였 OAuth λ¦¬λ‹€μ΄λ ‰νŠΈ URI HTTPS둜 λ³€κ²½ - ν”„λ‘œλ•μ…˜ 도메인 api.likelionnews.click μ‚¬μš©
  • CORS 정책에 ν”„λ‘œλ•μ…˜ 도메인 μΆ”κ°€ - ν”„λ‘ νŠΈμ—”λ“œ HTTPS 도메인 ν—ˆμš©

μˆ˜μ •λœ νŒŒμΌλ“€

  • SpringBoot/src/main/resources/application.properties
  • SpringBoot/src/main/java/Baemin/News_Deliver/SecurityConfig.java

상세 λ³€κ²½λ‚΄μš©

application.properties μ„€μ • μΆ”κ°€

# HTTPS ALB ν”„λ‘μ‹œ μ„€μ •
server.forward-headers-strategy=framework
server.tomcat.redirect-context-root=false
server.tomcat.use-relative-redirects=true

# 카카였 OAuth HTTPS λ¦¬λ‹€μ΄λ ‰νŠΈ URI
spring.security.oauth2.client.registration.kakao.redirect-uri=https://api.likelionnews.click/login/oauth2/code/kakao

SecurityConfig.java - CORS 도메인 μΆ”κ°€

configuration.setAllowedOriginPatterns(Arrays.asList(
    "http://localhost:3000",           // 개발용
    "http://localhost:3001",           // 개발용  
    "http://localhost:5173",           // 개발용
    "https://likelionnews.click",      // πŸ†• ν”„λ‘ νŠΈμ—”λ“œ 메인 도메인
    "https://www.likelionnews.click",  // πŸ†• ν”„λ‘ νŠΈμ—”λ“œ www 도메인
    "https://*.amplifyapp.com",        // πŸ†• AWS Amplify 도메인 νŒ¨ν„΄
    "https://merry-crepe-479d93.netlify.app", // κΈ°μ‘΄ ν”„λ‘œν† νƒ€μž… μœ μ§€
    "http://43.201.27.98"             // κΈ°μ‘΄ EC2 IP μœ μ§€
));

μ•„ν‚€ν…μ²˜ ν”Œλ‘œμš°

λ³€κ²½ μ „ (HTTP)

ν΄λΌμ΄μ–ΈνŠΈ β†’ EC2:8080 (HTTP)

λ³€κ²½ ν›„ (HTTPS)

ν΄λΌμ΄μ–ΈνŠΈ β†’ ALB:443 (HTTPS) β†’ EC2:8080 (HTTP)
         β†’ ALB:80 (HTTP) β†’ 301 λ¦¬λ‹€μ΄λ ‰νŠΈ β†’ HTTPS

도메인 ꡬ쑰

  • ν”„λ‘ νŠΈμ—”λ“œ: likelionnews.click (AWS Amplify)
  • λ°±μ—”λ“œ API: api.likelionnews.click (AWS ALB β†’ EC2)
  • SSL μΈμ¦μ„œ: AWS ACM으둜 관리

ν…ŒμŠ€νŠΈ 체크리슀트

배포 μ „ ν…ŒμŠ€νŠΈ

  • μ½”λ“œ 컴파일 확인
  • μ„€μ • 파일 문법 검증
  • Docker λΉŒλ“œ ν…ŒμŠ€νŠΈ

배포 ν›„ ν…ŒμŠ€νŠΈ

  • HTTPS API 접속 ν…ŒμŠ€νŠΈ: https://api.likelionnews.click/api/auth/status
  • HTTP β†’ HTTPS λ¦¬λ‹€μ΄λ ‰νŠΈ 확인: http://api.likelionnews.click
  • ALB λŒ€μƒ κ·Έλ£Ή ν—¬μŠ€μ²΄ν¬ μƒνƒœ 확인
  • 카카였 OAuth 둜그인 ν”Œλ‘œμš° ν…ŒμŠ€νŠΈ
  • CORS μ •μ±… λ™μž‘ 확인

ν…ŒμŠ€νŠΈ λͺ…λ Ήμ–΄

# HTTPS API ν…ŒμŠ€νŠΈ
curl -I https://api.likelionnews.click/api/auth/status

# HTTP λ¦¬λ‹€μ΄λ ‰νŠΈ ν…ŒμŠ€νŠΈ  
curl -I http://api.likelionnews.click/api/auth/status

# CORS ν…ŒμŠ€νŠΈ (λΈŒλΌμš°μ € μ½˜μ†”μ—μ„œ)
fetch('https://api.likelionnews.click/api/auth/status', {mode: 'cors'})

λ‘€λ°± κ³„νš

문제 λ°œμƒ μ‹œ μ¦‰μ‹œ 이전 μ»€λ°‹μœΌλ‘œ λ‘€λ°± κ°€λŠ₯:

git reset --hard HEAD~1
git push --force origin master
docker-compose down && docker-compose up -d --build

κ΄€λ ¨ 인프라 ꡬ성

  • AWS ALB: likelionnews-alb
  • λŒ€μƒ κ·Έλ£Ή: likelionnews-backend
  • ACM μΈμ¦μ„œ: api.likelionnews.click
  • Route 53: A λ ˆμ½”λ“œ api.likelionnews.click β†’ ALB

사전 μ™„λ£Œ μž‘μ—…

  • ALB 생성 및 μ„€μ • μ™„λ£Œ
  • ACM SSL μΈμ¦μ„œ λ°œκΈ‰ μ™„λ£Œ
  • Route 53 DNS μ„€μ • μ™„λ£Œ
  • EC2 λ³΄μ•ˆ κ·Έλ£Ή μˆ˜μ • μ™„λ£Œ
  • 카카였 개발자 μ½˜μ†” λ¦¬λ‹€μ΄λ ‰νŠΈ URI μΆ”κ°€

λ¨Έμ§€ ν›„ μž‘μ—… μ˜ˆμ •

  • 카카였 개발자 μ½˜μ†”μ—μ„œ μƒˆ λ¦¬λ‹€μ΄λ ‰νŠΈ URI μΆ”κ°€
  • ν”„λ‘ νŠΈμ—”λ“œ ν™˜κ²½ λ³€μˆ˜ μ—…λ°μ΄νŠΈ (REACT_APP_API_URL)
  • AWS Amplify ν”„λ‘ νŠΈμ—”λ“œ 배포 및 도메인 μ—°κ²°

κΈ°λŒ€ 효과

  • βœ… λ³΄μ•ˆ κ°•ν™”: HTTPS μ•”ν˜Έν™” 톡신
  • βœ… SEO κ°œμ„ : HTTPSλŠ” 검색 μ—”μ§„ λž­ν‚Ή μš”μ†Œ
  • βœ… μ‚¬μš©μž 신뒰도: λΈŒλΌμš°μ € λ³΄μ•ˆ κ²½κ³  제거
  • βœ… ν™•μž₯μ„±: ALBλ₯Ό ν†΅ν•œ λ‘œλ“œ λ°ΈλŸ°μ‹± 기반 마련
  • βœ… ν”„λ‘œλ•μ…˜ μ€€λΉ„: μ‹€μ œ 도메인을 μ‚¬μš©ν•œ μ„œλΉ„μŠ€ 운영
  1. ν˜Έν™˜μ„± 확인: κΈ°μ‘΄ 개발 ν™˜κ²½ 섀정이 μœ μ§€λ˜λŠ”μ§€

Summary by CodeRabbit

  • μƒˆλ‘œμš΄ κΈ°λŠ₯

    • ν”„λ‘ νŠΈμ—”λ“œ 메인 도메인, www μ„œλΈŒλ„λ©”μΈ, Amplify μ•± 도메인 νŒ¨ν„΄μ„ ν—ˆμš©λœ CORS μ˜€λ¦¬μ§„ λͺ©λ‘μ— μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.
  • 버그 μˆ˜μ •

    • OAuth2 카카였 ν΄λΌμ΄μ–ΈνŠΈ λ¦¬λ””λ ‰νŠΈ URIλ₯Ό 도메인 기반 HTTPS μ£Όμ†Œλ‘œ λ³€κ²½ν–ˆμŠ΅λ‹ˆλ‹€.
  • 기타 μž‘μ—…

    • Tomcat λ¦¬λ””λ ‰νŠΈ κ΄€λ ¨ 섀정이 μΆ”κ°€λ˜μ–΄ λ¦¬λ””λ ‰νŠΈ λ™μž‘μ΄ κ°œμ„ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

- ALB ν”„λ‘μ‹œ 헀더 처리 μ„€μ • μΆ”κ°€
- 카카였 OAuth λ¦¬λ‹€μ΄λ ‰νŠΈ URI HTTPS둜 λ³€κ²½
- CORS에 ν”„λ‘ νŠΈμ—”λ“œ HTTPS 도메인 μΆ”κ°€
- Amplify 도메인 νŒ¨ν„΄ μΆ”κ°€"
@coderabbitai

coderabbitai Bot commented Jul 19, 2025

Copy link
Copy Markdown

Walkthrough

CORS ν—ˆμš© μ˜€λ¦¬μ§„ λͺ©λ‘μ΄ ν™•μž₯λ˜μ—ˆκ³ , OAuth2 Kakao λ¦¬λ””λ ‰μ…˜ URIκ°€ 도메인 기반 HTTPS μ£Όμ†Œλ‘œ λ³€κ²½λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ Tomcat λ¦¬λ””λ ‰μ…˜ κ΄€λ ¨ μ„œλ²„ 속성이 μΆ”κ°€ 및 μˆ˜μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 곡개 μ—”ν‹°ν‹° μ‹œκ·Έλ‹ˆμ²˜λ‚˜ μ™ΈλΆ€ APIμ—λŠ” λ³€ν™”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

Changes

파일/경둜 λ³€κ²½ μš”μ•½
SpringBoot/src/main/java/Baemin/News_Deliver/SecurityConfig.java CORS ν—ˆμš© μ˜€λ¦¬μ§„ λͺ©λ‘μ— likelionnews.click, www.likelionnews.click, *.amplifyapp.com μΆ”κ°€
SpringBoot/src/main/resources/application.properties Kakao OAuth2 λ¦¬λ””λ ‰μ…˜ URIλ₯Ό 도메인 HTTPS둜 λ³€κ²½, Tomcat λ¦¬λ””λ ‰μ…˜ κ΄€λ ¨ 속성 2개 μΆ”κ°€

Possibly related PRs

✨ Finishing Touches
  • πŸ“ Generate Docstrings

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (2)
SpringBoot/src/main/resources/application.properties (1)

87-88: Tomcat redirect μ˜΅μ…˜β€”μƒλŒ€/μ ˆλŒ€ URI 혼용 μœ„ν—˜

server.tomcat.redirect-context-root=false
server.tomcat.use-relative-redirects=true

두 μ˜΅μ…˜μ„ λ™μ‹œμ— ν™œμ„±ν™”ν•˜λ©΄ λ‹€μŒ 영ν–₯이 μžˆμŠ΅λ‹ˆλ‹€.

  • μ•± λ‚΄λΆ€μ—μ„œ sendRedirect("/") 같은 μ ˆλŒ€ path λ₯Ό ν˜ΈμΆœν•  경우, Location: /(μƒλŒ€) 둜 λ‚΄λ €κ°‘λ‹ˆλ‹€. ALB 뒀라면 μ˜λ„ν•œ HTTPS 도메인을 λΈŒλΌμš°μ €κ°€ κ·ΈλŒ€λ‘œ μ‚¬μš©ν•˜λ―€λ‘œ μž₯점이 μžˆμ§€λ§Œ,
  • μ™ΈλΆ€ λ„λ©”μΈμœΌλ‘œμ˜ redirect(예: Swagger UI Oauth2 flow) λŠ” μƒλŒ€-URI 둜 μ „ν™˜λ˜λ©΄μ„œ 였λ₯˜κ°€ λ‚  수 μžˆμŠ΅λ‹ˆλ‹€.

운영 ν™˜κ²½ μ „λ°˜μ—μ„œ μƒλŒ€ redirect 만으둜 μΆ©λΆ„ν•œμ§€ 확인이 ν•„μš”ν•©λ‹ˆλ‹€. 특수 path redirect κ°€ μžˆλ‹€λ©΄ μ ˆλŒ€ URI μœ μ§€κ°€ μ•ˆμ „ν•  수 μžˆμœΌλ‹ˆ μž¬κ²€ν†  ꢌμž₯λ“œλ¦½λ‹ˆλ‹€.

SpringBoot/src/main/java/Baemin/News_Deliver/SecurityConfig.java (1)

128-138: CORS ν—ˆμš© 도메인 ν•˜λ“œμ½”λ”©β€”μœ μ§€λ³΄μˆ˜ 및 λ³΄μ•ˆ μΈ‘λ©΄ κ°œμ„  μ œμ•ˆ

λ³€κ²½ 자체(μ‹ κ·œ 도메인 3μ’… μΆ”κ°€)λŠ” νƒ€λ‹Ήν•©λ‹ˆλ‹€. λ‹€λ§Œ:

  1. νŒ¨ν„΄ "https://*.amplifyapp.com" 은 Spring 5.3 / Boot 2.7 μ΄μƒμ—μ„œλ§Œ λ§€μΉ­λ©λ‹ˆλ‹€. ν•˜μœ„ 버전이면 λ¬΄μ‹œλ˜λ‹ˆ ν˜„μž¬ λŸ°νƒ€μž„ 버전을 λ‹€μ‹œ 확인해 μ£Όμ„Έμš”.
  2. configuration.setAllowCredentials(true) λ₯Ό μ‚¬μš©ν•˜λ©΄μ„œ μ™€μΌλ“œμΉ΄λ“œ νŒ¨ν„΄μ„ ν—ˆμš©ν•˜λ©΄ λΈŒλΌμš°μ € μŠ€νŽ™μƒ λ¬Έμ œλŠ” μ—†μ§€λ§Œ, 도메인 μŠ€ν‘Έν•‘ μœ„ν—˜μ„ ν‚€μšΈ 수 μžˆμŠ΅λ‹ˆλ‹€. Amplify μ•±λ³„λ‘œ μ„œλΈŒλ„λ©”μΈμ„ μ œν•œμ μœΌλ‘œ λͺ…μ‹œν•˜κ±°λ‚˜, 배포 ν›„ Access-Control-Allow-Origin 헀더가 μ˜ˆμƒμΉ˜ μ•Šκ²Œ null 둜 λ–¨μ–΄μ§€μ§€ μ•ŠλŠ”μ§€ 점검이 ν•„μš”ν•©λ‹ˆλ‹€.
  3. μ°¨ν›„ 도메인 λ³€κ²½ μ‹œ μ½”λ“œλ₯Ό μˆ˜μ •Β·λ°°ν¬ν•΄μ•Ό ν•˜λ―€λ‘œ, application.yaml 둜 λͺ©λ‘μ„ μ™ΈλΆ€ν™”ν•˜κ±°λ‚˜ @Value μ£Όμž… ν›„ split(",") 둜 μ²˜λ¦¬ν•˜λŠ” 방식이 μœ μ§€λ³΄μˆ˜μ— μœ λ¦¬ν•©λ‹ˆλ‹€.

μ˜ˆμ‹œ λ¦¬νŒ©ν„°λ§:

-configuration.setAllowedOriginPatterns(Arrays.asList(
-    "https://likelionnews.click",
-    ...
-));
+configuration.setAllowedOriginPatterns(
+    Arrays.asList(corsAllowedOrigins.split(",")));

application.properties:

cors.allowed-origins=https://likelionnews.click,...
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between eeb86d7 and 6765d49.

πŸ“’ Files selected for processing (2)
  • SpringBoot/src/main/java/Baemin/News_Deliver/SecurityConfig.java (1 hunks)
  • SpringBoot/src/main/resources/application.properties (2 hunks)
πŸ”‡ Additional comments (1)
SpringBoot/src/main/resources/application.properties (1)

47-47: 카카였 Redirect URI λ³€κ²½β€”μš΄μ˜/개발 μ½˜μ†” λͺ¨λ‘ λ°˜λ“œμ‹œ 동기화 ν•„μš”

https://api.likelionnews.click/login/oauth2/code/kakao 둜 μˆ˜μ •ν•˜μ…¨λŠ”λ°,

  1. 카카였 개발자 μ½˜μ†”μ˜ Redirect URI λͺ©λ‘μ— λ™μΌν•œ 값이 μΆ”κ°€-승인돼 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.
  2. ALB β†’ EC2 ꡬ간이 HTTP(80)인 경우, X-Forwarded-Proto 헀더가 HTTPS 둜 전달돼야 Spring Security κ°€ μ ˆλŒ€ URI λ¦¬λ‹€μ΄λ ‰νŠΈλ₯Ό μ˜¬λ°”λ₯΄κ²Œ κ³„μ‚°ν•©λ‹ˆλ‹€. 이미 server.forward-headers-strategy=framework λ₯Ό μΌœμ…¨μ§€λ§Œ, Nginx / ALB μͺ½μ— X-Forwarded-* 헀더 제거 정책이 μ—†λŠ”μ§€ ν•œλ²ˆ 더 확인해 μ£Όμ„Έμš”.
    λ¬Έμ„œν™”λ§Œ λ˜μ–΄ 있으면 LGTM μž…λ‹ˆλ‹€.

@moonjun1
moonjun1 merged commit f053e64 into dev Jul 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant