forge
Explore
Log in

Don't you dare go Hollow

🔑 oidc: a scheduled key fetch no longer delays the refetch for a newly rotated key

Browse files at this commit

9ffa9cd4e4cbeeb36b92c9955daff074ba03ca0aAhmet Kaan GümüşParent: a05110d
crates/in-web/src/oidc.rsmodified+9 -2
@@ -590,7 +590,7 @@ struct Cache {
590 discovery_failed_at: Option<Instant>,590 discovery_failed_at: Option<Instant>,
591 /// The key set and when it was fetched.591 /// The key set and when it was fetched.
592 keys: Option<(Instant, Arc<KeySet>)>,592 keys: Option<(Instant, Arc<KeySet>)>,
593- /// When the keys were last fetched for an unknown `kid`. Limits those fetches.593+ /// When the keys were last fetched for an unknown `kid`, or a fetch failed. Limits those fetches.
594 keys_refresh_at: Option<Instant>,594 keys_refresh_at: Option<Instant>,
595 /// The client-credentials token for `im`, and the instant it stops being used.595 /// The client-credentials token for `im`, and the instant it stops being used.
596 service: Option<(String, Instant)>,596 service: Option<(String, Instant)>,
@@ -773,9 +773,16 @@ impl OidcClient {
773 return answer;773 return answer;
774 }774 }
775 let endpoints = self.endpoints().await;775 let endpoints = self.endpoints().await;
776- self.cache.lock().await.keys_refresh_at = Some(Instant::now());776+ // Only a forced refetch or a failure starts the gap. A scheduled fetch does not, so the first token
777+ // signed by a newly rotated key is verified at once.
778+ if force {
779+ self.cache.lock().await.keys_refresh_at = Some(Instant::now());
780+ }
777 let fetched = self.get_json::<Jwks>(&endpoints.jwks).await;781 let fetched = self.get_json::<Jwks>(&endpoints.jwks).await;
778 let mut cache = self.cache.lock().await;782 let mut cache = self.cache.lock().await;
783+ if fetched.is_err() {
784+ cache.keys_refresh_at = Some(Instant::now());
785+ }
779 match fetched {786 match fetched {
780 Ok(jwks) => {787 Ok(jwks) => {
781 let keys = Arc::new(KeySet::from_jwks(&jwks));788 let keys = Arc::new(KeySet::from_jwks(&jwks));