Skip to content

Commit a7345fb

Browse files
authored
Add Rekor v2 support for trusted-root create (#4242)
When deducing the Rekor log key ID, cosign universally assumes a Rekor v1 type checkpoint, which is not C2SP compliant. Rekor v2 is compliant for all different types of keys, which means the log ID must be calculated differently. This affects the `trusted-root create` tool which must generate the log ID from the public key. This change adds the ability for the trusted-root command to parse a ":" in the --rekor-key flag to indicate that the trusted material should be generated for a Rekor v2 log and that the origin string following the ":" should be used to calculate it. This is backwards compatible and will not affect Rekor v1 which needs no origin string. This addresses the issue strictly for this command so that trusted_root files can be created for Rekor v2 servers. A later change will make more general changes to the TUF client to ensure the trusted material is generated properly for the server it relates to. Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
1 parent 3df894e commit a7345fb

File tree

6 files changed

+67
-20
lines changed

6 files changed

+67
-20
lines changed

cmd/cosign/cli/options/trustedroot.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ func (o *TrustedRootCreateOptions) AddFlags(cmd *cobra.Command) {
6262
// _ = cmd.MarkFlagFilename("output") // no typical extensions
6363

6464
cmd.Flags().StringArrayVar(&o.RekorKeyPath, "rekor-key", nil,
65-
"path to a PEM-encoded public key used by transparency log like Rekor.")
65+
"path to a PEM-encoded public key used by transparency log like Rekor. "+
66+
"For Rekor V2, append the Rekor server name with ',', e.g. "+
67+
"'--rekor-key=/path/to/key.pub,rekor.example.test'.")
6668
_ = cmd.MarkFlagFilename("rekor-key", publicKeyExts...)
6769

6870
cmd.Flags().StringArrayVar(&o.RekorStartTime, "rekor-start-time", nil,

cmd/cosign/cli/trustedroot/trustedroot.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import (
2323
"encoding/pem"
2424
"fmt"
2525
"os"
26+
"strings"
2627
"time"
2728

2829
"github.com/sigstore/cosign/v2/pkg/cosign"
30+
"github.com/sigstore/rekor-tiles/pkg/note"
2931
"github.com/sigstore/sigstore-go/pkg/root"
3032
"github.com/sigstore/sigstore/pkg/cryptoutils"
3133
)
@@ -91,10 +93,22 @@ func (c *CreateCmd) Exec(_ context.Context) error {
9193
}
9294

9395
for i := 0; i < len(c.RekorKeyPath); i++ {
94-
tlogPubKey, id, idBytes, err := getPubKey(c.RekorKeyPath[i])
96+
keyParts := strings.SplitN(c.RekorKeyPath[i], ",", 2)
97+
keyPath := keyParts[0]
98+
tlogPubKey, id, idBytes, err := getPubKey(keyPath)
9599
if err != nil {
96100
return err
97101
}
102+
var origin string
103+
if len(keyParts) > 1 {
104+
origin = keyParts[1]
105+
}
106+
if origin != "" {
107+
id, idBytes, err = getCheckpointID(origin, *tlogPubKey)
108+
if err != nil {
109+
return err
110+
}
111+
}
98112

99113
startTime := time.Unix(0, 0)
100114

@@ -241,3 +255,11 @@ func getPubKey(path string) (*crypto.PublicKey, string, []byte, error) {
241255

242256
return &pubKey, keyID, idBytes, nil
243257
}
258+
259+
func getCheckpointID(origin string, key crypto.PublicKey) (string, []byte, error) {
260+
_, id, err := note.KeyHash(origin, key)
261+
if err != nil {
262+
return "", nil, err
263+
}
264+
return hex.EncodeToString(id), id, nil
265+
}

cmd/cosign/cli/trustedroot/trustedroot_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package trustedroot
1717

1818
import (
1919
"context"
20+
"crypto/ed25519"
2021
"crypto/rand"
2122
"crypto/rsa"
2223
"crypto/x509"
@@ -41,12 +42,18 @@ func TestCreateCmd(t *testing.T) {
4142
tsaChainPath := filepath.Join(td, "timestamp.pem")
4243
makeChain(t, tsaChainPath, 3)
4344

45+
rekorV1KeyPath := filepath.Join(td, "rekor.v1.pub")
46+
makeKey(t, rekorV1KeyPath)
47+
rekorV2KeyPath := filepath.Join(td, "rekor.v2.pub")
48+
makeKey(t, rekorV2KeyPath)
49+
4450
outPath := filepath.Join(td, "trustedroot.json")
4551

4652
trustedrootCreate := CreateCmd{
4753
CertChain: []string{fulcioChainPath},
4854
FulcioURI: []string{"https://fulcio.sigstore.example"},
4955
RekorURL: []string{"https://rekor.sigstore.example"},
56+
RekorKeyPath: []string{rekorV1KeyPath, rekorV2KeyPath + ",rekor.sigstore.example"},
5057
Out: outPath,
5158
TSACertChainPath: []string{tsaChainPath},
5259
TSAURI: []string{"https://tsa.sigstore.example"},
@@ -129,6 +136,19 @@ func makeChain(t *testing.T, path string, size int) {
129136
checkErr(t, err)
130137
}
131138

139+
func makeKey(t *testing.T, path string) {
140+
fd, err := os.Create(path)
141+
checkErr(t, err)
142+
defer fd.Close()
143+
144+
pub, _, err := ed25519.GenerateKey(rand.Reader)
145+
checkErr(t, err)
146+
derBytes, err := x509.MarshalPKIXPublicKey(pub)
147+
checkErr(t, err)
148+
err = pem.Encode(fd, &pem.Block{Type: "PUBLIC KEY", Bytes: derBytes})
149+
checkErr(t, err)
150+
}
151+
132152
func checkErr(t *testing.T, err error) {
133153
if err != nil {
134154
t.Fatal(err)

doc/cosign_trusted-root_create.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.9.1
1111
github.com/buildkite/agent/v3 v3.98.1
1212
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589
13-
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46
13+
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467
1414
github.com/depcheck-test/depcheck-test v0.0.0-20220607135614-199033aaa936
1515
github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7
1616
github.com/dustin/go-humanize v1.0.1
@@ -36,6 +36,7 @@ require (
3636
github.com/sigstore/fulcio v1.7.1
3737
github.com/sigstore/protobuf-specs v0.4.2
3838
github.com/sigstore/rekor v1.3.10
39+
github.com/sigstore/rekor-tiles v0.1.5
3940
github.com/sigstore/sigstore v1.9.4
4041
github.com/sigstore/sigstore-go v1.0.0
4142
github.com/sigstore/sigstore/pkg/signature/kms/aws v1.9.4
@@ -66,7 +67,7 @@ require (
6667
)
6768

6869
require (
69-
cloud.google.com/go v0.120.0 // indirect
70+
cloud.google.com/go v0.121.1 // indirect
7071
cloud.google.com/go/auth v0.16.1 // indirect
7172
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
7273
cloud.google.com/go/compute/metadata v0.7.0 // indirect
@@ -225,7 +226,7 @@ require (
225226
github.com/prometheus/procfs v0.15.1 // indirect
226227
github.com/protocolbuffers/txtpbfmt v0.0.0-20241112170944-20d2c9ebc01d // indirect
227228
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
228-
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a // indirect
229+
github.com/rogpeppe/go-internal v1.14.1 // indirect
229230
github.com/rs/cors v1.11.1 // indirect
230231
github.com/russross/blackfriday/v2 v2.1.0 // indirect
231232
github.com/ryanuber/go-glob v1.0.0 // indirect

go.sum

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2-
cloud.google.com/go v0.120.0 h1:wc6bgG9DHyKqF5/vQvX1CiZrtHnxJjBlKUyF9nP6meA=
3-
cloud.google.com/go v0.120.0/go.mod h1:/beW32s8/pGRuj4IILWQNd4uuebeT4dkOhKmkfit64Q=
2+
cloud.google.com/go v0.121.1 h1:S3kTQSydxmu1JfLRLpKtxRPA7rSrYPRPEUmL/PavVUw=
3+
cloud.google.com/go v0.121.1/go.mod h1:nRFlrHq39MNVWu+zESP2PosMWA0ryJw8KUBZ2iZpxbw=
44
cloud.google.com/go/auth v0.16.1 h1:XrXauHMd30LhQYVRHLGvJiYeczweKQXZxsTbV9TiguU=
55
cloud.google.com/go/auth v0.16.1/go.mod h1:1howDHJ5IETh/LwYs3ZxvlkXF48aSqqJUM+5o02dNOI=
66
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
@@ -215,8 +215,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3
215215
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
216216
github.com/creack/pty v1.1.19 h1:tUN6H7LWqNx4hQVxomd0CVsDwaDr9gaRQaI4GpSmrsA=
217217
github.com/creack/pty v1.1.19/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
218-
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 h1:2Dx4IHfC1yHWI12AxQDJM1QbRCDfk6M+blLzlZCXdrc=
219-
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw=
218+
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 h1:uX1JmpONuD549D73r6cgnxyUu18Zb7yHAy5AYU0Pm4Q=
219+
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw=
220220
github.com/danieljoos/wincred v1.2.2 h1:774zMFJrqaeYCK2W57BgAem/MLi6mtSE47MB6BOJ0i0=
221221
github.com/danieljoos/wincred v1.2.2/go.mod h1:w7w4Utbrz8lqeMbDAK0lkNJUv5sAOkFi7nd/ogr0Uh8=
222222
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -258,8 +258,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
258258
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
259259
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
260260
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
261-
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
262-
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
261+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
262+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
263263
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
264264
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
265265
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
@@ -490,8 +490,8 @@ github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUt
490490
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
491491
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
492492
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
493-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
494-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
493+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
494+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
495495
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
496496
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
497497
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
@@ -545,8 +545,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
545545
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
546546
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
547547
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
548-
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
549-
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
548+
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
549+
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
550550
github.com/open-policy-agent/opa v1.5.1 h1:LTxxBJusMVjfs67W4FoRcnMfXADIGFMzpqnfk6D08Cg=
551551
github.com/open-policy-agent/opa v1.5.1/go.mod h1:bYbS7u+uhTI+cxHQIpzvr5hxX0hV7urWtY+38ZtjMgk=
552552
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@@ -583,8 +583,8 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5X
583583
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
584584
github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI=
585585
github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
586-
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a h1:w3tdWGKbLGBPtR/8/oO74W6hmz0qE5q0z9aqSAewaaM=
587-
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a/go.mod h1:S8kfXMp+yh77OxPD4fdM6YUknrZpQxLhvxzS4gDHENY=
586+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
587+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
588588
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
589589
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
590590
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
@@ -612,6 +612,8 @@ github.com/sigstore/protobuf-specs v0.4.2 h1:bD5bnhctpGNiR+FAEZl7N95XkN8TJFrNMIc
612612
github.com/sigstore/protobuf-specs v0.4.2/go.mod h1:+gXR+38nIa2oEupqDdzg4qSBT0Os+sP7oYv6alWewWc=
613613
github.com/sigstore/rekor v1.3.10 h1:/mSvRo4MZ/59ECIlARhyykAlQlkmeAQpvBPlmJtZOCU=
614614
github.com/sigstore/rekor v1.3.10/go.mod h1:JvryKJ40O0XA48MdzYUPu0y4fyvqt0C4iSY7ri9iu3A=
615+
github.com/sigstore/rekor-tiles v0.1.5 h1:NzCpMPhoIFUrFj39+Em+WGeyGgshY0gbCGfXObjtvug=
616+
github.com/sigstore/rekor-tiles v0.1.5/go.mod h1:SO8yIfeP09Ggvs2PF6A5rfejA8a0LujSjz23fAxUdVw=
615617
github.com/sigstore/sigstore v1.9.4 h1:64+OGed80+A4mRlNzRd055vFcgBeDghjZw24rPLZgDU=
616618
github.com/sigstore/sigstore v1.9.4/go.mod h1:Q7tGTC3gbtK7c3jcxEmGc2MmK4rRpIRzi3bxRFWKvEY=
617619
github.com/sigstore/sigstore-go v1.0.0 h1:4N07S2zLxf09nTRwaPKyAxbKzpM8WJYUS8lWWaYxneU=
@@ -745,8 +747,8 @@ go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCRE
745747
go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs=
746748
go.opentelemetry.io/otel/sdk v1.36.0 h1:b6SYIuLRs88ztox4EyrvRti80uXIFy+Sqzoh9kFULbs=
747749
go.opentelemetry.io/otel/sdk v1.36.0/go.mod h1:+lC+mTgD+MUWfjJubi2vvXWcVxyr9rmlshZni72pXeY=
748-
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
749-
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
750+
go.opentelemetry.io/otel/sdk/metric v1.36.0 h1:r0ntwwGosWGaa0CrSt8cuNuTcccMXERFwHX4dThiPis=
751+
go.opentelemetry.io/otel/sdk/metric v1.36.0/go.mod h1:qTNOhFDfKRwX0yXOqJYegL5WRaW376QbB7P4Pb0qva4=
750752
go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w=
751753
go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA=
752754
go.opentelemetry.io/proto/otlp v1.6.0 h1:jQjP+AQyTf+Fe7OKj/MfkDrmK4MNVtw2NpXsf9fefDI=

0 commit comments

Comments
 (0)