Skip to content

Commit a887da5

Browse files
authored
debug: add error messages for debugging with rekor (slsa-framework#159)
* add error messages for debugging with rekor Signed-off-by: Asra Ali <[email protected]>
1 parent b326c4d commit a887da5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pkg/provenance.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"fmt"
9+
"os"
910
"strings"
1011

1112
"golang.org/x/mod/semver"
@@ -59,23 +60,25 @@ func verifySha256Digest(prov *intoto.ProvenanceStatement, expectedHash string) e
5960
// and the signing certificate given the provenance and artifact hash.
6061
func VerifyProvenanceSignature(ctx context.Context, rClient *client.Rekor, provenance []byte, artifactHash string) (*dsselib.Envelope, *x509.Certificate, error) {
6162
// Get Rekor entries corresponding to provenance
62-
if env, cert, err := GetRekorEntriesWithCert(rClient, provenance); err == nil {
63+
env, cert, err := GetRekorEntriesWithCert(rClient, provenance)
64+
if err == nil {
6365
return env, cert, nil
6466
}
6567

6668
// Fallback on using the redis search index to get matching UUIDs.
69+
fmt.Fprintf(os.Stderr, "Getting rekor entry error %s, trying Redis search index to find entries by subject digest\n", err)
6770
uuids, err := GetRekorEntries(rClient, artifactHash)
6871
if err != nil {
6972
return nil, nil, err
7073
}
7174

72-
env, err := EnvelopeFromBytes(provenance)
75+
env, err = EnvelopeFromBytes(provenance)
7376
if err != nil {
7477
return nil, nil, err
7578
}
7679

7780
// Verify the provenance and return the signing certificate.
78-
cert, err := FindSigningCertificate(ctx, uuids, *env, rClient)
81+
cert, err = FindSigningCertificate(ctx, uuids, *env, rClient)
7982
if err != nil {
8083
return nil, nil, err
8184
}

pkg/rekor.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"os"
14+
"strings"
1415
"time"
1516

1617
cjson "github.com/docker/go/canonical/json"
@@ -168,7 +169,7 @@ func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string
168169
}
169170
}
170171
if entryVerError != nil {
171-
return nil, fmt.Errorf("%w: %s", err, "error verifying root hash")
172+
return nil, fmt.Errorf("%w: %s", entryVerError, "error verifying root hash")
172173
}
173174

174175
// Verify the entry's inclusion
@@ -341,18 +342,25 @@ func FindSigningCertificate(ctx context.Context, uuids []string, dssePayload dss
341342
// * Verify dsse envelope signature against signing certificate.
342343
// * Check signature expiration against IntegratedTime in entry.
343344
// * If all succeed, return the signing certificate.
345+
var errs []string
344346
for _, uuid := range uuids {
345347
entry, err := verifyTlogEntryByUUID(ctx, rClient, uuid)
346348
if err != nil {
349+
// this is unexpected, hold on to this error.
350+
errs = append(errs, fmt.Sprintf("%s: verifying tlog entry %s", err, uuid))
347351
continue
348352
}
349353
cert, err := extractCert(entry)
350354
if err != nil {
355+
// this is unexpected, hold on to this error.
356+
errs = append(errs, fmt.Sprintf("%s: extracting certificate from %s", err, uuid))
351357
continue
352358
}
353359

354360
roots, err := fulcio.GetRoots()
355361
if err != nil {
362+
// this is unexpected, hold on to this error.
363+
errs = append(errs, fmt.Sprintf("%s: retrieving fulcio root", err))
356364
continue
357365
}
358366
co := &cosign.CheckOpts{
@@ -383,5 +391,5 @@ func FindSigningCertificate(ctx context.Context, uuids []string, dssePayload dss
383391
return cert, nil
384392
}
385393

386-
return nil, ErrorNoValidRekorEntries
394+
return nil, fmt.Errorf("%w: got unexpected errors %s", ErrorNoValidRekorEntries, strings.Join(errs, ", "))
387395
}

0 commit comments

Comments
 (0)