Skip to content

Commit 4dfcd62

Browse files
authored
feat(controlplane): store and show the digest in CAS of the attestation (#329)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 36d453d commit 4dfcd62

23 files changed

+467
-156
lines changed

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func workflowRunDescribeTableOutput(run *action.WorkflowRunItemFull) error {
116116
gt.AppendRow(table.Row{"Statement"})
117117
gt.AppendSeparator()
118118
gt.AppendRow(table.Row{"Payload Type", att.Envelope.PayloadType})
119+
gt.AppendRow(table.Row{"Digest", att.Digest})
119120
color := text.FgHiRed
120121
if run.Verified {
121122
color = text.FgHiGreen

app/cli/internal/action/workflow_run_describe.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type WorkflowRunAttestationItem struct {
5050
Materials []*Material `json:"materials,omitempty"`
5151
EnvVars []*EnvVar `json:"envvars,omitempty"`
5252
Annotations []*Annotation `json:"annotations,omitempty"`
53+
// Digest in CAS backend
54+
Digest string `json:"digest"`
5355
}
5456

5557
type Material struct {
@@ -153,6 +155,7 @@ func (action *WorkflowRunDescribe) Run(runID string, verify bool, publicKey stri
153155
EnvVars: envVars,
154156
Materials: materials,
155157
Annotations: annotations,
158+
Digest: attestation.DigestInCasBackend,
156159
}
157160

158161
return item, nil

app/controlplane/api/controlplane/v1/response_messages.pb.go

Lines changed: 145 additions & 133 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.pb.validate.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ message AttestationItem {
5353
google.protobuf.Timestamp created_at = 2;
5454
// encoded DSEE envelope
5555
bytes envelope = 3;
56+
// sha256sum of the envelope in json format, used as a key in the CAS backend
57+
string digest_in_cas_backend = 7;
5658

5759
// denormalized envelope/statement content
5860
repeated EnvVariable env_vars = 4;

app/controlplane/api/controlplane/v1/status_http.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/biz/mocks/WorkflowRunRepo.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/biz/workflowrun.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
package biz
1717

1818
import (
19+
"bytes"
1920
"context"
21+
"encoding/json"
2022
"errors"
23+
"fmt"
2124
"io"
2225
"time"
2326

2427
"github.com/chainloop-dev/chainloop/app/controlplane/internal/pagination"
2528
"github.com/secure-systems-lab/go-securesystemslib/dsse"
2629

2730
"github.com/go-kratos/kratos/v2/log"
31+
cr_v1 "github.com/google/go-containerregistry/pkg/v1"
2832
"github.com/google/uuid"
2933
)
3034

@@ -41,6 +45,7 @@ type WorkflowRun struct {
4145

4246
type Attestation struct {
4347
Envelope *dsse.Envelope
48+
Digest string
4449
}
4550

4651
type WorkflowRunWithContract struct {
@@ -63,7 +68,7 @@ type WorkflowRunRepo interface {
6368
FindByID(ctx context.Context, ID uuid.UUID) (*WorkflowRun, error)
6469
FindByIDInOrg(ctx context.Context, orgID, ID uuid.UUID) (*WorkflowRun, error)
6570
MarkAsFinished(ctx context.Context, ID uuid.UUID, status WorkflowRunStatus, reason string) error
66-
SaveAttestation(ctx context.Context, ID uuid.UUID, att *dsse.Envelope) error
71+
SaveAttestation(ctx context.Context, ID uuid.UUID, att *dsse.Envelope, digest string) error
6772
List(ctx context.Context, orgID, workflowID uuid.UUID, p *pagination.Options) ([]*WorkflowRun, string, error)
6873
// List the runs that have not finished and are older than a given time
6974
ListNotFinishedOlderThan(ctx context.Context, olderThan time.Time) ([]*WorkflowRun, error)
@@ -217,7 +222,18 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, en
217222
return NewErrInvalidUUID(err)
218223
}
219224

220-
return uc.wfRunRepo.SaveAttestation(ctx, runID, envelope)
225+
// Calculate the attestation hash of the json representation of the envelope
226+
jsonAtt, err := json.Marshal(envelope)
227+
if err != nil {
228+
return NewErrValidation(fmt.Errorf("marshaling attestation: %w", err))
229+
}
230+
231+
h, _, err := cr_v1.SHA256(bytes.NewBuffer(jsonAtt))
232+
if err != nil {
233+
return fmt.Errorf("calculating attestation hash: %w", err)
234+
}
235+
236+
return uc.wfRunRepo.SaveAttestation(ctx, runID, envelope, h.String())
221237
}
222238

223239
// List the workflowruns associated with an org and optionally filtered by a workflow

app/controlplane/internal/biz/workflowrun_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
5656
// Retrieve attestation ref from storage and compare
5757
r, err := s.WorkflowRun.View(ctx, s.org.ID, run.ID.String())
5858
assert.NoError(err)
59-
assert.Equal(r.Attestation, &biz.Attestation{Envelope: validEnvelope})
59+
assert.Equal(r.Attestation, &biz.Attestation{Envelope: validEnvelope, Digest: "sha256:f845058d865c3d4d491c9019f6afe9c543ad2cd11b31620cc512e341fb03d3d8"})
6060
})
6161
}
6262

0 commit comments

Comments
 (0)