diff --git a/pkg/chains/signing.go b/pkg/chains/signing.go index 6a28b5e349..17f6b09b72 100644 --- a/pkg/chains/signing.go +++ b/pkg/chains/signing.go @@ -28,6 +28,7 @@ import ( "github.com/tektoncd/chains/pkg/chains/signing/x509" "github.com/tektoncd/chains/pkg/chains/storage" "github.com/tektoncd/chains/pkg/config" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" versioned "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" "k8s.io/apimachinery/pkg/util/sets" "knative.dev/pkg/logging" @@ -134,10 +135,10 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) // Extract all the "things" to be signed. // We might have a few of each type (several binaries, or images) - objects := signableType.ExtractObjects(ctx, tektonObj) + objs := signableType.ExtractObjects(ctx, tektonObj) // Go through each object one at a time. - for _, obj := range objects { + for _, obj := range objs { payload, err := payloader.CreatePayload(ctx, obj) if err != nil { @@ -178,6 +179,33 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) // Now store those! for _, backend := range sets.List[string](signableType.StorageBackend(cfg)) { + // TODO(https://github.com/tektoncd/chains/issues/1026) add support for passing v1 object (vs converted v1beta1) for v2alpha3+ + + // convert types to v1beta1 as needed for backwards compatibility + var storageObj objects.TektonObject + switch v := obj.(type) { + case *objects.TaskRunObjectV1: + trV1Beta1 := &v1beta1.TaskRun{} //nolint:staticcheck + if err := trV1Beta1.ConvertFrom(ctx, v); err != nil { + return fmt.Errorf("error converting Tekton TaskRun from version v1 to v1beta1: %s", err) + } + storageObj = objects.NewTaskRunObjectV1Beta1(trV1Beta1) + case *objects.PipelineRunObjectV1: + prV1Beta1 := &v1beta1.PipelineRun{} //nolint:staticcheck + if err := prV1Beta1.ConvertFrom(ctx, v); err != nil { + return fmt.Errorf("error converting Tekton PipelineRun from version v1 to v1beta1: %s", err) + } + proV1Beta1 := objects.NewPipelineRunObjectV1Beta1(prV1Beta1) + trs := pro.GetTaskRuns() + for _, tr := range trs { + trV1Beta1 := &v1beta1.TaskRun{} //nolint:staticcheck + if err := trV1Beta1.ConvertFrom(ctx, tr); err != nil { + return fmt.Errorf("error converting Tekton TaskRun from version v1 to v1beta1: %s", err) + } + proV1Beta1.AppendTaskRun(trV1Beta1) + } + storageObj = proV1Beta1 + b := o.Backends[backend] storageOpts := config.StorageOpts{ ShortKey: signableType.ShortKey(obj), @@ -186,7 +214,7 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) Chain: signer.Chain(), PayloadFormat: payloadFormat, } - if err := b.StorePayload(ctx, tektonObj, rawPayload, string(signature), storageOpts); err != nil { + if err := b.StorePayload(ctx, storageObj, rawPayload, string(signature), storageOpts); err != nil { logger.Error(err) merr = multierror.Append(merr, err) }