Skip to content

Commit 3df894e

Browse files
committed
Add baseUrl and Uri to trusted-root create command
Clients using Rekor v2 need the name of the log server in order to create a checkpoint verifier, so it is useful to include it in the trust root. This change adds that functionality for all key material. Signed-off-by: Colleen Murphy <[email protected]>
1 parent fb26ffd commit 3df894e

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

cmd/cosign/cli/options/trustedroot.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ import (
2121

2222
type TrustedRootCreateOptions struct {
2323
CertChain []string
24+
FulcioURI []string
2425
CtfeKeyPath []string
2526
CtfeStartTime []string
27+
CtfeURL []string
2628
Out string
2729
RekorKeyPath []string
2830
RekorStartTime []string
31+
RekorURL []string
2932
TSACertChainPath []string
33+
TSAURI []string
3034
}
3135

3236
var _ Interface = (*TrustedRootCreateOptions)(nil)
@@ -39,6 +43,9 @@ func (o *TrustedRootCreateOptions) AddFlags(cmd *cobra.Command) {
3943
"signing certificate and end with the root certificate.")
4044
_ = cmd.MarkFlagFilename("certificate-chain", certificateExts...)
4145

46+
cmd.Flags().StringArrayVar(&o.FulcioURI, "fulcio-uri", nil,
47+
"URI of the Fulcio server issuing certificates.")
48+
4249
cmd.Flags().StringArrayVar(&o.CtfeKeyPath, "ctfe-key", nil,
4350
"path to a PEM-encoded public key used by certificate authority for "+
4451
"certificate transparency log.")
@@ -48,6 +55,9 @@ func (o *TrustedRootCreateOptions) AddFlags(cmd *cobra.Command) {
4855
"RFC 3339 string describing validity start time for key use by "+
4956
"certificate transparency log.")
5057

58+
cmd.Flags().StringArrayVar(&o.CtfeURL, "ctfe-url", nil,
59+
"URL of the certificate transparency log.")
60+
5161
cmd.Flags().StringVar(&o.Out, "out", "", "path to output trusted root")
5262
// _ = cmd.MarkFlagFilename("output") // no typical extensions
5363

@@ -59,8 +69,14 @@ func (o *TrustedRootCreateOptions) AddFlags(cmd *cobra.Command) {
5969
"RFC 3339 string describing validity start time for key use by "+
6070
"transparency log like Rekor.")
6171

72+
cmd.Flags().StringArrayVar(&o.RekorURL, "rekor-url", nil,
73+
"URL of the transparency log.")
74+
6275
cmd.Flags().StringArrayVar(&o.TSACertChainPath, "timestamp-certificate-chain", nil,
6376
"path to PEM-encoded certificate chain file for the RFC3161 timestamp authority. Must contain the root CA certificate. "+
6477
"Optionally may contain intermediate CA certificates")
6578
_ = cmd.MarkFlagFilename("timestamp-certificate-chain", certificateExts...)
79+
80+
cmd.Flags().StringArrayVar(&o.TSAURI, "timestamp-uri", nil,
81+
"URI of the timestamp authority server.")
6682
}

