From f406d38724894c56cff216126a777210dcfb0e0c Mon Sep 17 00:00:00 2001 From: Joe Stuart Date: Mon, 7 Aug 2023 21:58:08 -0500 Subject: [PATCH] default to slsa build type --- .../internal/build_definitions/build_definitions.go | 2 +- .../v2alpha2/internal/pipelinerun/pipelinerun.go | 12 +++++++++--- .../slsa/v2alpha2/internal/taskrun/taskrun.go | 13 ++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/chains/formats/slsa/v2alpha2/internal/build_definitions/build_definitions.go b/pkg/chains/formats/slsa/v2alpha2/internal/build_definitions/build_definitions.go index 02766e1f46..7510b0a18a 100644 --- a/pkg/chains/formats/slsa/v2alpha2/internal/build_definitions/build_definitions.go +++ b/pkg/chains/formats/slsa/v2alpha2/internal/build_definitions/build_definitions.go @@ -2,5 +2,5 @@ package builddefinitions const ( SlsaBuildType = "https://tekton.dev/chains/v2/slsa" - TektonBuildType = "" + TektonBuildType = "https://tekton.dev/chains/v2/slsa-tekton" ) diff --git a/pkg/chains/formats/slsa/v2alpha2/internal/pipelinerun/pipelinerun.go b/pkg/chains/formats/slsa/v2alpha2/internal/pipelinerun/pipelinerun.go index e50ab4573a..2d9041405d 100644 --- a/pkg/chains/formats/slsa/v2alpha2/internal/pipelinerun/pipelinerun.go +++ b/pkg/chains/formats/slsa/v2alpha2/internal/pipelinerun/pipelinerun.go @@ -57,7 +57,7 @@ func GenerateAttestation(ctx context.Context, pro *objects.PipelineRunObject, sl }, Predicate: slsa.ProvenancePredicate{ BuildDefinition: slsa.ProvenanceBuildDefinition{ - BuildType: slsaconfig.BuildType, + BuildType: bd.BuildType, ExternalParameters: bd.GetExternalParameters(), InternalParameters: bd.GetInternalParameters(), ResolvedDependencies: rd, @@ -108,10 +108,16 @@ func byproducts(pro *objects.PipelineRunObject) ([]slsa.ResourceDescriptor, erro } func getBuildDefinition(buildType string, pro *objects.PipelineRunObject) (builddefinitions.PipelineBuildType, error) { - switch buildType { + // if buildType is not set in the chains-config, default to slsa build type + buildDefinitionType := buildType + if buildType == "" { + buildDefinitionType = builddefinitions.SlsaBuildType + } + + switch buildDefinitionType { case builddefinitions.SlsaBuildType: return builddefinitions.PipelineBuildType{ - BuildType: buildType, + BuildType: buildDefinitionType, Pro: pro, InternalParameters: builddefinitions.SLSAPipelineInternalParameters, AddTaskDescriptorContent: builddefinitions.AddSLSATaskDescriptor, diff --git a/pkg/chains/formats/slsa/v2alpha2/internal/taskrun/taskrun.go b/pkg/chains/formats/slsa/v2alpha2/internal/taskrun/taskrun.go index 5689622bea..18106ff8e8 100644 --- a/pkg/chains/formats/slsa/v2alpha2/internal/taskrun/taskrun.go +++ b/pkg/chains/formats/slsa/v2alpha2/internal/taskrun/taskrun.go @@ -53,7 +53,7 @@ func GenerateAttestation(ctx context.Context, tro *objects.TaskRunObject, slsaCo }, Predicate: slsa.ProvenancePredicate{ BuildDefinition: slsa.ProvenanceBuildDefinition{ - BuildType: slsaConfig.BuildType, + BuildType: bd.BuildType, ExternalParameters: bd.GetExternalParameters(), InternalParameters: bd.GetInternalParameters(), ResolvedDependencies: rd, @@ -104,10 +104,17 @@ func byproducts(tro *objects.TaskRunObject) ([]slsa.ResourceDescriptor, error) { } func getBuildDefinition(buildType string, tro *objects.TaskRunObject) (builddefinitions.TaskBuildType, error) { - switch buildType { + // if buildType is not set in the chains-config, default to slsa build type + buildDefinitionType := buildType + if buildType == "" { + buildDefinitionType = builddefinitions.SlsaBuildType + } + + switch buildDefinitionType { + // if buildType is not set in the chains-config, default to slsa build type case builddefinitions.SlsaBuildType: return builddefinitions.TaskBuildType{ - BuildType: buildType, + BuildType: buildDefinitionType, Tro: tro, InternalParameters: builddefinitions.SLSATaskInternalParameters, }, nil