Skip to content

Commit 7f3d9d4

Browse files
committed
trust: Start returning RekorV2Client from signingconfig
If signingconfig contains rekor v2, let's start preferring it Make sure we test the status quo (no rekor v2 in signing config) and the case where there is a rekor v2 in signing config. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 8faeace commit 7f3d9d4

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

sigstore/_internal/trust.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060
)
6161

6262
from sigstore._internal.fulcio.client import FulcioClient
63+
from sigstore._internal.rekor import RekorLogSubmitter
6364
from sigstore._internal.rekor.client import RekorClient
65+
from sigstore._internal.rekor.client_v2 import RekorV2Client
6466
from sigstore._internal.timestamp import TimestampAuthorityClient
6567
from sigstore._internal.tuf import DEFAULT_TUF_URL, STAGING_TUF_URL, TrustUpdater
6668
from sigstore._utils import (
@@ -73,7 +75,7 @@
7375
from sigstore.errors import Error, MetadataError, TUFError, VerificationError
7476

7577
# Versions supported by this client
76-
REKOR_VERSIONS = [1]
78+
REKOR_VERSIONS = [1, 2]
7779
TSA_VERSIONS = [1]
7880
FULCIO_VERSIONS = [1]
7981
OIDC_VERSIONS = [1]
@@ -420,11 +422,19 @@ def _get_valid_services(
420422

421423
return result[:count]
422424

423-
def get_tlogs(self) -> list[RekorClient]:
425+
def get_tlogs(self) -> list[RekorLogSubmitter]:
424426
"""
425427
Returns the rekor transparency log clients to sign with.
426428
"""
427-
return [RekorClient(tlog.url) for tlog in self._tlogs]
429+
result: list[RekorLogSubmitter] = []
430+
for tlog in self._tlogs:
431+
if tlog.major_api_version == 1:
432+
result.append(RekorClient(tlog.url))
433+
elif tlog.major_api_version == 2:
434+
result.append(RekorV2Client(tlog.url))
435+
else:
436+
raise AssertionError(f"Unexpected Rekor v{tlog.major_api_version}")
437+
return result
428438

429439
def get_fulcio(self) -> FulcioClient:
430440
"""
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"mediaType": "application/vnd.dev.sigstore.signingconfig.v0.2+json",
3+
"caUrls": [
4+
{
5+
"url": "https://fulcio.example.com",
6+
"majorApiVersion": 1,
7+
"validFor": {
8+
"start": "2023-04-14T21:38:40Z"
9+
}
10+
},
11+
{
12+
"url": "https://fulcio-old.example.com",
13+
"majorApiVersion": 1,
14+
"validFor": {
15+
"start": "2022-04-14T21:38:40Z",
16+
"end": "2023-04-14T21:38:40Z"
17+
}
18+
}
19+
],
20+
"oidcUrls": [
21+
{
22+
"url": "https://oauth2.example.com/auth",
23+
"majorApiVersion": 1,
24+
"validFor": {
25+
"start": "2025-04-16T00:00:00Z"
26+
}
27+
}
28+
],
29+
"rekorTlogUrls": [
30+
{
31+
"url": "https://rekor.example.com",
32+
"majorApiVersion": 1,
33+
"validFor": {
34+
"start": "2021-01-12T11:53:27Z"
35+
}
36+
}
37+
],
38+
"tsaUrls": [
39+
{
40+
"url": "https://timestamp.example.com/api/v1/timestamp",
41+
"majorApiVersion": 1,
42+
"validFor": {
43+
"start": "2025-04-09T00:00:00Z"
44+
}
45+
}
46+
],
47+
"rekorTlogConfig": {
48+
"selector": "ANY"
49+
},
50+
"tsaConfig": {
51+
"selector": "ANY"
52+
}
53+
}

test/unit/internal/test_trust.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from sigstore._internal.fulcio.client import FulcioClient
3030
from sigstore._internal.rekor.client import RekorClient
31+
from sigstore._internal.rekor.client_v2 import RekorV2Client
3132
from sigstore._internal.timestamp import TimestampAuthorityClient
3233
from sigstore._internal.trust import (
3334
CertificateAuthority,
@@ -83,16 +84,27 @@ def test_good(self, asset):
8384
assert fulcio.url == "https://fulcio.example.com"
8485
assert signing_config.get_oidc_url() == "https://oauth2.example.com/auth"
8586

87+
# signing config contains v1 and v2, we pick v2
8688
tlogs = signing_config.get_tlogs()
8789
assert len(tlogs) == 1
88-
assert isinstance(tlogs[0], RekorClient)
89-
assert tlogs[0].url == "https://rekor.example.com/api/v1"
90+
assert isinstance(tlogs[0], RekorV2Client)
91+
assert tlogs[0].url == "https://rekor-v2.example.com/api/v2"
9092

9193
tsas = signing_config.get_tsas()
9294
assert len(tsas) == 1
9395
assert isinstance(tsas[0], TimestampAuthorityClient)
9496
assert tsas[0].url == "https://timestamp.example.com/api/v1/timestamp"
9597

98+
def test_good_only_v1_rekor(self, asset):
99+
"""Test case where a rekor 2 instance is not available"""
100+
path = asset("signing_config/signingconfig-only-v1-rekor.v2.json")
101+
signing_config = SigningConfig.from_file(path)
102+
103+
tlogs = signing_config.get_tlogs()
104+
assert len(tlogs) == 1
105+
assert isinstance(tlogs[0], RekorClient)
106+
assert tlogs[0].url == "https://rekor.example.com/api/v1"
107+
96108
@pytest.mark.parametrize(
97109
"services, versions, config, expected_result",
98110
[

0 commit comments

Comments
 (0)