Skip to content

feat(backend): ATTESTATION material type - #727

Merged
jiparis merged 9 commits into
chainloop-dev:mainfrom
jiparis:feat-719
Apr 30, 2024
Merged

feat(backend): ATTESTATION material type#727
jiparis merged 9 commits into
chainloop-dev:mainfrom
jiparis:feat-719

Conversation

@jiparis

@jiparis jiparis commented Apr 29, 2024

Copy link
Copy Markdown
Member

This PR adds a new ATTESTATION material type to allow cross-linking different workflow runs using existing attestations.

This is what the logic do:

  • check that the attestation is valid (valid DSSE envelope, valid in-toto attestation and chainloop predicate).
  • re-marshall the envelope to mitigate possible digest unmatches with existing previously uploaded attestations
  • Some refactor to reuse common code in CLI and backend.

References #719

jiparis added 2 commits April 29, 2024 21:06
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis
jiparis requested review from javirln and migmartri April 29, 2024 19:47
@jiparis
jiparis marked this pull request as draft April 29, 2024 19:47
@jiparis

jiparis commented Apr 29, 2024

Copy link
Copy Markdown
Member Author

Marking as draft, as I still want to add some tests for the digests.

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Comment thread app/controlplane/internal/biz/attestation.go Outdated
Comment thread internal/attestation/crafter/materials/attestation.go Outdated
Comment thread internal/attestation/crafter/materials/attestation.go Outdated
Comment thread internal/attestation/crafter/materials/materials.go Outdated

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good!

Just added some comments so far with some of my concerns, will do a more complete review soon.

Thank you!!

// see tests for examples
func extractReferrers(att *dsse.Envelope) ([]*Referrer, error) {
_, h, err := jsonEnvelopeWithDigest(att)
_, h, err := materials.JsonEnvelopeWithDigest(att)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could merge this but right after this, we could do a follow up to handle these kind of attestations to make sure they are not injected in the graph.

That said, it's not trivial and not worth being added in this patch.

jiparis added 3 commits April 30, 2024 00:32
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis
jiparis marked this pull request as ready for review April 29, 2024 23:41
@jiparis
jiparis requested a review from migmartri April 29, 2024 23:49

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about changing the upload calls but there is nothing wrong with it.

I left some comments to get your take, if you want, feel free to merge. Thanks!

if tc.wantErr == "" {
uploader.On("UploadFile", context.TODO(), tc.filePath).
uploader.On("Upload", context.TODO(), mock.Anything,
"sha256:c27087147fa040909e0ef1b522386608af545b0a163c30c9f11c3d753676fa44", filepath.Base(tc.filePath)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why of this specific digest? which one does it correspond?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: I understand now, this is because now we are using upload not upload file

For this, since you do not care about the case when the upload fails, you can just add mock.anything in the digest arg.

l.Debug().Str("backend", backend.Name).Msg("uploading")

_, err = backend.Uploader.UploadFile(ctx, artifactPath)
_, err := backend.Uploader.Upload(ctx, buf, hash, filename)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% about these changes. Especially the fact that the content and the ahs are now separate. I am wondering if an alternative less optimal, but that will require less changes would have been to store the content in a temporary file. Not sure, I'd love to get your take

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking into account that the grunt of these changes are because of we want to provide some modified versions of a provided file, an alternative, would have been to during the attestation material craft, take the resulted marshalled data and store it in a temporary file and use that one instead.

Then, the rest of the code wouldn't have changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, cleaner for sure. Let me refactor a little bit the change.

@migmartri

Copy link
Copy Markdown
Member

btw, have you tested this and see what's the result in the index?

For future PRs, it would be great if you could add some snippets, demos of the functionality when possible.

Thanks!

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@migmartri

migmartri commented Apr 30, 2024

Copy link
Copy Markdown
Member

I am having some issues while running it locally

cat /tmp/att.json                                                        
{
   "payloadType": "application/vnd.in-toto+json",
   "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJzdWJqZWN0IjpbeyJuYW1lIjoiY2hhaW5sb29wLndvcmtmbG93LnRlc3QyIiwiZGlnZXN0Ijp7InNoYTI1NiI6IjE1MTAwMzA1OWJmOTRiMTViZTMzNTBiZTc5MGM5MGEyYzE5MzBjOWU0Y2ZkYzQwOTEyYmMxY2UzM2Y3YzFmZGQifX0seyJuYW1lIjoiZ2l0LmhlYWQiLCJkaWdlc3QiOnsic2hhMSI6IjM1MTBkZDE1YzJiYTRmMWFkMDk0YjVlNTI3ZjNjYTAxNjVhNjk2MDAifSwiYW5ub3RhdGlvbnMiOnsiYXV0aG9yLmVtYWlsIjoibWlndWVsQGNoYWlubG9vcC5kZXYiLCJhdXRob3IubmFtZSI6Ik1pZ3VlbCBNYXJ0aW5leiBUcml2aW5vIiwiZGF0ZSI6IjIwMjQtMDQtMzBUMDY6Mjg6NDZaIiwibWVzc2FnZSI6ImZlYXQoY2xpKTogYWRkIGpzb24gb3V0cHV0IHRvIGF0dGVzdGF0aW9uIHB1c2hcblxuU2lnbmVkLW9mZi1ieTogTWlndWVsIE1hcnRpbmV6IFRyaXZpbm8gPG1pZ3VlbEBjaGFpbmxvb3AuZGV2PlxuIiwicmVtb3RlcyI6W3sibmFtZSI6Im9yaWdpbiIsInVybCI6ImdpdEBnaXRodWIuY29tOm1pZ21hcnRyaS9jaGFpbmxvb3AuZ2l0In0seyJuYW1lIjoidXBzdHJlYW0iLCJ1cmwiOiJnaXRAZ2l0aHViLmNvb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
   ]
}

go run main.go --insecure att add --name deployment --value /tmp/att.json
WRN API contacted in insecure mode
ERR adding material: crafting material: uploading material: decoding digest: cannot parse hash: "att.json"

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my latest comment.

jiparis added 2 commits April 30, 2024 10:21
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis

jiparis commented Apr 30, 2024

Copy link
Copy Markdown
Member Author

Thanks, @migmartri. Fixed!

@jiparis
jiparis merged commit 8d85e75 into chainloop-dev:main Apr 30, 2024
@jiparis
jiparis deleted the feat-719 branch April 30, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants