Skip to content

Commit

Permalink
debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-prindle committed Dec 13, 2023
1 parent 9e61860 commit 50a092c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 49 deletions.
7 changes: 7 additions & 0 deletions pkg/chains/formats/slsa/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,23 @@ import (
//
//nolint:all
func SubjectDigests(ctx context.Context, obj objects.TektonObject, slsaconfig *slsaconfig.SlsaConfig) []intoto.Subject {
logger := logging.FromContext(ctx)

logger.Infof("aprindle-20 - here")
var subjects []intoto.Subject

switch obj.GetObject().(type) {
case *v1.PipelineRun:
logger.Infof("aprindle-21 - here")
subjects = subjectsFromPipelineRun(ctx, obj, slsaconfig)
case *v1.TaskRun:
logger.Infof("aprindle-22 - here")
subjects = subjectsFromTektonObject(ctx, obj)
case *v1beta1.PipelineRun:
logger.Infof("aprindle-23 - here")
subjects = extractv1beta1.SubjectsFromPipelineRunV1Beta1(ctx, obj, slsaconfig)
case *v1beta1.TaskRun:
logger.Infof("aprindle-24 - here")
subjects = extractv1beta1.SubjectsFromTektonObjectV1Beta1(ctx, obj)
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/chains/formats/slsa/extract/v1beta1/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func SubjectsFromPipelineRunV1Beta1(ctx context.Context, obj objects.TektonObjec

pro := obj.(*objects.PipelineRunObjectV1Beta1)

logger.Infof("aprindle-50 - here")
pSpec := pro.Status.PipelineSpec
if pSpec != nil {
pipelineTasks := append(pSpec.Tasks, pSpec.Finally...)
Expand All @@ -79,7 +80,7 @@ func SubjectsFromPipelineRunV1Beta1(ctx context.Context, obj objects.TektonObjec
logger.Infof("taskrun status not found for task %s", t.Name)
continue
}

logger.Infof("aprindle-51 - here")
trSubjects := SubjectsFromTektonObjectV1Beta1(ctx, tr)
result = artifact.AppendSubjects(result, trSubjects...)
}
Expand All @@ -95,8 +96,10 @@ func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObje
logger := logging.FromContext(ctx)
var subjects []intoto.Subject

logger.Infof("aprindle-30 - here")
imgs := artifacts.ExtractOCIImagesFromResults(ctx, obj)
for _, i := range imgs {
logger.Infof("aprindle-31 - here")
if d, ok := i.(name.Digest); ok {
subjects = artifact.AppendSubjects(subjects, intoto.Subject{
Name: d.Repository.Name(),
Expand All @@ -107,13 +110,15 @@ func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObje
}
}

logger.Infof("aprindle-32 - here")
sts := artifacts.ExtractSignableTargetFromResults(ctx, obj)
for _, obj := range sts {
splits := strings.Split(obj.Digest, ":")
if len(splits) != 2 {
logger.Errorf("Digest %s should be in the format of: algorthm:abc", obj.Digest)
continue
}
logger.Infof("aprindle-33 - here")
subjects = artifact.AppendSubjects(subjects, intoto.Subject{
Name: obj.URI,
Digest: common.DigestSet{
Expand All @@ -122,11 +127,13 @@ func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObje
})
}

logger.Infof("aprindle-34 - here")
ssts := artifacts.ExtractStructuredTargetFromResults(ctx, obj, artifacts.ArtifactsOutputsResultName)
for _, s := range ssts {
splits := strings.Split(s.Digest, ":")
alg := splits[0]
digest := splits[1]
logger.Infof("aprindle-35 - here")
subjects = artifact.AppendSubjects(subjects, intoto.Subject{
Name: s.URI,
Digest: common.DigestSet{
Expand All @@ -142,17 +149,21 @@ func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObje
// More info: https://tekton.dev/docs/pipelines/resources/
tr, ok := obj.GetObject().(*v1beta1.TaskRun) //nolint:staticcheck
if !ok || tr.Spec.Resources == nil { //nolint:staticcheck
logger.Infof("aprindle-36 - here")
return subjects
}

logger.Infof("aprindle-25 - here")
// go through resourcesResult
for _, output := range tr.Spec.Resources.Outputs { //nolint:staticcheck
logger.Infof("aprindle-26 - here")
name := output.Name
if output.PipelineResourceBinding.ResourceSpec == nil {
continue
}
// similarly, we could do this for other pipeline resources or whatever thing replaces them
if output.PipelineResourceBinding.ResourceSpec.Type == backport.PipelineResourceTypeImage {
logger.Infof("aprindle-27 - here")
// get the url and digest, and save as a subject
var url, digest string
for _, s := range tr.Status.ResourcesResult {
Expand All @@ -173,6 +184,7 @@ func SubjectsFromTektonObjectV1Beta1(ctx context.Context, obj objects.TektonObje
})
}
}
logger.Infof("aprindle-28 - here")

return subjects
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/chains/formats/slsa/v1/intotoite6.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tektoncd/chains/pkg/config"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"knative.dev/pkg/logging"
)

const (
Expand Down Expand Up @@ -58,27 +59,35 @@ func (i *InTotoIte6) Wrap() bool {
}

func (i *InTotoIte6) CreatePayload(ctx context.Context, obj interface{}) (interface{}, error) {
logger := logging.FromContext(ctx)

logger.Infof("aprindle-40 - here")
switch v := obj.(type) {
// TODO(aaron-prindle) convert to v1beta1 before usage
case *objects.TaskRunObjectV1:
logger.Infof("aprindle-41 - here")
tro := obj.(*objects.TaskRunObjectV1)
trV1Beta1 := &v1beta1.TaskRun{} //nolint:staticcheck
if err := trV1Beta1.ConvertFrom(ctx, tro.GetObject().(*v1.TaskRun)); err != nil {
return nil, fmt.Errorf("error converting Tekton TaskRun from version v1 to v1beta1: %s", err)
}
return taskrun.GenerateAttestation(ctx, objects.NewTaskRunObjectV1Beta1(trV1Beta1), i.slsaConfig)
case *objects.PipelineRunObjectV1:
logger.Infof("aprindle-42 - here")
pro := obj.(*objects.PipelineRunObjectV1)
prV1Beta1 := &v1beta1.PipelineRun{} //nolint:staticcheck
if err := prV1Beta1.ConvertFrom(ctx, pro.GetObject().(*v1.PipelineRun)); err != nil {
return nil, fmt.Errorf("error converting Tekton PipelineRun from version v1 to v1beta1: %s", err)
}
return pipelinerun.GenerateAttestation(ctx, objects.NewPipelineRunObjectV1Beta1(prV1Beta1), i.slsaConfig)
case *objects.TaskRunObjectV1Beta1:
logger.Infof("aprindle-42 - here")
return taskrun.GenerateAttestation(ctx, v, i.slsaConfig)
case *objects.PipelineRunObjectV1Beta1:
logger.Infof("aprindle-43 - here")
return pipelinerun.GenerateAttestation(ctx, v, i.slsaConfig)
default:
logger.Infof("aprindle-44 - here")
return nil, fmt.Errorf("intoto does not support type: %s", v)
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/chains/formats/slsa/v1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ func buildConfig(ctx context.Context, pro *objects.PipelineRunObjectV1Beta1) Bui
tasks := []TaskAttestation{}

pSpec := pro.Status.PipelineSpec
logger.Infof("aprindle-10 - here")
if pSpec == nil {
logger.Infof("aprindle-11 - here")
return BuildConfig{}
}
pipelineTasks := append(pSpec.Tasks, pSpec.Finally...)

var last string
for i, t := range pipelineTasks {
tr := pro.GetTaskRunFromTask(t.Name)
logger.Infof("aprindle-12 - here")

// Ignore Tasks that did not execute during the PipelineRun.
if tr == nil || tr.Status.CompletionTime == nil {
Expand All @@ -103,6 +106,7 @@ func buildConfig(ctx context.Context, pro *objects.PipelineRunObjectV1Beta1) Bui
}
steps := []attest.StepAttestation{}
for i, stepState := range tr.Status.Steps {
logger.Infof("aprindle-60 - here")
step := tr.Status.TaskSpec.Steps[i]
steps = append(steps, attest.StepV1Beta1(&step, &stepState))
}
Expand Down
96 changes: 48 additions & 48 deletions test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ type TestExample struct {
// https://github.com/tektoncd/pipeline/blob/main/test/examples_test.go
func TestExamples(t *testing.T) {
tests := []TestExample{
{
name: "taskrun-examples-slsa-v1",
cm: map[string]string{
"artifacts.taskrun.format": "slsa/v1",
"artifacts.oci.storage": "tekton",
},
getExampleObjects: getTaskRunExamples,
payloadKey: "chains.tekton.dev/payload-taskrun-%s",
signatureKey: "chains.tekton.dev/signature-taskrun-%s",
outputLocation: "slsa/v1",
predicate: "slsav0.1",
},
// {
// name: "taskrun-examples-slsa-v1",
// cm: map[string]string{
// "artifacts.taskrun.format": "slsa/v1",
// "artifacts.oci.storage": "tekton",
// },
// getExampleObjects: getTaskRunExamples,
// payloadKey: "chains.tekton.dev/payload-taskrun-%s",
// signatureKey: "chains.tekton.dev/signature-taskrun-%s",
// outputLocation: "slsa/v1",
// predicate: "slsav0.1",
// },
{
name: "pipelinerun-examples-slsa-v1",
cm: map[string]string{
Expand All @@ -95,42 +95,42 @@ func TestExamples(t *testing.T) {
outputLocation: "slsa/v1",
predicate: "slsav0.1",
},
{
name: "taskrun-examples-slsa-v2",
cm: map[string]string{
"artifacts.taskrun.format": "slsa/v2alpha1",
"artifacts.oci.storage": "tekton",
},
getExampleObjects: getTaskRunExamples,
payloadKey: "chains.tekton.dev/payload-taskrun-%s",
signatureKey: "chains.tekton.dev/signature-taskrun-%s",
outputLocation: "slsa/v2",
predicate: "slsav0.2",
},
{
name: "taskrun-examples-slsa-v2alpha2",
cm: map[string]string{
"artifacts.taskrun.format": "slsa/v2alpha2",
"artifacts.oci.storage": "tekton",
},
getExampleObjects: getTaskRunExamples,
payloadKey: "chains.tekton.dev/payload-taskrun-%s",
signatureKey: "chains.tekton.dev/signature-taskrun-%s",
outputLocation: "slsa/v2alpha2",
predicate: "slsav1.0",
},
{
name: "pipelinerun-examples-slsa-v2alpha2",
cm: map[string]string{
"artifacts.pipelinerun.format": "slsa/v2alpha2",
"artifacts.oci.storage": "tekton",
},
getExampleObjects: getPipelineRunExamples,
payloadKey: "chains.tekton.dev/payload-pipelinerun-%s",
signatureKey: "chains.tekton.dev/signature-pipelinerun-%s",
outputLocation: "slsa/v2alpha2",
predicate: "slsav1.0",
},
// {
// name: "taskrun-examples-slsa-v2",
// cm: map[string]string{
// "artifacts.taskrun.format": "slsa/v2alpha1",
// "artifacts.oci.storage": "tekton",
// },
// getExampleObjects: getTaskRunExamples,
// payloadKey: "chains.tekton.dev/payload-taskrun-%s",
// signatureKey: "chains.tekton.dev/signature-taskrun-%s",
// outputLocation: "slsa/v2",
// predicate: "slsav0.2",
// },
// {
// name: "taskrun-examples-slsa-v2alpha2",
// cm: map[string]string{
// "artifacts.taskrun.format": "slsa/v2alpha2",
// "artifacts.oci.storage": "tekton",
// },
// getExampleObjects: getTaskRunExamples,
// payloadKey: "chains.tekton.dev/payload-taskrun-%s",
// signatureKey: "chains.tekton.dev/signature-taskrun-%s",
// outputLocation: "slsa/v2alpha2",
// predicate: "slsav1.0",
// },
// {
// name: "pipelinerun-examples-slsa-v2alpha2",
// cm: map[string]string{
// "artifacts.pipelinerun.format": "slsa/v2alpha2",
// "artifacts.oci.storage": "tekton",
// },
// getExampleObjects: getPipelineRunExamples,
// payloadKey: "chains.tekton.dev/payload-pipelinerun-%s",
// signatureKey: "chains.tekton.dev/signature-pipelinerun-%s",
// outputLocation: "slsa/v2alpha2",
// predicate: "slsav1.0",
// },
}

for _, test := range tests {
Expand Down

0 comments on commit 50a092c

Please sign in to comment.