Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the ServiceAccount running a pipeline in the chains provenance #1145

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/chains/formats/slsa/v1/intotoite6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ func getBuildPipelineRun() pipelinerun.BuildConfig {
Name: "git-clone",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
ServiceAccountName: "pipeline",
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "git clone",
Expand Down Expand Up @@ -626,9 +627,10 @@ func getBuildPipelineRun() pipelinerun.BuildConfig {
Name: "build",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
ServiceAccountName: "pipeline",
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "",
Expand Down
36 changes: 19 additions & 17 deletions pkg/chains/formats/slsa/v1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ type BuildConfig struct {
}

type TaskAttestation struct {
Name string `json:"name,omitempty"`
After []string `json:"after,omitempty"`
Ref v1beta1.TaskRef `json:"ref,omitempty"`
StartedOn time.Time `json:"startedOn,omitempty"`
FinishedOn time.Time `json:"finishedOn,omitempty"`
Status string `json:"status,omitempty"`
Steps []attest.StepAttestation `json:"steps,omitempty"`
Invocation slsa.ProvenanceInvocation `json:"invocation,omitempty"`
Results []v1beta1.TaskRunResult `json:"results,omitempty"`
Name string `json:"name,omitempty"`
After []string `json:"after,omitempty"`
Ref v1beta1.TaskRef `json:"ref,omitempty"`
StartedOn time.Time `json:"startedOn,omitempty"`
FinishedOn time.Time `json:"finishedOn,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Status string `json:"status,omitempty"`
Steps []attest.StepAttestation `json:"steps,omitempty"`
Invocation slsa.ProvenanceInvocation `json:"invocation,omitempty"`
Results []v1beta1.TaskRunResult `json:"results,omitempty"`
}

const statementInTotoV01 = "https://in-toto.io/Statement/v0.1"
Expand Down Expand Up @@ -149,14 +150,15 @@ func buildConfig(ctx context.Context, pro *objects.PipelineRunObjectV1Beta1) Bui
}

task := TaskAttestation{
Name: t.Name,
After: after,
StartedOn: tr.Status.StartTime.Time.UTC(),
FinishedOn: tr.Status.CompletionTime.Time.UTC(),
Status: getStatus(tr.Status.Conditions),
Steps: steps,
Invocation: attest.Invocation(tr, params, paramSpecs),
Results: tr.Status.TaskRunResults,
Name: t.Name,
After: after,
StartedOn: tr.Status.StartTime.Time.UTC(),
FinishedOn: tr.Status.CompletionTime.Time.UTC(),
ServiceAccountName: pro.Spec.ServiceAccountName,
Status: getStatus(tr.Status.Conditions),
Steps: steps,
Invocation: attest.Invocation(tr, params, paramSpecs),
Results: tr.Status.TaskRunResults,
}

if t.TaskRef != nil {
Expand Down
28 changes: 16 additions & 12 deletions pkg/chains/formats/slsa/v1/pipelinerun/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func TestBuildConfig(t *testing.T) {
Name: "git-clone",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
ServiceAccountName: "pipeline",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "git clone",
Expand Down Expand Up @@ -148,9 +149,10 @@ func TestBuildConfig(t *testing.T) {
Name: "build",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
ServiceAccountName: "pipeline",
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "",
Expand Down Expand Up @@ -285,9 +287,10 @@ func TestBuildConfigTaskOrder(t *testing.T) {
Name: "git-clone",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
ServiceAccountName: "pipeline",
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "git clone",
Expand Down Expand Up @@ -341,9 +344,10 @@ func TestBuildConfigTaskOrder(t *testing.T) {
Name: "build",
Kind: "ClusterTask",
},
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
Status: "Succeeded",
StartedOn: e1BuildStart,
FinishedOn: e1BuildFinished,
ServiceAccountName: "pipeline",
Status: "Succeeded",
Steps: []attest.StepAttestation{
{
EntryPoint: "",
Expand Down
1 change: 1 addition & 0 deletions test/testdata/slsa/v1/pipeline-output-image.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ref": {},
"startedOn": "{{index .BuildStartTimes 0}}",
"finishedOn": "{{index .BuildFinishedTimes 0}}",
"serviceAccountName": "default",
"status": "Succeeded",
"steps": [
{
Expand Down
Loading