From a033c267fadb19c2d43aa893f2b7e1e54fa167c4 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 13 Dec 2022 08:07:11 -0600 Subject: [PATCH] :seedling: Retries for signing the results with rekor - Included retries for signing the results with rekor. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- signing/signing.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/signing/signing.go b/signing/signing.go index bef7da77..a763fa56 100644 --- a/signing/signing.go +++ b/signing/signing.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" "io" + "log" "net/http" "net/url" "os" @@ -74,6 +75,7 @@ func New(token string) (*Signing, error) { // SignScorecardResult signs the results file and uploads the attestation to the Rekor transparency log. func (s *Signing) SignScorecardResult(scorecardResultsFile string) error { // Prepare settings for SignBlobCmd. + numberOfRetries := 3 rootOpts := &sigOpts.RootOptions{Timeout: sigOpts.DefaultTimeout} // Just the timeout. keyOpts := sigOpts.KeyOpts{ FulcioURL: sigOpts.DefaultFulcioURL, // Signing certificate provider. @@ -86,8 +88,16 @@ func (s *Signing) SignScorecardResult(scorecardResultsFile string) error { // This command will use the provided OIDCIssuer to authenticate into Fulcio, which will generate the // signing certificate on the scorecard result. This attestation is then uploaded to the Rekor transparency log. // The output bytes (signature) and certificate are discarded since verification can be done with just the payload. - if _, err := sign.SignBlobCmd(rootOpts, keyOpts, regOpts, scorecardResultsFile, true, "", ""); err != nil { - return fmt.Errorf("error signing payload: %w", err) + for i := 0; i < numberOfRetries; i++ { // Retry in case of network errors. + if _, err := sign.SignBlobCmd(rootOpts, keyOpts, regOpts, scorecardResultsFile, true, "", ""); err != nil { + log.Printf("error signing scorecard results: %v\n", err) + if i == numberOfRetries-1 { + return fmt.Errorf("error signing scorecard results: %w", err) + } + } else { + break + } + time.Sleep(5 * time.Second) // Wait 5 seconds before retrying. } return nil