cmd/cosign/cli/trustedroot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ func trustedRootCreate() *cobra.Command {
4545
RunE: func(cmd *cobra.Command, _ []string) error {
4646
trCreateCmd := &trustedroot.CreateCmd{
4747
CertChain: o.CertChain,
48+
FulcioURI: o.FulcioURI,
4849
CtfeKeyPath: o.CtfeKeyPath,
4950
CtfeStartTime: o.CtfeStartTime,
51+
CtfeURL: o.CtfeURL,
5052
Out: o.Out,
5153
RekorKeyPath: o.RekorKeyPath,
5254
RekorStartTime: o.RekorStartTime,
55+
RekorURL: o.RekorURL,
5356
TSACertChainPath: o.TSACertChainPath,
57+
TSAURI: o.TSAURI,
5458
}
5559

5660
ctx, cancel := context.WithTimeout(cmd.Context(), ro.Timeout)

cmd/cosign/cli/trustedroot/trustedroot.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ import (
3232

3333
type CreateCmd struct {
3434
CertChain []string
35+
FulcioURI []string
3536
CtfeKeyPath []string
3637
CtfeStartTime []string
38+
CtfeURL []string
3739
Out string
3840
RekorKeyPath []string
3941
RekorStartTime []string
42+
RekorURL []string
4043
TSACertChainPath []string
44+
TSAURI []string
4145
}
4246

4347
func (c *CreateCmd) Exec(_ context.Context) error {
@@ -47,7 +51,11 @@ func (c *CreateCmd) Exec(_ context.Context) error {
4751
rekorTransparencyLogs := make(map[string]*root.TransparencyLog)
4852

4953
for i := 0; i < len(c.CertChain); i++ {
50-
fulcioAuthority, err := parseCAPEMFile(c.CertChain[i])
54+
var fulcioURI string
55+
if i < len(c.FulcioURI) {
56+
fulcioURI = c.FulcioURI[i]
57+
}
58+
fulcioAuthority, err := parseCAPEMFile(c.CertChain[i], fulcioURI)
5159
if err != nil {
5260
return err
5361
}
@@ -76,6 +84,10 @@ func (c *CreateCmd) Exec(_ context.Context) error {
7684
PublicKey: *ctLogPubKey,
7785
SignatureHashFunc: crypto.SHA256,
7886
}
87+
88+
if i < len(c.CtfeURL) {
89+
ctLogs[id].BaseURL = c.CtfeURL[i]
90+
}
7991
}
8092

8193
for i := 0; i < len(c.RekorKeyPath); i++ {
@@ -100,10 +112,18 @@ func (c *CreateCmd) Exec(_ context.Context) error {
100112
PublicKey: *tlogPubKey,
101113
SignatureHashFunc: crypto.SHA256,
102114
}
115+
116+
if i < len(c.RekorURL) {
117+
rekorTransparencyLogs[id].BaseURL = c.RekorURL[i]
118+
}
103119
}
104120

105121
for i := 0; i < len(c.TSACertChainPath); i++ {
106-
timestampAuthority, err := parseTAPEMFile(c.TSACertChainPath[i])
122+
var tsaURI string
123+
if i < len(c.TSAURI) {
124+
tsaURI = c.TSAURI[i]
125+
}
126+
timestampAuthority, err := parseTAPEMFile(c.TSACertChainPath[i], tsaURI)
107127
if err != nil {
108128
return err
109129
}
@@ -137,7 +157,7 @@ func (c *CreateCmd) Exec(_ context.Context) error {
137157
return nil
138158
}
139159

140-
func parseCAPEMFile(path string) (root.CertificateAuthority, error) {
160+
func parseCAPEMFile(path, uri string) (root.CertificateAuthority, error) {
141161
certs, err := parseCerts(path)
142162
if err != nil {
143163
return nil, err
@@ -149,11 +169,12 @@ func parseCAPEMFile(path string) (root.CertificateAuthority, error) {
149169
if len(certs) > 1 {
150170
ca.Intermediates = certs[:len(certs)-1]
151171
}
172+
ca.URI = uri
152173

153174
return &ca, nil
154175
}
155176

156-
func parseTAPEMFile(path string) (root.TimestampingAuthority, error) {
177+
func parseTAPEMFile(path, uri string) (root.TimestampingAuthority, error) {
157178
certs, err := parseCerts(path)
158179
if err != nil {
159180
return nil, err
@@ -165,6 +186,7 @@ func parseTAPEMFile(path string) (root.TimestampingAuthority, error) {
165186
if len(certs) > 1 {
166187
ta.Intermediates = certs[:len(certs)-1]
167188
}
189+
ta.URI = uri
168190

169191
return &ta, nil
170192
}

cmd/cosign/cli/trustedroot/trustedroot_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ func TestCreateCmd(t *testing.T) {
4545

4646
trustedrootCreate := CreateCmd{
4747
CertChain: []string{fulcioChainPath},
48+
FulcioURI: []string{"https://fulcio.sigstore.example"},
49+
RekorURL: []string{"https://rekor.sigstore.example"},
4850
Out: outPath,
4951
TSACertChainPath: []string{tsaChainPath},
52+
TSAURI: []string{"https://tsa.sigstore.example"},
5053
}
5154

5255
err := trustedrootCreate.Exec(ctx)

doc/cosign_trusted-root_create.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)