Skip to content
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
2 changes: 1 addition & 1 deletion app/controlplane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The control plane has 4 main dependencies
- 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).
- 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.

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

## Runbook

Expand Down
3 changes: 0 additions & 3 deletions app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 0 additions & 92 deletions app/controlplane/internal/biz/attestation.go

This file was deleted.

82 changes: 0 additions & 82 deletions app/controlplane/internal/biz/attestation_test.go

This file was deleted.

1 change: 0 additions & 1 deletion app/controlplane/internal/biz/biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var ProviderSet = wire.NewSet(
NewRootAccountUseCase,
NewWorkflowRunUseCase,
NewOrganizationUseCase,
NewAttestationUseCase,
NewWorkflowContractUseCase,
NewCASCredentialsUseCase,
NewOCIRepositoryUseCase,
Expand Down
27 changes: 7 additions & 20 deletions app/controlplane/internal/biz/mocks/WorkflowRunRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions app/controlplane/internal/biz/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package biz

import (
"context"
"errors"
"io"
"time"

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

"github.com/go-kratos/kratos/v2/log"
"github.com/google/uuid"
Expand All @@ -35,7 +35,11 @@ type WorkflowRun struct {
AttestationID uuid.UUID
RunURL, RunnerType string
ContractVersionID uuid.UUID
AttestationRef *AttestationRef
Attestation *Attestation
}

type Attestation struct {
Envelope *dsse.Envelope
}

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

// Store the attestation digest for the workflowrun
func (uc *WorkflowRunUseCase) AssociateAttestation(ctx context.Context, id string, ref *AttestationRef) error {
if ref == nil || ref.SecretRef == "" || ref.Sha256 == "" {
return NewErrValidation(errors.New("attestation ref is nil or invalid"))
}

func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, envelope *dsse.Envelope) error {
runID, err := uuid.Parse(id)
if err != nil {
return NewErrInvalidUUID(err)
}

return uc.wfRunRepo.SaveAttestationRef(ctx, runID, ref)
return uc.wfRunRepo.SaveAttestation(ctx, runID, envelope)
}

// List the workflowruns associated with an org and optionally filtered by a workflow
Expand Down
18 changes: 7 additions & 11 deletions app/controlplane/internal/biz/workflowrun_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@ import (
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz/testhelpers"
"github.com/google/uuid"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

func (s *workflowRunIntegrationTestSuite) TestAssociateAttestation() {
func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
assert := assert.New(s.T())
ctx := context.Background()
validRef := &biz.AttestationRef{Sha256: "deadbeef", SecretRef: "secret-ref"}

validEnvelope := &dsse.Envelope{}

s.T().Run("non existing workflowRun", func(t *testing.T) {
err := s.WorkflowRun.AssociateAttestation(ctx, uuid.NewString(), validRef)
err := s.WorkflowRun.SaveAttestation(ctx, uuid.NewString(), validEnvelope)
assert.Error(err)
assert.True(biz.IsNotFound(err))
})

s.T().Run("empty attestation ref", func(t *testing.T) {
err := s.WorkflowRun.AssociateAttestation(ctx, uuid.NewString(), nil)
assert.Error(err)
assert.True(biz.IsErrValidation(err))
})

s.T().Run("valid workflowrun", func(t *testing.T) {
org, err := s.Organization.Create(ctx, "testing org")
assert.NoError(err)
Expand All @@ -64,13 +60,13 @@ func (s *workflowRunIntegrationTestSuite) TestAssociateAttestation() {
})
assert.NoError(err)

err = s.WorkflowRun.AssociateAttestation(ctx, run.ID.String(), validRef)
err = s.WorkflowRun.SaveAttestation(ctx, run.ID.String(), validEnvelope)
assert.NoError(err)

// Retrieve attestation ref from storage and compare
r, err := s.WorkflowRun.View(ctx, org.ID, run.ID.String())
assert.NoError(err)
assert.Equal(r.AttestationRef, validRef)
assert.Equal(r.Attestation, &biz.Attestation{Envelope: validEnvelope})
})
}

Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/internal/data/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading