Skip to content

Commit 38e140d

Browse files
authored
feat(verification): Store attestation bundles in Chainloop database (#1777)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 4fc5d25 commit 38e140d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3740
-322
lines changed

app/cli/internal/action/attestation_push.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626
"github.com/chainloop-dev/chainloop/pkg/attestation/renderer"
2727
"github.com/chainloop-dev/chainloop/pkg/attestation/signer"
2828
"github.com/secure-systems-lab/go-securesystemslib/dsse"
29+
protobundle "github.com/sigstore/protobuf-specs/gen/pb-go/bundle/v1"
2930
"google.golang.org/grpc"
31+
"google.golang.org/protobuf/encoding/protojson"
3032
"google.golang.org/protobuf/types/known/timestamppb"
3133
)
3234

@@ -174,7 +176,7 @@ func (action *AttestationPush) Run(ctx context.Context, attestationID string, ru
174176
}
175177

176178
// render final attestation with all the evaluated policies inside
177-
envelope, err := renderer.Render(ctx)
179+
envelope, bundle, err := renderer.Render(ctx)
178180
if err != nil {
179181
return nil, err
180182
}
@@ -194,7 +196,7 @@ func (action *AttestationPush) Run(ctx context.Context, attestationID string, ru
194196

195197
workflow := crafter.CraftingState.Attestation.GetWorkflow()
196198

197-
attestationResult.Digest, err = pushToControlPlane(ctx, action.ActionsOpts.CPConnection, envelope, workflow.GetWorkflowRunId(), workflow.GetVersion().GetMarkAsReleased())
199+
attestationResult.Digest, err = pushToControlPlane(ctx, action.ActionsOpts.CPConnection, envelope, bundle, workflow.GetWorkflowRunId(), workflow.GetVersion().GetMarkAsReleased())
198200
if err != nil {
199201
return nil, fmt.Errorf("pushing to control plane: %w", err)
200202
}
@@ -209,21 +211,29 @@ func (action *AttestationPush) Run(ctx context.Context, attestationID string, ru
209211
return attestationResult, nil
210212
}
211213

212-
func pushToControlPlane(ctx context.Context, conn *grpc.ClientConn, envelope *dsse.Envelope, workflowRunID string, markVersionAsReleased bool) (string, error) {
213-
encodedAttestation, err := encodeEnvelope(envelope)
214+
func pushToControlPlane(ctx context.Context, conn *grpc.ClientConn, envelope *dsse.Envelope, bundle *protobundle.Bundle, workflowRunID string, markVersionAsReleased bool) (string, error) {
215+
encodedBundle, err := encodeBundle(bundle)
214216
if err != nil {
215217
return "", fmt.Errorf("encoding attestation: %w", err)
216218
}
217219

218220
client := pb.NewAttestationServiceClient(conn)
221+
222+
// if endpoint doesn't accept the bundle, we still send the plain attestation for backwards compatibility
223+
encodedAttestation, err := encodeEnvelope(envelope)
224+
if err != nil {
225+
return "", fmt.Errorf("encoding attestation: %w", err)
226+
}
227+
228+
// Store bundle next versions will perform this in a single call)
219229
resp, err := client.Store(ctx, &pb.AttestationServiceStoreRequest{
220230
Attestation: encodedAttestation,
231+
Bundle: encodedBundle,
221232
WorkflowRunId: workflowRunID,
222233
MarkVersionAsReleased: &markVersionAsReleased,
223234
})
224-
225235
if err != nil {
226-
return "", fmt.Errorf("contacting the control plane: %w", err)
236+
return "", fmt.Errorf("storing attestation: %w", err)
227237
}
228238

229239
return resp.Result.Digest, nil
@@ -233,6 +243,10 @@ func encodeEnvelope(e *dsse.Envelope) ([]byte, error) {
233243
return json.Marshal(e)
234244
}
235245

246+
func encodeBundle(b *protobundle.Bundle) ([]byte, error) {
247+
return protojson.Marshal(b)
248+
}
249+
236250
func decodeEnvelope(rawEnvelope []byte) (*dsse.Envelope, error) {
237251
envelope := &dsse.Envelope{}
238252
if err := json.Unmarshal(rawEnvelope, envelope); err != nil {

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

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

app/controlplane/api/controlplane/v1/workflow_run.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ message AttestationServiceInitResponse {
136136

137137
message AttestationServiceStoreRequest {
138138
// encoded DSEE envelope
139-
bytes attestation = 1 [(buf.validate.field).bytes.min_len = 1];
139+
bytes attestation = 1 [deprecated=true];
140+
// encoded Sigstore attestation bundle
141+
// TODO. Add min_len constraint
142+
bytes bundle = 4;
140143
string workflow_run_id = 2 [(buf.validate.field).string = {min_len: 1}];
141144
// mark the associated version as released
142145
optional bool mark_version_as_released = 3;

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

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleRequest.jsonschema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleRequest.schema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleResponse.Result.jsonschema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleResponse.Result.schema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleResponse.jsonschema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceStoreBundleResponse.schema.json

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

0 commit comments

Comments
 (0)