Skip to content

Commit

Permalink
feat(attestation): add tag to container image attestation (chainloop-…
Browse files Browse the repository at this point in the history
…dev#747)

Signed-off-by: Miguel Martinez Trivino <[email protected]>
  • Loading branch information
migmartri authored May 6, 2024
1 parent c736f90 commit 855534d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 78 deletions.

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

154 changes: 82 additions & 72 deletions internal/attestation/crafter/api/attestation/v1/crafting_state.pb.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ message Attestation {
string name = 2 [(buf.validate.field).string.min_len = 1];
string digest = 3 [(buf.validate.field).string.min_len = 1];
bool is_subject = 4;
// provided tag
string tag = 5;
}

message Artifact {
Expand Down
3 changes: 2 additions & 1 deletion internal/attestation/crafter/materials/oci_image.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 @@ -65,6 +65,7 @@ func (i *OCIImageCrafter) Craft(_ context.Context, imageRef string) (*api.Attest
M: &api.Attestation_Material_ContainerImage_{
ContainerImage: &api.Attestation_Material_ContainerImage{
Id: i.input.Name, Name: repoName, Digest: remoteRef.DigestStr(), IsSubject: i.input.Output,
Tag: ref.Identifier(),
},
},
}, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/attestation/renderer/chainloop/chainloop.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 @@ -219,6 +219,7 @@ var (
AnnotationMaterialName = prefixed("material.name")
AnnotationMaterialCAS = prefixed("material.cas")
annotationMaterialInlineCAS = prefixed("material.cas.inline")
annotationContainerTag = prefixed("material.image.tag")
)

func prefixed(name string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "chainloop.workflow.test-new-types",
"digest": {
"sha256": "524b370dd444326d8150f5a8176bd4d57bb2052a1b77471d1fcb9fcc0983c958"
"sha256": "f468a33a5a4ae153c1c50949b771b6dd9034f663bf00a5fdfbef73f03886a8e1"
}
},
{
Expand All @@ -31,6 +31,7 @@
"sha256": "fbd9335f55d83d8aaf9ab1a539b0f2a87b444e8c54f34c9a1ca9d7df15605db4"
},
"annotations": {
"chainloop.material.image.tag": "devel",
"chainloop.material.name": "image",
"chainloop.material.type": "CONTAINER_IMAGE"
}
Expand All @@ -45,6 +46,7 @@
"materials": [
{
"annotations": {
"chainloop.material.image.tag": "devel",
"chainloop.material.name": "image",
"chainloop.material.type": "CONTAINER_IMAGE"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"id": "image",
"name": "index.docker.io/bitnami/nginx",
"digest": "sha256:fbd9335f55d83d8aaf9ab1a539b0f2a87b444e8c54f34c9a1ca9d7df15605db4",
"isSubject": true
"isSubject": true,
"tag": "devel"
},
"addedAt": "2023-10-20T12:57:52.459112368Z",
"materialType": "CONTAINER_IMAGE"
Expand Down
9 changes: 8 additions & 1 deletion internal/attestation/renderer/chainloop/v02.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 @@ -213,6 +213,13 @@ func outputMaterials(att *v1.Attestation, onlyOutput bool) ([]*intoto.ResourceDe
AnnotationMaterialName: mdefName,
}

// Set the special annotations for container images
if artifactType == schemaapi.CraftingSchema_Material_CONTAINER_IMAGE {
if tag := mdef.GetContainerImage().GetTag(); tag != "" {
annotationsM[annotationContainerTag] = tag
}
}

// Custom annotations, it does not override the built-in ones
for k, v := range mdef.Annotations {
_, ok := annotationsM[k]
Expand Down

0 comments on commit 855534d

Please sign in to comment.