Skip to content

[fix] prod 프로파일에서 lazy-initialization 제거로 SecurityFilterChain 미등록 문제 해결#190

Merged
geunyong16 merged 1 commit into
mainfrom
fix/189-remove-lazy-init-prod
May 14, 2026
Merged

[fix] prod 프로파일에서 lazy-initialization 제거로 SecurityFilterChain 미등록 문제 해결#190
geunyong16 merged 1 commit into
mainfrom
fix/189-remove-lazy-init-prod

Conversation

@geunyong16
Copy link
Copy Markdown
Collaborator

@geunyong16 geunyong16 commented May 14, 2026

🔖 관련 GitHub Issue

📝 변경 사항

주요 변경 내용

  • application-prod.properties에서 spring.main.lazy-initialization=true 설정 제거
  • 동일 위치에 사유와 후속 대응 가이드를 주석으로 남김

상세 설명

문제

2026-05-14 09:32 KST 프로덕션 EC2 재배포 이후, 모바일 앱의 카카오 로그인 및 Dev 로그인이 모두 실패. EC2에서 직접 curl로 호출해도 모든 /api/auth/* 엔드포인트가 빈 본문 403을 반환. 부팅 로그에 결정적 신호가 출력됨:

WARN  UserDetailsServiceAutoConfiguration : Using generated security password: ...
INFO  InitializeUserDetailsManagerConfigurer : Global AuthenticationManager configured with UserDetailsService bean with name inMemoryUserDetailsManager

→ Spring Boot가 우리 SecurityFilterChain 빈을 감지하지 못하고 폴백 보안(HTTP Basic + inMemoryUserDetailsManager + CSRF on)을 활성화한 상태. 결과적으로 SecurityConfigpermitAll() 설정이 무시되어 모든 POST 요청이 403.

원인

application-prod.properties에 prod 전용으로 설정되어 있던:

spring.main.lazy-initialization=true

이 설정 때문에 사용자 정의 SecurityFilterChain 빈이 lazy 초기화 상태로 등록되며, Spring Boot의 SpringBootWebSecurityConfiguration@ConditionalOnDefaultWebSecurity(= @ConditionalOnMissingBean(SecurityFilterChain.class)) 평가 시점에 사용자 정의 빈의 존재를 감지하지 못해 폴백 보안 체인을 활성화함.

해당 설정은 application.properties/application-local.properties에는 없고 prod에만 존재했기 때문에 로컬에서는 정상 동작하고 프로덕션에서만 재현되었음.

해결

prod 프로파일에서 spring.main.lazy-initialization=true 설정을 제거. SecurityConfig.java 등 코드는 변경하지 않음(코드 자체는 정상).

원래 lazy-init을 도입한 의도(시작 시 Hibernate 6 ANTLR4 파서 메모리 스파이크 방지)는 별도 옵션으로 대응할 수 있도록 주석에 안내를 남김:

  • Hibernate plan cache 한도 (hibernate.query.plan_cache_max_size, plan_parameter_metadata_max_size)
  • Tomcat 스레드 한도 (server.tomcat.threads.max, accept-count)
  • OSIV 비활성화 (spring.jpa.open-in-view=false)

배포 후 EC2 staging에서 실제 메모리 스파이크가 관측되면 위 옵션들로 별도 PR 대응 예정.

✅ 체크리스트

  • PR 제목이 형식에 맞는가? (유형: 작업 요약)
  • 코드가 정상적으로 빌드되는가? (./gradlew test --tests PayCheckApplicationTests BUILD SUCCESSFUL)
  • 새로운 기능에 대한 테스트 코드를 작성했는가? (해당 없음 - 설정 파일 변경)
  • 모든 테스트가 통과하는가?
  • 코드 스타일 가이드를 따랐는가?
  • 관련 문서를 업데이트했는가? (해당 없음)

🔗 관련 PR

🧪 검증

자동 검증

./gradlew test --tests PayCheckApplicationTests
→ BUILD SUCCESSFUL

배포 후 수동 검증

  1. 폴백 로그 부재 확인

    sudo journalctl -u paycheck --since '<배포시각>' \
      | grep -E 'generated security password|inMemoryUserDetailsManager'
    # → 아무것도 출력되지 않아야 함
  2. 로그인 동작 재현

    curl -i -X POST http://localhost:8080/api/auth/kakao/login \
      -H 'Content-Type: application/json' \
      -d '{"kakaoAccessToken":"..."}'
    # → 403이 아닌 정상 응답 또는 의도된 비즈니스 에러
  3. 인증 보호 경로

    curl -i http://localhost:8080/api/users/me
    # → 401 + ApiResponse.error JSON (403 아님, JwtAuthenticationFilter 응답)

🤖 Generated with Claude Code

Summary by CodeRabbit

버그 수정

  • Spring Security의 보안 필터가 올바르게 작동하도록 애플리케이션 초기화 방식이 조정되었습니다.

Review Change Stack

prod 프로파일에 설정된 spring.main.lazy-initialization=true 때문에 사용자 정의
SecurityFilterChain 빈이 lazy 초기화되어, Spring Boot의 SpringBootWebSecurityConfiguration이
@ConditionalOnMissingBean(SecurityFilterChain.class) 평가 시 빈을 감지하지 못하고 폴백
보안(inMemoryUserDetailsManager + HTTP Basic + CSRF)을 활성화. 결과적으로 우리 SecurityConfig의
permitAll 설정이 무시되어 /api/auth/* 경로가 모두 403을 반환했음.

메모리 스파이크 완화 의도는 lazy-init이 아닌 Hibernate plan cache 한도 / Tomcat 스레드 한도 / OSIV 비활성화 등으로 후속 대응한다.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b3dd155d-8128-46e7-a4d1-03b3322401ec

📥 Commits

Reviewing files that changed from the base of the PR and between 7621de9 and a60aa41.

📒 Files selected for processing (1)
  • src/main/resources/application-prod.properties

요약

프로덕션 환경의 Spring Boot 설정에서 spring.main.lazy-initialization=true 속성을 제거하고, 커스텀 SecurityFilterChain 빈의 자동 감지가 지연 초기화로 인해 방해될 수 있음을 설명하는 주석으로 교체했습니다.

변경 사항

Spring Security 설정 복원

Layer / File(s) 요약
지연 초기화 설정 제거 및 설명 주석 추가
src/main/resources/application-prod.properties
spring.main.lazy-initialization=true 설정이 제거되어 Spring Boot의 기본 bean 초기화 순서가 복구되고, 지연 초기화가 커스텀 SecurityFilterChain 빈의 감지를 방해할 수 있음을 설명하는 주석이 추가되었습니다.

예상 코드 리뷰 시간

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 [fix] 유형을 명시하고 'prod 프로파일에서 lazy-initialization 제거로 SecurityFilterChain 미등록 문제 해결'이라는 구체적 요약으로 변경사항을 정확히 반영합니다.
Description check ✅ Passed PR 설명은 템플릿의 모든 주요 섹션(관련 Issue, 변경사항, 상세 설명, 체크리스트)을 완전히 작성했으며 문제-원인-해결 방안을 명확히 기술하고 검증 절차도 포함합니다.
Linked Issues check ✅ Passed PR의 변경사항이 #189의 모든 코딩 관련 요구사항을 충족합니다. application-prod.properties에서 lazy-initialization 설정 제거로 SecurityFilterChain 빈이 정상 로드되어 폴백 보안 문제를 해결하고, /api/auth/* permitAll() 설정이 작동하며, 테스트 통과를 확인했습니다.
Out of Scope Changes check ✅ Passed 설정 파일의 단일 항목 제거와 설명 주석 추가만 수행되어 모든 변경이 #189의 SecurityFilterChain 미등록 문제 해결에 직접 관련되며 범위를 벗어나지 않습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/189-remove-lazy-init-prod

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@geunyong16 geunyong16 merged commit 63e7df7 into main May 14, 2026
2 checks passed
@geunyong16 geunyong16 deleted the fix/189-remove-lazy-init-prod branch May 14, 2026 07:41
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.

[BUG] 프로덕션에서 모든 로그인 엔드포인트가 403 반환 (Spring Security 미적용 추정)

1 participant