Skip to content

Commit 9647148

Browse files
committed
trust: Refactor service configuration
* Abstract the ServiceConfiguration handling as suggested in review (so both tsa and rekor are handled in the same way) * This creates some issues as TSAs are still optional... I decided that it is reasonable to require "ANY" selector to be used with at least one service, meaning I have to change the placeholder signingconfig for production. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 0dac9f4 commit 9647148

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

sigstore/_internal/trust.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
)
4848
from sigstore_protobuf_specs.dev.sigstore.trustroot.v1 import (
4949
Service,
50+
ServiceConfiguration,
5051
ServiceSelector,
5152
TransparencyLogInstance,
5253
)
@@ -340,34 +341,27 @@ def __init__(self, inner: _SigningConfig):
340341
except ValueError:
341342
raise Error(f"unsupported signing config format: {self._inner.media_type}")
342343

343-
# Create lists of service protos that are valid & supported by this client
344-
# Limit the TSA and tlog lists using the service selector config
345-
tlogs = self._get_valid_services(self._inner.rekor_tlog_urls, REKOR_VERSIONS)
346-
if not tlogs:
344+
# Create lists of service protos that are valid, selected by the service
345+
# configuration & supported by this client
346+
self._tlogs = self._get_valid_services(
347+
self._inner.rekor_tlog_urls, REKOR_VERSIONS, self._inner.rekor_tlog_config
348+
)
349+
if not self._tlogs:
347350
raise Error("No valid Rekor transparency log found in signing config")
348-
if self._inner.rekor_tlog_config.selector == ServiceSelector.EXACT:
349-
if len(tlogs) < self._inner.rekor_tlog_config.count:
350-
raise Error(
351-
"Not enough Rekor transparency logs found in signing config"
352-
)
353-
self._tlogs = tlogs[: self._inner.rekor_tlog_config.count]
354-
elif self._inner.rekor_tlog_config.selector == ServiceSelector.ANY:
355-
self._tlogs = tlogs[:1]
356-
else:
357-
self._tlogs = tlogs
358351

359-
tsas = self._get_valid_services(self._inner.tsa_urls, TSA_VERSIONS)
360-
if self._inner.tsa_config.selector == ServiceSelector.EXACT:
361-
self._tsas = tsas[: self._inner.tsa_config.count]
362-
elif self._inner.tsa_config.selector == ServiceSelector.ANY:
363-
self._tsas = tsas[:1]
364-
else:
365-
self._tsas = tsas
352+
self._tsas = self._get_valid_services(
353+
self._inner.tsa_urls, TSA_VERSIONS, self._inner.tsa_config
354+
)
366355

367-
self._fulcios = self._get_valid_services(self._inner.ca_urls, FULCIO_VERSIONS)
356+
self._fulcios = self._get_valid_services(
357+
self._inner.ca_urls, FULCIO_VERSIONS, None
358+
)
368359
if not self._fulcios:
369360
raise Error("No valid Fulcio CA found in signing config")
370-
self._oidcs = self._get_valid_services(self._inner.oidc_urls, OIDC_VERSIONS)
361+
362+
self._oidcs = self._get_valid_services(
363+
self._inner.oidc_urls, OIDC_VERSIONS, None
364+
)
371365

372366
@classmethod
373367
def from_file(
@@ -379,7 +373,10 @@ def from_file(
379373
return cls(inner)
380374

381375
def _get_valid_services(
382-
self, services: list[Service], valid_versions: list[int]
376+
self,
377+
services: list[Service],
378+
valid_versions: list[int],
379+
config: ServiceConfiguration | None,
383380
) -> list[Service]:
384381
"""Return supported services, taking SigningConfig restrictions into account"""
385382

@@ -394,7 +391,7 @@ def _get_valid_services(
394391

395392
logs_by_operator[service.operator].append(service)
396393

397-
# return a list of services but make sure we only return logs of one version per operator
394+
# build a list of services but make sure we only include logs of one version per operator
398395
result: list[Service] = []
399396
for logs in logs_by_operator.values():
400397
logs.sort(key=lambda s: -s.major_api_version)
@@ -403,7 +400,17 @@ def _get_valid_services(
403400
while logs and logs[-1].major_api_version == max_version:
404401
result.append(logs.pop())
405402

406-
return result
403+
# limit the list based on ServiceConfiguration
404+
if not config or config.selector == ServiceSelector.ALL:
405+
return result
406+
407+
count = config.count if config.selector == ServiceSelector.EXACT else 1
408+
if len(result) < count:
409+
raise ValueError(
410+
f"Expected {count} services in signing config, found {len(result)}"
411+
)
412+
413+
return result[:count]
407414

408415
def get_tlogs(self) -> list[RekorClient]:
409416
"""

sigstore/_store/https%3A%2F%2Ftuf-repo-cdn.sigstore.dev/signing_config.v0.2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
"selector": "ANY"
3535
},
3636
"tsaConfig": {
37-
"selector": "ANY"
37+
"selector": "ALL"
3838
}
3939
}

0 commit comments

Comments
 (0)