Skip to content

Commit 310954b

Browse files
authored
feat: store jwks keysets based on issuer_url (#18862)
Currently, any custom issuer keys would be stored alongside the "parent" keys for the service, intermingling and making it less clear which keys belong to which service. Store with the `issuer_url` instead, as redis is fine with keys using special characters, and thus allow storage and lookups for a given issuer. No migration path necessary, as an empty cache will trigger a fresh lookup and storage the first time. Signed-off-by: Mike Fiedler <[email protected]>
1 parent 7be2ad6 commit 310954b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

warehouse/oidc/services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(
121121
self.cache_url = cache_url
122122
self.metrics = metrics
123123

124-
self._publisher_jwk_key = f"/warehouse/oidc/jwks/{self.publisher}"
124+
self._publisher_jwk_key = f"/warehouse/oidc/jwks/{self.issuer_url}"
125125
self._publisher_timeout_key = f"{self._publisher_jwk_key}/timeout"
126126

127127
def _store_keyset(self, keys: dict) -> None:
@@ -255,7 +255,7 @@ def jwt_identifier_exists(self, jti: str) -> bool:
255255
Check if a JWT Token Identifier has already been used.
256256
"""
257257
with redis.StrictRedis.from_url(self.cache_url) as r:
258-
return bool(r.exists(f"/warehouse/oidc/{self.publisher}/{jti}"))
258+
return bool(r.exists(f"/warehouse/oidc/{self.issuer_url}/{jti}"))
259259

260260
def store_jwt_identifier(self, jti: str, expiration: int) -> None:
261261
"""
@@ -266,7 +266,7 @@ def store_jwt_identifier(self, jti: str, expiration: int) -> None:
266266
# the token expiration date. Thus, the lock will not be
267267
# released before the token invalidation.
268268
r.set(
269-
f"/warehouse/oidc/{self.publisher}/{jti}",
269+
f"/warehouse/oidc/{self.issuer_url}/{jti}",
270270
exat=expiration + 5,
271271
value="", # empty value to lower memory usage
272272
nx=True,

0 commit comments

Comments
 (0)