본문 바로가기
IT 둘러보기

카카오 광고 플랫폼 MSA 적용 사례 및 API Gateway와 인증 구현에 대한 소개

by 날고싶은커피향 2023. 10. 27.

  • 1. 카카오 광고 플랫폼 MSA 적용사례 (API Gateway 도입과 인증 구현) 황민호(robin.hwang) DSP개발파트
  • 2. Kakao Moment
  • 3. 카카오 광고 플랫폼 (Moment) 노출 지면은 지속적으로 확대 예정입니다 카카오 이용자가 있는 곳이라면 어디든 찾아가서 광고를 노출합니다. 카카오 서비스를 비롯한 주요 네트워크 지면에 노출 됩니다.
  • 4. 카카오 광고 플랫폼 (Moment) 카카오 광고 플랫폼은 광고 등록부터 광고 성과 분석까지 가능한 원스탑 시스템입니다 카카오 광고 플랫폼은 광고 목적 최적화를 지원합니다 카카오 광고 플랫폼은 오디언스 타겟팅을 지원합니다 캠페인 광고 목적 선택 광고그룹 타겟팅 설정 예산 설정 광고 노출 심사 완료 시 보고서 광고 성과 분석 소재 광고 소재 등록
  • 5. 디지털 광고 시스템 SUPPLY SIDE
 Platform AUDIENCE AD INVESTMENT DSP DSP SSP AD EXCHANGE SSP SSP DATA EXCHANGE / DATA LAKE / DMP Header Bidding DEMAND SIDE
 Platform Advertiser Agency . Publisher DSP ,
  • 6. 카카오 광고 DSP Moment Agency Admin Review , 광고주를 위한 서비스 광고 등록 및 정산 보고서 등 대행사를 위한 서비스 광고계정 영업권 관리 등 광고 플랫폼 관리 광고 소재 심사 광고주 . 대행사 3 관리자 4 심사자
  • 7. 카카오 광고 DSP Moment Agency Admin Review Ad Server Billing Report Ranking Targeting API Server Related Support Aggregation
  • 8. 카카오 광고 DSP Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search API Server Related Support RabbitMQ MySQL Kakao Auth
  • 9. 카카오 광고 DSP Moment Agency Admin Review Aggregation Billing Report API Server Related Support A
 P I
 G
 A T E W A Y Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search RabbitMQ MySQL Kakao Auth Ad Server
  • 10. API Gateway Authentication Authorization MSA
  • 11. API Gateway
  • 12. API Gateway 
 
 Logging 
 
 인증/인가 
 
 Aggregation 
 
 Mediation API Routing 
 
 Statistic 
 
 Limitation API Gateway
  • 13. AWS API Gateway API Gateway ZUUL API Gateway
  • 14. AWS API Gateway API Gateway API Gateway 선택 Spring Cloud Services Spring Cloud ZUUL Spring Framework Simple Netflix ZUUL
  • 15. AWS API Gateway API Gateway 선택 ZUUL
  • 16. Netflix OSS (Open Source Software center) image : http://lucasmatt.com/2017/08/22/spring-microservices/
  • 17. Spring Cloud with Netflix OSS Service A Hystrix RibbonEureka Feign Gateway Hystrix RibbonEureka Zuul OAuth2 Service Discovery Eureka Monitor Service Dashboard Routing Proxy Zuul Client Trace Service zipkin Config Service Spring-Config Rest Client Feign Load Balancing Ribbon Circuit Breaker Hystrix Cloud BusCloud StreamCloud SecurityOAuth2 Service A Hystrix RibbonEureka Feign Service A Hystrix RibbonEureka Feign Service B Hystrix RibbonEureka Feign Service B Hystrix RibbonEureka Feign Service B Hystrix RibbonEureka Feign
  • 18. 그렇다면.. 카카오 광고 DSP 구성은? Moment Agency Admin Review , 광고주 . 대행사 3 관리자 4 심사자
  • 19. Review Admin Agency Moment 그렇다면.. 카카오 광고 DSP 구성은? Moment Agency Admin Review API GATEWAY (Zuul) L7 L7 L7 L7 zuul: routes: moment: url: http://moment-api:8080 agency: url: http://agency-api:8080 admin: url: http://admin-api:8080 review: url: http://review-api:8080 application.yml , 광고주 . 대행사 3 관리자 4 심사자
  • 20. Review Admin Agency Moment 그렇다면.. 카카오 광고 DSP 구성은? Moment Agency Admin Review API GATEWAY (Zuul) L7 L7 L7 L7 Review AggregationL7 zuul: routes: moment: url: http://moment-api:8080 agency: url: http://agency-api:8080 admin: url: http://admin-api:8080 review: url: http://review-api:8080 application.yml aggregation: url: http://aggregation-api:8080 , 광고주 . 대행사 3 관리자 4 심사자
  • 21. 잘 돌아가던 어느날.. (구성이 뭔가 빈약하긴 하지만) 서비스 장애
  • 22. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL
  • 23. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL
  • 24. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL OOM발생
  • 25. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL OOM발생 Timeout
  • 26. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL OOM발생 Timeout
  • 27. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL OOM발생 Timeout Connection 증가
  • 28. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL RestTemplate connection timeout : 5 sec read timeout : 10 sec connection request timeout : 0 (default) OOM발생 Timeout Connection 증가
  • 29. 서비스 장애 원인 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL RestTemplate connection timeout : 5 sec read timeout : 10 sec connection request timeout : 0 (default) -> 5 sec OOM발생 Timeout Connection 증가
  • 30. Circuit Breaker(Hystrix) 적용 image : http://lucasmatt.com/2017/08/22/spring-microservices/
  • 31. Circuit Breaker(Hystrix) 적용 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL H Y S T R I X
  • 32. Circuit Breaker(Hystrix) 적용 Moment Agency Admin Review Aggregation Ad Server Billing Report Batch Notification Ranking Targeting Plus Friends CTS Tenth Hadoop Elastic Search Kakao Account API Server Related Support G
 A T E W A Y RabbitMQ MySQL H Y S T R I X Isolation Circuit Open!
  • 33. Eureka와 Ribbon은? image : http://lucasmatt.com/2017/08/22/spring-microservices/
  • 34. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon zuul: routes: moment: path: /moment/** serviceId: moment agency: path: /agency/** serviceId: agency moment: ribbon: listOfServices: http://moment- api-01:8080, http://moment-api-02:8080,.. agency: ribbon: listOfServices: http://agency-api-01:8080, http://agency-api-02:8080,.. application.yml ribbon: eureka: enabled: false H Y S T R I X
  • 35. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon zuul: threadPool: useSeparateThreadPools: true ribbonIsolationStrategy: THREAD hystrix: threadpool: default: coreSize: 10 maximumSize: 20 command: default: circuitBreaker: requestVolumeThreshold: 10 errorThresholdPercentage: 50 moment: circuitBreaker: requestVolumeThreshold: 20 errorThresholdPercentage: 50 application.yml H Y S T R I X metrics.rollingStats.timeInMilliseconds : 감시 시간, 기본값 10초 circuitBreaker.requestVolumeThreshold : 감시 시간 내 요청 수, 기본값 20 circuitBreaker.errorThresholdPercentage : 요청 대비 오류율, 기본값 50 10초이내에 발생한 요청 20번 동안 50% 오류 발생시 Circuit을 Open
  • 36. 서버 내리니까 에러나는데..? 유레카 없이 로드 밸런싱 안된건가?
  • 37. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon H Y S T R I X
  • 38. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon H Y S T R I X
  • 39. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon H Y S T R I X
  • 40. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon H Y S T R I X
  • 41. G
 A T E W A Y Review Admin Agency Moment Hystrix + Ribbon 구성 Moment Agency Admin Review Ribbon Ribbon Ribbon Ribbon Review AggregationRibbon ????? H Y S T R I X
  • 42. G
 A T E W A Y Moment Ribbon - Load Balancing & Fault tolerance Moment Ribbon H Y S T R I X
  • 43. G
 A T E W A Y Ribbon - Load Balancing & Fault tolerance Ribbon Default: Round Robin API 3 API 2 API 1 API 4 H Y S T R I X
  • 44. G
 A T E W A Y Ribbon - Load Balancing & Fault tolerance Ribbon Default: Round Robin API 3 API 2 API 1 API 4 H Y S T R I X
  • 45. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon API 1 API 4 Default: Round Robin circuit open! timeout Exception??H Y S T R I X
  • 46. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon API 1 API 4 Default: Round Robin circuit open! timeout Exception??H Y S T R I X
  • 47. Ribbon - Load Balancing & Fault tolerance RibbonHYSTRIX timeout (읽기시간 + 커넥션시간) * 재시도횟수 * 재시도 서버수 moment: ribbon: MaxAutoRetries: 1 # Retry 횟수 MaxAutoRetriesNextServer: 1 # Retry할 (다음) 서버 수 OkToRetryOnAllOperations: true # 모든 operation에 retry 유무 ServerListRefreshInterval: 2000 # 서버 갱신 시간 ConnectTimeout: 3000 # connection timeout ReadTimeout: 3000 # read timeout listOfServers: execution: isolation: thread: timeoutInMilliseconds: 1000 ribbonTimeout = (ribbonReadTimeout + ribbonConnectTimeout) * (maxAutoRetries + 1) * (maxAutoRetriesNextServer + 1) > timeout
  • 48. Ribbon - Load Balancing & Fault tolerance RibbonHYSTRIX timeout (읽기시간 + 커넥션시간) * 재시도횟수 * 재시도 서버수 moment: ribbon: MaxAutoRetries: 0 # Retry 횟수 MaxAutoRetriesNextServer: 0 # Retry할 (다음) 서버 수 OkToRetryOnAllOperations: true # 모든 operation에 retry 유무 ServerListRefreshInterval: 2000 # 서버 갱신 시간 ConnectTimeout: 1000 # connection timeout ReadTimeout: 2000 # read timeout listOfServers: execution: isolation: thread: timeoutInMilliseconds: 5000 ribbonTimeout = (ribbonReadTimeout + ribbonConnectTimeout) * (maxAutoRetries + 1) * (maxAutoRetriesNextServer + 1) > timeout 해결안됨
  • 49. Ribbon - Load Balancing & Fault tolerance RibbonHYSTRIX timeout (읽기시간 + 커넥션시간) * 재시도횟수 * 재시도 서버수 ribbonTimeout = (ribbonReadTimeout + ribbonConnectTimeout) * (maxAutoRetries + 1) * (maxAutoRetriesNextServer + 1) > timeout moment: ribbon: MaxAutoRetries: 1 # Retry 횟수 MaxAutoRetriesNextServer: 1 # Retry할 (다음) 서버 수 OkToRetryOnAllOperations: true # 모든 operation에 retry 유무 ServerListRefreshInterval: 2000 # 서버 갱신 시간 ConnectTimeout: 3000 # connection timeout ReadTimeout: 3000 # read timeout listOfServers: execution: isolation: thread: timeoutInMilliseconds: 1000
  • 50. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon H Y S T R I X API 1 API 4 Load Balancer moment: ribbon: listOfServers: ServerListRefreshInterval LoadBalancer는 Eureka를 사용중일 경우 서버 목록을 갱신하며 사용하지 않을 때는 property 파일의 서버 목록을 주기 적으로 갱신한다 이때 서버 상태를 체크하지 않음
  • 51. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon H Y S T R I X API 1 API 4 Load Balancer moment: ribbon: listOfServers: ServerListRefreshInterval LoadBalancer는 Eureka를 사용중일 경우 서버 목록을 갱신하며 사용하지 않을 때는 property 파일의 서버 목록을 주기 적으로 갱신한다 이때 서버 상태를 체크하지 않음Ping 서버 목록을 주기적으로 Ping 을 날려서 리스트에서 제외시키는 별도의 작업을 수 행한다 NFLoadBalancerPingInterval (default 30 sec) 이때 default가 dummyPing 인데 isAlive( ) 에서 무조건 true로 리턴
  • 52. G
 A T E W A Y Ribbon - Load Balancing & Fault tolerance H Y S T R I X moment: ribbon: NFLoadBalancerPingClassName: com.kakao.dsp.ServerAlivePing NFLoadBalancerRuleClassName: com.netflix.loadbalancer.AvailabilityFilteringRule # round robin 방식을 기본으로 하되 서버가 현재 처리가능한 상태인지 체크(ping)한다 NFLoadBalancerPingInterval: 3 #sec import com.netflix.loadbalancer.PingUrl; public class ServerAlivePing extends PingUrl { @Override public String getPingAppendString() { return "/alive"; } } Dummy ping -> PingUrl Round Robin -> AvailabilityFilteringRule
  • 53. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon API 1 API 4 Default: Round Robin 서버 목록 제외 H Y S T R I X
  • 54. G
 A T E W A Y API 3 Ribbon - Load Balancing & Fault tolerance API 2 Ribbon API 1 API 4 Default: Round Robin 서버 목록 제외 H Y S T R I X
  • 55. 서버 요청 제한은 어떻게 하지? Open API 도 만들어야 하는데...
  • 56. 2018.06 GA Release Filter Predicate Spring Flux Limit Rate Spring Cloud Non-Blocking Websocket support Spring Framework 5 2018.05 Release Netty Server Http/2 Protection Limit Rate Websocket support Origin Concurrency API Gateway ZUUL API Gateway ZUUL2 Spring Cloud Gateway Blocking API Servelet 2.5 Websocket not support
  • 57. API Spring Cloud Gateway - Rate Limit 예제 @Bean public RouteLocator myRoutes(RouteLocatorBuilder builder) { return builder.routes() .route(p -> p .path(“/api/**”) .filters(f -> f.requestRateLimiter(r -> { r.setRateLimiter(new RedisRateLimiter(10, 20)) }).uri(“http://moment.kakao.com/api”)) .build(); } // HTTP 429 - Too Many Requests https://en.wikipedia.org/wiki/Token_bucket Token_bucket redis-rate-limiter.replenishRate : drop없이 사용자당 처리 가능한 초당 요청 수 redis-rate-limiter.burstCapacity : 사용자당 허용된 초당 요청 수 (0이면 모두 블럭)
  • 58. Zuul Pre filter 라우팅 전 실행 logging 및 인증 등 처리 Routing Filter 요청에 대한 라우팅 처리 Post Filter 라우팅 후 실행 사용자 정의 헤더 추가/제거 통계 및 matrix 수집 Error Filter 에러 발생시 핸들링 Http ResponseHttp Request HTTP Request Pre Filter Routing Filter Post Filter Custom Filter API Servers Error Filter
  • 59. Netty Server Handlers Zuul2 Netty Handlers 네트워크 프로토콜, 웹서버, Connection 관리, 프록시 작업 Inbound Filter 요청을 proxy 하기전 처리 인증, 라우팅, Request 변경 등 Endpoint Filter 정적 응답 반환 요청을 백엔드 서비스로 프록시 Outbound Filter 응답이 반환된 후 실행 gziping, matrix 사용자 정의 헤더 추가/제거 ResponseRequest Internet Endpoint Filter API Servers Netty Client Handlers Outbound Filter Inbound Filter Inbound Filter Inbound Filter Outbound Filter Outbound Filter 기존 Zuul 과 유사한 구조, Netty 적용
  • 60. Spring Cloud Gateway Gateway Handler Mapping 경로와 일치하는지 판단 Gateway Web Handler 요청과 관련된 필터 체인을 통해 요청을 전송 Filter 필터는 프록시 요청이 보내지기 전후에 나뉘어서 로직 수행 Proxy Filter 프록시 요청이 처리될때 수행 Gateway Client Gateway Handler Mapping Proxied Service Gateway Web Handler Filter Filter Filter Proxy Filter Predicate Filter Predicat와 Filter로 모든 요청 처리
  • 61. Spring Cloud Gateway PredicateFactory After Before Between Cookie Header Host Remote Address Method Path Query spring: cloud: gateway: routes: - id: foo_route uri: lb://foo predicates: - After=2018-09-04T14:00:00.000+09:00[Asia/Seoul] - Cookie=chocolate, ch.p - Header=X-Request-Id, d+ - Host=**.foo.org - RemoteAddr=192.168.1.1/24 - Method=GET - Path=/foo/{segment} - Query=foo, ba - Query=baz - Cookie=chocolate, ch.p Spring WebFlux의 HandlerMapping 의 일부를 적용하여 라우팅을 표현 합니다
  • 62. Spring Cloud Gateway FilterFactory {Add|Remove}RequestHeader {Add|Remove}RequestParameter {Add|Remove}ResponseHeader SetStatus SetResponseHeader SecureHeaders PreserveHostHeader Hystrix RequestRateLimiter RedirectTo PrefixPath RewritePath SetPath StrixPrefix SaveSession spring: cloud: gateway: routes: - id: foo_route uri: lb://foo filters: - AddRequestHeader=X-Request-Foo, Bar - AddRequestParameter=foo, bar - AddResponseHeader=X-Response-Foo, Bar - SetStatus=401 - SetResponseHeader=X-Response-Foo, Bar - PreserveHostHeader - Hystrix=myCommandName - RequestRateLimiter=10, 50, userKeyResolver - RedirectTo=302, http://kakao.com - PrefixPath=/mypath - RewritePath=/consumingserviceendpoint, / backingserviceendpoint - SetPath=/{segment} - StripPrefix=2 - SaveSession 필터를 통해 HTTP 요청이나 응답 데이터를 필터링하여 수정합니다
  • 63. API Gateway Authentication Authorization MSA
  • 64. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 고정 세션관리
 (Sticky Session) 세션 VS 토큰
  • 65. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 서버 특정 사용자의 모든 요청이 동일한 서버로 전송 로드 밸런서에 의해 강제 리로드시 모든 사용자 의 세션데이터가 손실되는 위험 존재
  • 66. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 서버 각 인스턴스가 모든 세션 데이터를 저장하고 네트워크를 통해 동기화됨 인스턴스가 증가할 수록 많은 대역폭이 필요해짐
  • 67. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 서버 공유 세션 저장소에서 사용자 데이터를 엑세스 가용성과 확장성이 좋은편 세션 저장소에 대한 보호 매커니즘이 필요 세션 복제
 (Session Replication)
  • 68. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 서버 인증 정보를 사용자 브라우저에 저장 보통 쿠키 형태로 저장됨 위,변조가 불가하도록 암호화 필요 시스템마다 인증처리 필요 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage)
  • 69. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) 클라이언트 토큰 SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 SSO
 서버 사용자는 한번 로그인 하면 다른 여러 시스템에 추가 인증프로세스 없이 접근 가능 유저가 접근시마다 SSO 서버와 상호 작용 필요 인증을 위한 반복적인 네트워크 트래픽을 사용 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage)
  • 70. 마이크로 서비스 인증 및 권한 부여 방법 분산 세션 관리 고정 세션관리
 (Sticky Session) SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 서버 서버 게이트웨이에서 인증정보 처리 위,변조가 불가하도록 암호화 필요 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 Gate way
  • 71. 카카오 광고 플랫폼 (moment) 인증 분산 세션 관리 고정 세션관리
 (Sticky Session) SSO (Single Sign-On) API게이트웨이를 통한 클라이언트 토큰 세션 복제
 (Session Replication) 중앙 집중식 세션
 (Centralized Session Storage) 클라이언트 토큰 G
 A T E W A Y Admin Agency Moment Aggregation Billing Report
  • 72. 카카오 광고 플랫폼 (moment) 인증 Admin Agency Moment Aggregation Billing Report G
 A T E W A Y 로그인 F R O N T Kakao Account /login/moment cookie JWT 광고계정 생성 POST /moment/adAccounts
  • 73. JWT (JSON Web Token) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG 9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
  • 74. JWT (JSON Web Token) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG 9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c base64enc({ “alg”: “HS256”, “typ”: “JWT” }) Header
  • 75. JWT (JSON Web Token) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG 9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c base64enc({ “alg”: “HS256”, “typ”: “JWT” }) Header base64enc({ “key1”: “value1”, “key2”: “value2”, “exp”: “1426420800” }) Payload
  • 76. JWT (JSON Web Token) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG 9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c base64enc({ “alg”: “HS256”, “typ”: “JWT” }) Header base64enc({ “key1”: “value1”, “key2”: “value2”, “exp”: “1426420800” }) Payload HMACSHA256({ base64enc(header) + ‘.’ + base64enc(payload) , secretKey }) Signature
  • 77. JWT (JSON Web Token) 수평으로 쉽게 확장 가능 세션방식의 인증의 경우 중앙 
 세션 스토리지 시스템이 필요함, Sticky session방식은 비용증대 유지 보수 및 디버그 용이 Base64 방식으로 데이터 인코딩되 어 웹 토큰 자체에 포함됨 RESTful 서비스에 적합 쿠키방식의 경우 쿠키의 출처가 된 도메인에 대해서만 사용할 수 있는 단점 해소 보안성 암호화 알고리즘으로 암호화하여 
 클라이언트 변조를 막음 특정IP 주소로 JWT발행 및 브라우 저 핑거 프린팅 등을 사용하여 토큰 탈취에 따른 보안 강화 토큰 자체 만료시간 기술 토큰 만료시간을 미리 알고 갱신 요청을 할 수 있음 JSON Web Token은 디지털 서명을 통해 확인하고 신뢰할 수 있는 정보를 보내는데 사용됩니다.
  • 78. 카카오 광고 플랫폼 (moment) 인증 Admin Agency Moment Aggregation Billing Report G
 A T E W A Y 로그인 F R O N T Kakao Account /login/moment cookie JWT 광고계정 생성 POST /moment/adAccounts
  • 79. 카카오 광고 플랫폼 (moment) 인증 Access Refresh Refresh Token Access Token • 자원에 직접 Access하는데 필요한 정보를 포함 • 클라이언트의 권한 부여 여부를 판단 • 만료날짜가 있으며 토큰 수명이 짧음 • Access Token을 재발급 하는데 필요한 정보를 포함 • 만료될 수 있으며 일반적으로 오랜기간 사용됨 • 누출되지 않도록 엄격한 관리가 필요함 • 발급된 IP 기준으로 제한을 두거나 브라우저 핑거프린터 정보등을 통해 
 유효성 확인 필요 . ,
  • 80. 카카오 광고 플랫폼 (moment) 인증 Access Refresh Refresh Token Access Token • ID • 서비스Type • 사용자정보 • 광고계정ID • 권한 정보 • 생성시간 • 만료시간 • ID • 서비스Type • IP정보 • 생성시간 • 만료시간 . , Admin Agency Moment Aggregation Billing Report G
 A T E W A Y Gateway에서 header 로 변환해서 처리
  • 81. 카카오 광고 플랫폼 (moment) 인가 리소스 서버 리소스 서버 인증서버 G
 A T E W A Y 인증요청 권한부여 role={member} role={member} 응답 권한없음 일반적으로는 별도 인증서버를 통해 권한을 획득하고, 리소스 서버에서 권한 체크를 한다
  • 82. 카카오 광고 플랫폼 (moment) 인가 리소스 서버 리소스 서버 인증서버 G
 A T E W A Y 인증요청 권한부여 role={member} 보고서 조회 role={member} 멤버 승인 응답 권한없음 카카오 광고 플랫폼에서는 게이트웨이에서 권한을 통합관리 하고 있음 보고서 조회 응답
  • 83. 카카오 광고 플랫폼 (moment) 인가 Gateway에서 권한은 알아서 해주세요 1. 서비스별 권한 정의 2. API 서버들 URL PATH 수집 3. 수집된 URL PATH별로 Spring Security에 권한 맵핑 실행 고민 1. 계속 추가되는 API, 계속 변경되는 권한을 계속 적용해야 하나? (Resource 소유권 혹은 Resource Boundary 체크는 Gateway에서 힘듬) 2. Gateway에서 인증정보를 전부 알고 있어야 하나?
  • 84. 로그아웃 했는데도 ...? JWT 특성상 자체 만료시간이 기술되어 있으므로 강제 무효화가 안됨
  • 85. API게이트웨이를 통한 클라이언트 토큰 Resource Server Auth ServerAPI GatewayUser Authenticates with Auth Server Forward Generate JWT Grant JWT Translate to opaque token and save Grant opaque token Request Access With opaque token Translate to Auth token Forward Access with Auth Token Valid Auth Token Return Resource Logout with opaque Token Remove opaque token AccessToken 무효화 => JWT 관리 및 opaque token 고려중
  • 86. Q&A
반응형