Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: #BBB-136 로그인 및 회원가입 시 클라이언트와 서버 간 종단간 암호화 적용 #57

Merged
merged 12 commits into from
Oct 20, 2024

Conversation

platinouss
Copy link
Contributor

@platinouss platinouss commented Sep 19, 2024

작업 개요

  • HTTPS 환경에서도 민감한 데이터를 안전하게 전송하기 위해, 클라이언트와 서버 간 종단간 암호화 적용
  • redis에 10개 정도의 비대칭키를 미리 만들어 두고, 클라이언트에서 PublicKey 요청 시 랜덤으로 하나의 PublicKey를 id와 함께 전달
  • 이후 클라이언트에서 암호화된 request body를 전달하면, Filter에서 복호화를 진행하고 새로운 request를 만들어 다음 Filter에 요청을 위임하도록 하여 기존 Controller 부분의 코드 변경 없이 암·복호화 진행

고민한 점

비대칭 키 갱신 시점에도 유연하게 복호화를 진행하기 (versioning 이용)

Encryption (1)

  • 기존 구조는 클라이언트가 PublicKey를 가져간 상황에서 새로운 비대칭키로 갱신 한 경우, 서버에 다시 PublicKey를 요청해서 암호화 진행 후 재요청을 하게 될 것
  • 복호화를 유연하게 처리하기 위해, 각 비대칭키를 versioning 하여 갱신 시에 새로운 버전으로 값을 업데이트 하고, 이전 버전의 비대칭 키를 가지고 있는 Redis의 Key에 5분의 TTL을 설정

Redis 장애에도 원활한 암·복호화 진행하기 (서버마다 공유되는 비대칭키와 circuit breaker의 fallback method 이용)

Encryption (2)

  • 기존 구조는 Redis 장애 발생 시, 비대칭키를 가져올 수 없어 암·복호화에 실패할 것
  • 따라서, DB에 임시 비대칭 키를 저장해두고, API 서버 실행 시점에서 DB에서 비대칭키를 읽어오고 인메모리에 저장
    • 만약 DB에 저장된 비대칭키 갱신 시에는, 특정 API를 호출하여 DB에서 새로운 버전의 비대칭키를 읽고 인메모리에 저장하도록 구성
  • circuit breaker open 시, 인메모리에 저장된 public key를 전달하는 fallback method가 실행된다. 이때 id는 0으로 구분할 수 있다.
  • Redis가 원활하게 동작할 때와 장애가 발생했을 때 프론트에서 동일한 로직으로 수행되도록 구성

전달 사항

현재 로그인과 회원가입 상황에만 적용됨

참고 자료

circuit breaker 적용을 위한 resilience4j

https://resilience4j.readme.io/docs/circuitbreaker

@platinouss platinouss added the ✨Feat 새로운 기능 추가 label Sep 19, 2024
@platinouss platinouss self-assigned this Sep 19, 2024
@platinouss platinouss marked this pull request as draft September 19, 2024 17:06
@platinouss platinouss force-pushed the feat/e2e_encryption_login_signup#BBB-136 branch 4 times, most recently from cee1eb6 to b5e0cdb Compare September 25, 2024 14:42
@platinouss platinouss marked this pull request as ready for review September 25, 2024 14:43
@platinouss platinouss force-pushed the feat/e2e_encryption_login_signup#BBB-136 branch 2 times, most recently from d4f2d80 to 2993e5c Compare September 25, 2024 23:38
@msjang4 msjang4 self-requested a review September 27, 2024 08:33
Copy link
Contributor

@msjang4 msjang4 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다. 덕분에 Retry & CB패턴에 대해 알아보는 시간을 가질 수 있었네요

Comment on lines +31 to +44
resilience4j:
circuitbreaker:
failure-rate-threshold: 10
slow-call-duration-threshold: 500
slow-call-rate-threshold: 10
wait-duration-in-open-state: 30000
minimum-number-of-calls: 50
sliding-window-size: 100
permitted-number-of-calls-in-half-open-state: 30
retry:
wait-duration: 100
max-attempts: 2
Copy link
Contributor

Choose a reason for hiding this comment

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

이 설정값은 어디서 사용하는 걸까요? class CircuitBreakerProperty에서는 사용하지 않는 것 같아서요

Copy link
Contributor Author

@platinouss platinouss Oct 10, 2024

Choose a reason for hiding this comment

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

CircuitBreakerProperty클래스에 @ConfigurationProperties(prefix = "resilience4j.circuitbreaker")어노테이션 선언을 통해 해당 application.yml의 설정 값을 읽어오게 돼요.
만약 읽어오는데 실패했다면, CircuitBreakerProperty클래스에 선언된 값으로 설정되게 됩니다

…도록 적용

Redis 장애 시, 이미 인메모리에 저장된 서버 간에 공유되는 비대칭키를 사용하도록 하여 항상 로그인 요청이 처리될 수 있도록 보완했습니다.
새로운 버전의 인메모리용 비대칭키가 추가된 경우, 해당 API를 호출하여 DB에서 최신 버전의 비대칭키를 읽어온 후 갱신합니다.
@platinouss platinouss force-pushed the feat/e2e_encryption_login_signup#BBB-136 branch from 2993e5c to f3f695d Compare October 20, 2024 16:50
@platinouss platinouss merged commit a630abd into develop Oct 20, 2024
1 check passed
platinouss added a commit that referenced this pull request Nov 14, 2024
…signup#BBB-136

Feat: #BBB-136 로그인 및 회원가입 시 클라이언트와 서버 간 종단간 암호화 적용
@platinouss platinouss deleted the feat/e2e_encryption_login_signup#BBB-136 branch December 5, 2024 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨Feat 새로운 기능 추가
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants