Skip to content

Commit 2543a7d

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 <[email protected]>
1 parent e54457c commit 2543a7d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

sigstore/_internal/trust.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,31 @@ 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(
353+
"Not enough Rekor transparency logs found in signing config"
354+
)
355+
self._tlogs = self._tlogs[: self._inner.rekor_tlog_config.count]
356+
elif self._inner.rekor_tlog_config.selector == ServiceSelector.ANY:
357+
self._tlogs = self._tlogs[:1]
358+
356359
self._tsas = self._get_valid_services(self._inner.tsa_urls, TSA_VERSIONS)
360+
if self._inner.tsa_config.selector == ServiceSelector.EXACT:
361+
self._tsas = self._tsas[: self._inner.tsa_config.count]
362+
elif self._inner.tsa_config.selector == ServiceSelector.ANY:
363+
self._tsas = self._tsas[:1]
364+
357365
self._fulcios = self._get_valid_services(self._inner.ca_urls, FULCIO_VERSIONS)
366+
if not self._fulcios:
367+
raise Error("No valid Fulcio CA found in signing config")
358368
self._oidcs = self._get_valid_services(self._inner.oidc_urls, OIDC_VERSIONS)
359369

360370
@classmethod
@@ -397,18 +407,13 @@ def get_tlogs(self) -> list[RekorClient]:
397407
"""
398408
Returns the rekor transparency logs that client should sign with.
399409
"""
400-
401-
if not self._tlogs:
402-
raise Error("No valid Rekor transparency log found in signing config")
403410
return [RekorClient(tlog.url) for tlog in self._tlogs]
404411

405412
def get_fulcio(self) -> FulcioClient:
406413
"""
407414
Returns url for the fulcio instance that client should use to get a
408415
signing certificate from
409416
"""
410-
if not self._fulcios:
411-
raise Error("No valid Fulcio CA found in signing config")
412417
return FulcioClient(self._fulcios[0].url)
413418

414419
def get_oidc_url(self) -> str:

0 commit comments

Comments
 (0)