Skip to content

Commit e904663

Browse files
committed
trust: Support ServiceSelector fully
I don't think we'll be seeing anything else than ANY for a while but for completeness, support all selector modes for TSA and Rekor. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent e54457c commit e904663

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

sigstore/_internal/trust.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,32 @@ def __init__(self, inner: _SigningConfig):
340340
except ValueError:
341341
raise Error(f"unsupported signing config format: {self._inner.media_type}")
342342

343-
# currently not supporting other select modes
344-
# TODO: Support other modes ensuring tsa_urls() and tlog_urls() work
345-
if self._inner.rekor_tlog_config.selector != ServiceSelector.ANY:
346-
raise Error(
347-
f"unsupported tlog selector {self._inner.rekor_tlog_config.selector}"
348-
)
349-
if self._inner.tsa_config.selector != ServiceSelector.ANY:
350-
raise Error(f"unsupported TSA selector {self._inner.tsa_config.selector}")
351-
352343
# Create lists of service protos that are valid & supported by this client
344+
# Limit the TSA and tlog lists using the service selector config
353345
self._tlogs = self._get_valid_services(
354346
self._inner.rekor_tlog_urls, REKOR_VERSIONS
355347
)
348+
if not self._tlogs:
349+
raise Error("No valid Rekor transparency log found in signing config")
350+
if self._inner.rekor_tlog_config.selector == ServiceSelector.EXACT:
351+
if len(self._tlogs) < self._inner.rekor_tlog_config.count:
352+
raise Error("Not enough Rekor transparency logs found in signing config")
353+
self._tlogs = self._tlogs[:self._inner.rekor_tlog_config.count]
354+
elif self._inner.rekor_tlog_config.selector == ServiceSelector.ANY:
355+
self._tlogs = self._tlogs[:1]
356+
356357
self._tsas = self._get_valid_services(self._inner.tsa_urls, TSA_VERSIONS)
358+
if self._inner.tsa_config.selector == ServiceSelector.EXACT:
359+
self._tsas = self._tsas[:self._inner.tsa_config.count]
360+
elif self._inner.tsa_config.selector == ServiceSelector.ANY:
361+
self._tsas = self._tsas[:1]
362+
357363
self._fulcios = self._get_valid_services(self._inner.ca_urls, FULCIO_VERSIONS)
364+
if not self._fulcios:
365+
raise Error("No valid Fulcio CA found in signing config")
358366
self._oidcs = self._get_valid_services(self._inner.oidc_urls, OIDC_VERSIONS)
359367

368+
360369
@classmethod
361370
def from_file(
362371
cls,
@@ -397,18 +406,13 @@ def get_tlogs(self) -> list[RekorClient]:
397406
"""
398407
Returns the rekor transparency logs that client should sign with.
399408
"""
400-
401-
if not self._tlogs:
402-
raise Error("No valid Rekor transparency log found in signing config")
403409
return [RekorClient(tlog.url) for tlog in self._tlogs]
404410

405411
def get_fulcio(self) -> FulcioClient:
406412
"""
407413
Returns url for the fulcio instance that client should use to get a
408414
signing certificate from
409415
"""
410-
if not self._fulcios:
411-
raise Error("No valid Fulcio CA found in signing config")
412416
return FulcioClient(self._fulcios[0].url)
413417

414418
def get_oidc_url(self) -> str:

0 commit comments

Comments
 (0)