Skip to content

Commit b1767e6

Browse files
authored
feat(controlplane): store attestation in DB (#180)
* feat(controlplane): store attestation in DB Signed-off-by: Miguel Martinez Trivino <[email protected]> * wrap attestation Signed-off-by: Miguel Martinez Trivino <[email protected]> * update docs Signed-off-by: Miguel Martinez Trivino <[email protected]> * update docs Signed-off-by: Miguel Martinez Trivino <[email protected]> * update docs Signed-off-by: Miguel Martinez Trivino <[email protected]> --------- Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 59caa39 commit b1767e6

20 files changed

+152
-383
lines changed

app/controlplane/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The control plane has 4 main dependencies
2323
- Sensitive information provided by the user such as OCI registry credentials is sent to a secret storage backend. Currently we support [Hashicorp Vault](https://www.vaultproject.io/), [AWS Secret Manager](https://aws.amazon.com/secrets-manager/) and [GCP Secret Manager](https://cloud.google.com/secret-manager).
2424
- In addition to those third party dependencies, the control plane also has a dependency on Chainloop own [Artifact CAS](../artifact-cas). It is used to upload the received attestation to the end-user storage backend.
2525

26-
> NOTE: The control plane does not store attestation or artifact data, these get forwarded to the user storage backend through the Artifact CAS.
26+
> NOTE: The control plane does not store artifacts, these get forwarded to the user storage backend (i.e OCI registry) through the Artifact CAS.
2727
2828
## Runbook
2929

app/controlplane/cmd/wire_gen.go

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

app/controlplane/internal/biz/attestation.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

app/controlplane/internal/biz/attestation_test.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

app/controlplane/internal/biz/biz.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var ProviderSet = wire.NewSet(
2424
NewRootAccountUseCase,
2525
NewWorkflowRunUseCase,
2626
NewOrganizationUseCase,
27-
NewAttestationUseCase,
2827
NewWorkflowContractUseCase,
2928
NewCASCredentialsUseCase,
3029
NewOCIRepositoryUseCase,

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

Lines changed: 7 additions & 20 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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ package biz
1717

1818
import (
1919
"context"
20-
"errors"
2120
"io"
2221
"time"
2322

2423
"github.com/chainloop-dev/chainloop/app/controlplane/internal/pagination"
24+
"github.com/secure-systems-lab/go-securesystemslib/dsse"
2525

2626
"github.com/go-kratos/kratos/v2/log"
2727
"github.com/google/uuid"
@@ -35,7 +35,11 @@ type WorkflowRun struct {
3535
AttestationID uuid.UUID
3636
RunURL, RunnerType string
3737
ContractVersionID uuid.UUID
38-
AttestationRef *AttestationRef
38+
Attestation *Attestation
39+
}
40+
41+
type Attestation struct {
42+
Envelope *dsse.Envelope
3943
}
4044

4145
type WorkflowRunWithContract struct {
@@ -58,7 +62,7 @@ type WorkflowRunRepo interface {
5862
FindByID(ctx context.Context, ID uuid.UUID) (*WorkflowRun, error)
5963
FindByIDInOrg(ctx context.Context, orgID, ID uuid.UUID) (*WorkflowRun, error)
6064
MarkAsFinished(ctx context.Context, ID uuid.UUID, status WorkflowRunStatus, reason string) error
61-
SaveAttestationRef(ctx context.Context, ID uuid.UUID, ref *AttestationRef) error
65+
SaveAttestation(ctx context.Context, ID uuid.UUID, att *dsse.Envelope) error
6266
List(ctx context.Context, orgID, workflowID uuid.UUID, p *pagination.Options) ([]*WorkflowRun, string, error)
6367
// List the runs that have not finished and are older than a given time
6468
ListNotFinishedOlderThan(ctx context.Context, olderThan time.Time) ([]*WorkflowRun, error)
@@ -198,18 +202,13 @@ func (uc *WorkflowRunUseCase) MarkAsFinished(ctx context.Context, id string, sta
198202
return uc.wfRunRepo.MarkAsFinished(ctx, runID, status, reason)
199203
}
200204

201-
// Store the attestation digest for the workflowrun
202-
func (uc *WorkflowRunUseCase) AssociateAttestation(ctx context.Context, id string, ref *AttestationRef) error {
203-
if ref == nil || ref.SecretRef == "" || ref.Sha256 == "" {
204-
return NewErrValidation(errors.New("attestation ref is nil or invalid"))
205-
}
206-
205+
func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, envelope *dsse.Envelope) error {
207206
runID, err := uuid.Parse(id)
208207
if err != nil {
209208
return NewErrInvalidUUID(err)
210209
}
211210

212-
return uc.wfRunRepo.SaveAttestationRef(ctx, runID, ref)
211+
return uc.wfRunRepo.SaveAttestation(ctx, runID, envelope)
213212
}
214213

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

app/controlplane/internal/biz/workflowrun_integration_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,23 @@ import (
2222
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
2323
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz/testhelpers"
2424
"github.com/google/uuid"
25+
"github.com/secure-systems-lab/go-securesystemslib/dsse"
2526
"github.com/stretchr/testify/assert"
2627
"github.com/stretchr/testify/suite"
2728
)
2829

29-
func (s *workflowRunIntegrationTestSuite) TestAssociateAttestation() {
30+
func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
3031
assert := assert.New(s.T())
3132
ctx := context.Background()
32-
validRef := &biz.AttestationRef{Sha256: "deadbeef", SecretRef: "secret-ref"}
33+
34+
validEnvelope := &dsse.Envelope{}
3335

3436
s.T().Run("non existing workflowRun", func(t *testing.T) {
35-
err := s.WorkflowRun.AssociateAttestation(ctx, uuid.NewString(), validRef)
37+
err := s.WorkflowRun.SaveAttestation(ctx, uuid.NewString(), validEnvelope)
3638
assert.Error(err)
3739
assert.True(biz.IsNotFound(err))
3840
})
3941

40-
s.T().Run("empty attestation ref", func(t *testing.T) {
41-
err := s.WorkflowRun.AssociateAttestation(ctx, uuid.NewString(), nil)
42-
assert.Error(err)
43-
assert.True(biz.IsErrValidation(err))
44-
})
45-
4642
s.T().Run("valid workflowrun", func(t *testing.T) {
4743
org, err := s.Organization.Create(ctx, "testing org")
4844
assert.NoError(err)
@@ -64,13 +60,13 @@ func (s *workflowRunIntegrationTestSuite) TestAssociateAttestation() {
6460
})
6561
assert.NoError(err)
6662

67-
err = s.WorkflowRun.AssociateAttestation(ctx, run.ID.String(), validRef)
63+
err = s.WorkflowRun.SaveAttestation(ctx, run.ID.String(), validEnvelope)
6864
assert.NoError(err)
6965

7066
// Retrieve attestation ref from storage and compare
7167
r, err := s.WorkflowRun.View(ctx, org.ID, run.ID.String())
7268
assert.NoError(err)
73-
assert.Equal(r.AttestationRef, validRef)
69+
assert.Equal(r.Attestation, &biz.Attestation{Envelope: validEnvelope})
7470
})
7571
}
7672

app/controlplane/internal/data/ent/migrate/schema.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.

0 commit comments

Comments
 (0)