Skip to content

Commit e7ef428

Browse files
authored
Merge pull request #18 from alopez-suse/main
NVSHAS-8377: implement RootlessKeypairsOnly flag
2 parents dcc1155 + f6873e4 commit e7ef428

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

main.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ type Configuration struct {
3030
}
3131

3232
type RootOfTrust struct {
33-
Name string `json:"Name"`
34-
RekorPublicKey string `json:"RekorPublicKey"`
35-
RootCert string `json:"RootCert"`
36-
SCTPublicKey string `json:"SCTPublicKey"`
37-
Verifiers []Verifier `json:"Verifiers"`
33+
Name string `json:"Name"`
34+
RootlessKeypairsOnly bool `json:"RootlessKeypairsOnly"`
35+
RekorPublicKey string `json:"RekorPublicKey"`
36+
RootCert string `json:"RootCert"`
37+
SCTPublicKey string `json:"SCTPublicKey"`
38+
Verifiers []Verifier `json:"Verifiers"`
3839
}
3940

4041
func (r *RootOfTrust) IsPublic() bool {
@@ -191,10 +192,14 @@ func verify(imgDigest v1.Hash, rootOfTrust RootOfTrust, sigs []oci.Signature, pr
191192
}
192193

193194
func setRootOfTrustCosignOptions(cosignOptions *cosign.CheckOpts, rootOfTrust RootOfTrust, proxy Proxy, ctx context.Context) (err error) {
195+
if rootOfTrust.RootlessKeypairsOnly {
196+
return nil
197+
}
198+
194199
// rekor public keys
195200
rekorKeyCollection := cosign.NewTrustedTransparencyLogPubKeys()
196-
if rootOfTrust.RekorPublicKey == "" {
197-
rekorKeyTargets, err := GetTargets(sigtuf.Rekor, proxy)
201+
if rootOfTrust.IsPublic() {
202+
rekorKeyTargets, err := GetSigstorePublicTufTargets(sigtuf.Rekor, proxy)
198203
if err != nil {
199204
return fmt.Errorf("could not retrieve rekor tuf targets: %s", err.Error())
200205
}
@@ -203,7 +208,7 @@ func setRootOfTrustCosignOptions(cosignOptions *cosign.CheckOpts, rootOfTrust Ro
203208
return fmt.Errorf("could not add public root of trust rekor public key to collection: %w", err)
204209
}
205210
}
206-
} else {
211+
} else if rootOfTrust.RekorPublicKey != "" {
207212
if err := rekorKeyCollection.AddTransparencyLogPubKey([]byte(rootOfTrust.RekorPublicKey), sigtuf.Active); err != nil {
208213
return fmt.Errorf("could not add custom root of trust rekor public key to collection: %w", err)
209214
}
@@ -233,8 +238,8 @@ func setRootOfTrustCosignOptions(cosignOptions *cosign.CheckOpts, rootOfTrust Ro
233238
}
234239
cosignOptions.RootCerts = rootPool
235240
cosignOptions.IntermediateCerts = intermediatePool
236-
} else {
237-
targetCertificates, err := GetTargets(sigtuf.Fulcio, proxy)
241+
} else if rootOfTrust.IsPublic() {
242+
targetCertificates, err := GetSigstorePublicTufTargets(sigtuf.Fulcio, proxy)
238243
// certificates, err := GetPublicRootOfTrustFulcioCertificates(proxy)
239244
if err != nil {
240245
return fmt.Errorf("could not retrieve public root of trust fulcio certificates: %s", err.Error())
@@ -263,8 +268,8 @@ func setRootOfTrustCosignOptions(cosignOptions *cosign.CheckOpts, rootOfTrust Ro
263268

264269
// sct public keys
265270
sctKeyCollection := cosign.NewTrustedTransparencyLogPubKeys()
266-
if rootOfTrust.SCTPublicKey == "" {
267-
sctKeyTargets, err := GetTargets(sigtuf.CTFE, proxy)
271+
if rootOfTrust.IsPublic() {
272+
sctKeyTargets, err := GetSigstorePublicTufTargets(sigtuf.CTFE, proxy)
268273
if err != nil {
269274
return fmt.Errorf("could not retrieve ctfe tuf targets: %s", err.Error())
270275
}
@@ -273,7 +278,7 @@ func setRootOfTrustCosignOptions(cosignOptions *cosign.CheckOpts, rootOfTrust Ro
273278
return fmt.Errorf("could not add public root of trust sct public key to collection: %w", err)
274279
}
275280
}
276-
} else {
281+
} else if rootOfTrust.SCTPublicKey != "" {
277282
if err := sctKeyCollection.AddTransparencyLogPubKey([]byte(rootOfTrust.SCTPublicKey), sigtuf.Active); err != nil {
278283
return fmt.Errorf("could not add custom root of trust sct public key to collection: %w", err)
279284
}
@@ -291,6 +296,12 @@ func setVerifierCosignOptions(cosignOptions *cosign.CheckOpts, verifier Verifier
291296
return fmt.Errorf("could not load PEM encoded public key of verifier %s under %s: %s", verifier.Name, rootOfTrust.Name, err.Error())
292297
}
293298
case "keyless":
299+
if rootOfTrust.RootlessKeypairsOnly {
300+
return fmt.Errorf("cannot use keyless verifier for root of trust with field RootlessKeypairsOnly set to true")
301+
}
302+
if rootOfTrust.RootCert == "" && !rootOfTrust.IsPublic() {
303+
return fmt.Errorf("cannot use keyless verifier %s with private root of trust without root cert", verifier.Name)
304+
}
294305
cosignOptions.Identities = []cosign.Identity{
295306
{
296307
Issuer: verifier.KeylessOptions.CertIssuer,
@@ -309,5 +320,9 @@ func setVerifierCosignOptions(cosignOptions *cosign.CheckOpts, verifier Verifier
309320
cosignOptions.IgnoreSCT = true
310321
}
311322
}
323+
if rootOfTrust.RootlessKeypairsOnly {
324+
cosignOptions.IgnoreSCT = true
325+
cosignOptions.IgnoreTlog = true
326+
}
312327
return nil
313328
}

public_root_of_trust.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (d inMemoryDest) Delete() error {
2525
panic("inMemoryDest delete function should not run")
2626
}
2727

28-
func GetTargets(usage sigtuf.UsageKind, proxy Proxy) ([]sigtuf.TargetFile, error) {
28+
func GetSigstorePublicTufTargets(usage sigtuf.UsageKind, proxy Proxy) ([]sigtuf.TargetFile, error) {
2929
// client initialization
3030
httpClient := &http.Client{
3131
Timeout: 20 * time.Second,

0 commit comments

Comments
 (0)