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
1 change: 1 addition & 0 deletions app/cli/internal/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int) (s

workflowRun := runResp.GetResult().GetWorkflowRun()
workflowMeta.WorkflowRunId = workflowRun.GetId()
workflowMeta.Organization = runResp.GetResult().GetOrganization()
action.Logger.Debug().Str("workflow-run-id", workflowRun.GetId()).Msg("attestation initialized in the control plane")
attestationID = workflowRun.GetId()
}
Expand Down
321 changes: 166 additions & 155 deletions app/controlplane/api/controlplane/v1/workflow_run.pb.go

Large diffs are not rendered by default.

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

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/workflow_run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ message AttestationServiceInitResponse {

message Result {
WorkflowRunItem workflow_run = 2;
// organization name
string organization = 3;
}
}

Expand Down

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

21 changes: 19 additions & 2 deletions app/controlplane/api/gen/frontend/controlplane/v1/workflow_run.ts

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

1 change: 1 addition & 0 deletions app/controlplane/cmd/wire_gen.go

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

21 changes: 7 additions & 14 deletions app/controlplane/internal/biz/referrer.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,7 @@
package biz

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -29,7 +27,6 @@ import (
"github.com/chainloop-dev/chainloop/internal/attestation/renderer/chainloop"
"github.com/chainloop-dev/chainloop/internal/servicelogger"
"github.com/go-kratos/kratos/v2/log"
cr_v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/uuid"
v1 "github.com/in-toto/attestation/go/v1"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
Expand Down Expand Up @@ -250,18 +247,11 @@ func (r *Referrer) MapID() string {
// 4 - creating link between the attestation and the materials/subjects as needed
// see tests for examples
func extractReferrers(att *dsse.Envelope) ([]*Referrer, error) {
// Calculate the attestation hash
jsonAtt, err := json.Marshal(att)
_, h, err := jsonEnvelopeWithDigest(att)
if err != nil {
return nil, fmt.Errorf("marshaling attestation: %w", err)
}

// Calculate the attestation hash
h, _, err := cr_v1.SHA256(bytes.NewBuffer(jsonAtt))
if err != nil {
return nil, fmt.Errorf("calculating attestation hash: %w", err)
}

referrersMap := make(map[string]*Referrer)
// 1 - Attestation referrer
// Add the attestation itself as a referrer to the map without references yet
Expand All @@ -284,8 +274,11 @@ func extractReferrers(att *dsse.Envelope) ([]*Referrer, error) {
// We add both annotations and workflow metadata
attestationReferrer.Annotations = predicate.GetAnnotations()
attestationReferrer.Metadata = map[string]string{
// workflow name
"name": predicate.GetMetadata().Name,
// workflow name, team and project
"name": predicate.GetMetadata().Name,
"team": predicate.GetMetadata().Team,
"project": predicate.GetMetadata().Project,
"organization": predicate.GetMetadata().Organization,
}

// Create new referrers for each material
Expand Down
17 changes: 11 additions & 6 deletions app/controlplane/internal/biz/referrer_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@ func (s *referrerIntegrationTestSuite) TestGetFromRootInPublicSharedIndex() {
require.NoError(s.T(), json.Unmarshal(attJSON, &envelope))

wantReferrerAtt := &biz.Referrer{
Digest: "sha256:ad704d286bcad6e155e71c33d48247931231338396acbcd9769087530085b2a2",
Digest: "sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7",
Kind: "ATTESTATION",
Downloadable: true,
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
require.NoError(s.T(), json.Unmarshal(attJSON, &envelope))

wantReferrerAtt := &biz.Referrer{
Digest: "sha256:ad704d286bcad6e155e71c33d48247931231338396acbcd9769087530085b2a2",
Digest: "sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7",
Kind: "ATTESTATION",
Downloadable: true,
}
Expand Down Expand Up @@ -186,7 +186,12 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
s.Equal(wantReferrerAtt.Downloadable, got.Downloadable)
s.Equal(wantReferrerAtt.Kind, got.Kind)
// It has metadata
s.Equal(map[string]string{"name": "test-new-types"}, got.Metadata)
s.Equal(map[string]string{
"name": "test-new-types",
"project": "test",
"team": "my-team",
"organization": "my-org",
}, got.Metadata)
// it has all the references
require.Len(t, got.References, 6)

Expand Down Expand Up @@ -316,9 +321,9 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
// it should be referenced by two attestations since it's subject of both
require.Len(t, got.References, 2)
s.Equal("ATTESTATION", got.References[0].Kind)
s.Equal(wantReferrerAtt.Digest, got.References[0].Digest)
s.Equal("sha256:c90ccaab0b2cfda9980836aef407f62d747680ea9793ddc6ad2e2d7ab615933d", got.References[0].Digest)
s.Equal("ATTESTATION", got.References[1].Kind)
s.Equal("sha256:c90ccaab0b2cfda9980836aef407f62d747680ea9793ddc6ad2e2d7ab615933d", got.References[1].Digest)
s.Equal("sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7", got.References[1].Digest)
})

s.T().Run("if all associated workflows are private, the referrer is private", func(t *testing.T) {
Expand Down
28 changes: 20 additions & 8 deletions app/controlplane/internal/biz/referrer_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,7 +94,10 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "only-sbom",
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
},
Annotations: map[string]string{
"branch": "stable",
Expand Down Expand Up @@ -137,7 +140,10 @@ func (s *referrerTestSuite) TestExtractReferrers() {
},
},
Metadata: map[string]string{
"name": "test",
"name": "test",
"organization": "",
"team": "",
"project": "bar",
},
Annotations: map[string]string{
"version": "oss",
Expand Down Expand Up @@ -165,7 +171,10 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "only-sbom",
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
},
Annotations: map[string]string{
"branch": "stable",
Expand Down Expand Up @@ -212,11 +221,14 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Downloadable: true,
},
{
Digest: "sha256:ad704d286bcad6e155e71c33d48247931231338396acbcd9769087530085b2a2",
Digest: "sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7",
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "test-new-types",
"name": "test-new-types",
"organization": "my-org",
"team": "my-team",
"project": "test",
},
References: []*Referrer{
{
Expand Down Expand Up @@ -251,7 +263,7 @@ func (s *referrerTestSuite) TestExtractReferrers() {
// the container image is a subject in the attestation
References: []*Referrer{
{
Digest: "sha256:ad704d286bcad6e155e71c33d48247931231338396acbcd9769087530085b2a2",
Digest: "sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7",
Kind: "ATTESTATION",
},
},
Expand All @@ -262,7 +274,7 @@ func (s *referrerTestSuite) TestExtractReferrers() {
// the git commit a subject in the attestation
References: []*Referrer{
{
Digest: "sha256:ad704d286bcad6e155e71c33d48247931231338396acbcd9769087530085b2a2",
Digest: "sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7",
Kind: "ATTESTATION",
},
},
Expand Down
Loading