-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide support for multiple buildTypes. The initial types are to
support more general slsa verifiers and provide more verbose output for tekton verifiers. This implementation will default to the slsa buildType.
- Loading branch information
1 parent
94d0d16
commit 3620b9b
Showing
16 changed files
with
1,044 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
pkg/chains/formats/slsa/v2alpha2/internal/build_types/build_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package buildtypes | ||
|
||
const ( | ||
SlsaBuildType = "https://tekton.dev/chains/v2/slsa" | ||
TektonBuildType = "https://tekton.dev/chains/v2/slsa-tekton" | ||
) |
44 changes: 44 additions & 0 deletions
44
pkg/chains/formats/slsa/v2alpha2/internal/external_parameters/external_parameters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package externalparameters | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tektoncd/chains/pkg/chains/objects" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
) | ||
|
||
func buildConfigSource(provenance *v1beta1.Provenance) map[string]string { | ||
ref := "" | ||
for alg, hex := range provenance.RefSource.Digest { | ||
ref = fmt.Sprintf("%s:%s", alg, hex) | ||
break | ||
} | ||
buildConfigSource := map[string]string{ | ||
"ref": ref, | ||
"repository": provenance.RefSource.URI, | ||
"path": provenance.RefSource.EntryPoint, | ||
} | ||
return buildConfigSource | ||
} | ||
|
||
// PipelineRun adds the pipeline run spec and provenance if available | ||
func PipelineRun(pro *objects.PipelineRunObject) map[string]any { | ||
externalParams := make(map[string]any) | ||
|
||
if provenance := pro.GetRemoteProvenance(); provenance != nil { | ||
externalParams["buildConfigSource"] = buildConfigSource(provenance) | ||
} | ||
externalParams["runSpec"] = pro.Spec | ||
return externalParams | ||
} | ||
|
||
// TaskRun adds the task run spec and provenance if available | ||
func TaskRun(tro *objects.TaskRunObject) map[string]any { | ||
externalParams := make(map[string]any) | ||
|
||
if provenance := tro.GetRemoteProvenance(); provenance != nil { | ||
externalParams["buildConfigSource"] = buildConfigSource(provenance) | ||
} | ||
externalParams["runSpec"] = tro.Spec | ||
return externalParams | ||
} |
97 changes: 97 additions & 0 deletions
97
pkg/chains/formats/slsa/v2alpha2/internal/external_parameters/external_parameters_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package externalparameters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/tektoncd/chains/pkg/chains/objects" | ||
"github.com/tektoncd/chains/pkg/internal/objectloader" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
) | ||
|
||
func TestBuildConfigSource(t *testing.T) { | ||
provenance := &v1beta1.Provenance{ | ||
RefSource: &v1beta1.RefSource{ | ||
Digest: map[string]string{"alg1": "hex1", "alg2": "hex2"}, | ||
URI: "https://tekton.com", | ||
EntryPoint: "/path/to/entry", | ||
}, | ||
} | ||
|
||
want := map[string]string{ | ||
"ref": "alg1:hex1", | ||
"repository": "https://tekton.com", | ||
"path": "/path/to/entry", | ||
} | ||
|
||
got := buildConfigSource(provenance) | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("buildConfigSource(): -want +got: %s", diff) | ||
} | ||
} | ||
func createPro(path string) *objects.PipelineRunObject { | ||
pr, err := objectloader.PipelineRunFromFile(path) | ||
if err != nil { | ||
panic(err) | ||
} | ||
tr1, err := objectloader.TaskRunFromFile("../../../testdata/v2alpha2/taskrun1.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
tr2, err := objectloader.TaskRunFromFile("../../../testdata/v2alpha2/taskrun2.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
p := objects.NewPipelineRunObject(pr) | ||
p.AppendTaskRun(tr1) | ||
p.AppendTaskRun(tr2) | ||
return p | ||
} | ||
|
||
func TestPipelineRun(t *testing.T) { | ||
pro := createPro("../../../testdata/v2alpha2/pipelinerun1.json") | ||
|
||
got := PipelineRun(pro) | ||
|
||
want := map[string]any{ | ||
"runSpec": v1beta1.PipelineRunSpec{ | ||
PipelineRef: &v1beta1.PipelineRef{Name: "test-pipeline"}, | ||
Params: v1beta1.Params{ | ||
{ | ||
Name: "IMAGE", | ||
Value: v1beta1.ParamValue{Type: "string", StringVal: "test.io/test/image"}, | ||
}, | ||
}, | ||
ServiceAccountName: "pipeline", | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("PipelineRun(): -want +got: %s", diff) | ||
} | ||
} | ||
|
||
func TestTaskRun(t *testing.T) { | ||
tr, err := objectloader.TaskRunFromFile("../../../testdata/v2alpha2/taskrun1.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got := TaskRun(objects.NewTaskRunObject(tr)) | ||
|
||
want := map[string]any{ | ||
"runSpec": v1beta1.TaskRunSpec{ | ||
Params: v1beta1.Params{ | ||
{Name: "IMAGE", Value: v1beta1.ParamValue{Type: "string", StringVal: "test.io/test/image"}}, | ||
{Name: "CHAINS-GIT_COMMIT", Value: v1beta1.ParamValue{Type: "string", StringVal: "taskrun"}}, | ||
{Name: "CHAINS-GIT_URL", Value: v1beta1.ParamValue{Type: "string", StringVal: "https://git.test.com"}}, | ||
}, | ||
ServiceAccountName: "default", | ||
TaskRef: &v1beta1.TaskRef{Name: "build", Kind: "Task"}, | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("TaskRun(): -want +got: %s", diff) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
pkg/chains/formats/slsa/v2alpha2/internal/internal_parameters/internal_parameters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package internalparameters | ||
|
||
import ( | ||
"github.com/tektoncd/chains/pkg/chains/objects" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
) | ||
|
||
// SLSAInternalParameters provides the chains config as internalparameters | ||
func SLSAInternalParameters(tko objects.TektonObject) map[string]any { | ||
internalParams := make(map[string]any) | ||
if provenance := tko.GetProvenance(); provenance != (*v1beta1.Provenance)(nil) && provenance.FeatureFlags != nil { | ||
internalParams["tekton-pipelines-feature-flags"] = *provenance.FeatureFlags | ||
} | ||
return internalParams | ||
} | ||
|
||
// TektonInternalParameters provides the chains config as well as annotations and labels | ||
func TektonInternalParameters(tko objects.TektonObject) map[string]any { | ||
internalParams := make(map[string]any) | ||
if provenance := tko.GetProvenance(); provenance != (*v1beta1.Provenance)(nil) && provenance.FeatureFlags != nil { | ||
internalParams["tekton-pipelines-feature-flags"] = *provenance.FeatureFlags | ||
} | ||
internalParams["labels"] = tko.GetLabels() | ||
internalParams["annotations"] = tko.GetAnnotations() | ||
return internalParams | ||
} |
44 changes: 44 additions & 0 deletions
44
pkg/chains/formats/slsa/v2alpha2/internal/internal_parameters/internal_parameters_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package internalparameters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/tektoncd/chains/pkg/chains/objects" | ||
"github.com/tektoncd/chains/pkg/internal/objectloader" | ||
"github.com/tektoncd/pipeline/pkg/apis/config" | ||
) | ||
|
||
func TestTektonInternalParameters(t *testing.T) { | ||
tr, err := objectloader.TaskRunFromFile("../../../testdata/v2alpha2/taskrun1.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tro := objects.NewTaskRunObject(tr) | ||
got := TektonInternalParameters(tro) | ||
want := map[string]any{ | ||
"labels": tro.GetLabels(), | ||
"annotations": tro.GetAnnotations(), | ||
"tekton-pipelines-feature-flags": config.FeatureFlags{EnableAPIFields: "beta", ResultExtractionMethod: "termination-message"}, | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("TaskRun(): -want +got: %s", diff) | ||
} | ||
} | ||
|
||
func TestSLSAInternalParameters(t *testing.T) { | ||
tr, err := objectloader.TaskRunFromFile("../../../testdata/v2alpha2/taskrun1.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tro := objects.NewTaskRunObject(tr) | ||
got := SLSAInternalParameters(tro) | ||
want := map[string]any{ | ||
"tekton-pipelines-feature-flags": config.FeatureFlags{EnableAPIFields: "beta", ResultExtractionMethod: "termination-message"}, | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("TaskRun(): -want +got: %s", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.