Class: KeycloakSdk::JwksStore

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak_sdk/jwks_store.rb

Overview

DoS-safe JWKS 스토어. Mutex 캐시 + rate-limit + single-flight. 위조 서명(알려진 kid)은 캐시 반환만 하고 재조회를 유발하지 않는다. 미해결 kid(force:true)만 재조회하며, rate-limit gate는 재조회 결정 시점에 stamp한다 (성공 아님 — IdP 장애창에서 위조 kid 폭주에도 재조회를 상한한다). Go/Rust/Python 동형.

Instance Method Summary collapse

Constructor Details

#initialize(jwks_url:, http:, min_refetch: 10.0) ⇒ JwksStore

Returns a new instance of JwksStore.



11
12
13
14
15
16
17
18
# File 'lib/keycloak_sdk/jwks_store.rb', line 11

def initialize(jwks_url:, http:, min_refetch: 10.0)
  @jwks_url = jwks_url
  @http = http
  @min_refetch = min_refetch
  @mutex = Mutex.new
  @cache = nil        # {"keys" => [...]}
  @last_refetch = nil # monotonic seconds
end

Instance Method Details

#key_set(force: false) ⇒ Object

ruby-jwt jwks: 로더가 호출. force=true는 미해결 kid 재조회 요청.



21
22
23
24
25
26
27
28
29
# File 'lib/keycloak_sdk/jwks_store.rb', line 21

def key_set(force: false)
  @mutex.synchronize do
    return @cache if @cache && !force
    return @cache if force && !refetch_allowed?

    @last_refetch = monotonic if force # 결정 시점 stamp(cold load는 예산 미소모)
    @cache = fetch
  end
end