Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notation): add support for notation in HelmChart and OCIRepository configuration #1075

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

JasonTheDeveloper
Copy link
Contributor

@JasonTheDeveloper JasonTheDeveloper commented Apr 17, 2023

This PR introduces notation as an additional option to cosign as a provider to verify the signature of source helmchart/ocirepository deployment.

This PR is related to issue #1072.

Testing

To test the changes to helmchart and ocirepository I have included a couple example configuration deployments under config/testdata/helmchart-from-oci and /workspaces/source-controller/config/testdata/ocirepository. These manifests are also deployed when running make e2e.

These manifests deploy a forked version of stefanprodan's podinfo, singed using notation and stored in my ghcr found here: https://github.com/JasonTheDeveloper?tab=packages&repo_name=podinfo.

Sample trust store policy and public key needed for verification can also be found here: https://github.com/JasonTheDeveloper/podinfo/tree/feat/notation/.notation.

Todo

  • Expand on unit tests
  • Update documentation
  • Add examples
  • Update Flux CLI subcommand flux create secret to generate notation configuration

@makkes makkes mentioned this pull request Nov 20, 2023
@makkes makkes self-assigned this Nov 23, 2023
@makkes
Copy link
Member

makkes commented Nov 23, 2023

Thanks @JasonTheDeveloper for creating this PR! I'd be happy to help getting this over the line. Are you planning to add the missing tests and documentation anytime soon? Happy to chat on the CNCF Slack as well.

@makkes makkes added area/security Security related issues and pull requests area/oci OCI related issues and pull requests area/api API related issues and pull requests labels Nov 23, 2023
@JasonTheDeveloper JasonTheDeveloper force-pushed the feat/notation branch 2 times, most recently from 7b8500a to 83d7208 Compare November 29, 2023 06:54
@JasonTheDeveloper
Copy link
Contributor Author

Thanks @JasonTheDeveloper for creating this PR! I'd be happy to help getting this over the line. Are you planning to add the missing tests and documentation anytime soon? Happy to chat on the CNCF Slack as well.

@makkes - I have added the missing tests. I'll be adding the documentation later today. Apologies for taking so long to getting around to finishing off this PR. Originally, I was holding off until notation 1.0.0 was released to the public just in case there were any major changes prior to going public. Looks like that happened a couple months ago 😅

internal/oci/notation.go Fixed Show fixed Hide fixed
@JasonTheDeveloper JasonTheDeveloper marked this pull request as ready for review December 7, 2023 07:23
Copy link
Member

@souleb souleb left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @JasonTheDeveloper. I left some comments

internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
Copy link
Member

@souleb souleb left a comment

Choose a reason for hiding this comment

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

can you put this in a separate PR?

.devcontainer.json Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/verifier.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
docs/spec/v1beta2/helmcharts.md Outdated Show resolved Hide resolved
docs/spec/v1beta2/ocirepositories.md Show resolved Hide resolved
@souleb
Copy link
Member

souleb commented Jan 29, 2024

can you also rebase your branch?

Makefile Outdated Show resolved Hide resolved
docs/spec/v1beta2/helmcharts.md Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
hack/ci/e2e.sh Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation_test.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/helm/getter/client_opts.go Show resolved Hide resolved
internal/oci/verifier.go Outdated Show resolved Hide resolved
internal/oci/notation.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller_test.go Outdated Show resolved Hide resolved
internal/oci/cosign/cosign_test.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Show resolved Hide resolved
internal/oci/notation/notation.go Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
@JasonTheDeveloper
Copy link
Contributor Author

We could check for skip and set trustStores/trustedIdentities to an empty string array + log so that notation doesn't complain.

Yes maybe this could be a function that take a trustPolicy and return a cleaned version that we can use for the verifier instantiation.

I've created a new func in 86e98fa and added unit tests in a4c93d9.

go.mod Outdated Show resolved Hide resolved
internal/oci/notation/notation_test.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Show resolved Hide resolved
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

I did some manual testing with OCIRepository, tried various things to break the implementation but so far everything looks good to me.
TestOCIRepository_reconcileSource_verifyOCISourceTrustPolicyNotation tests are great for confidence in the correctness.

I've left a few suggestions for minor improvements.

Will do final OCI HelmChart testing next.

internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
internal/oci/verifier.go Show resolved Hide resolved
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

I did manual testing for OCI HelmChart verification and it also worked very well.
I'm confident with the results.

Going through the code, I found some potential bugs and inconsistencies, nothing major. Left comment for those. Please have a look.
Once these and the previous comments are addressed, I will approve this PR.

Thanks for all the work on this.

internal/helm/repository/oci_chart_repository.go Outdated Show resolved Hide resolved
internal/helm/repository/oci_chart_repository.go Outdated Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/oci/notation/notation_test.go Outdated Show resolved Hide resolved
internal/oci/notation/notation_test.go Show resolved Hide resolved
internal/controller/helmchart_controller.go Outdated Show resolved Hide resolved
internal/controller/ocirepository_controller.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
internal/oci/notation/notation.go Outdated Show resolved Hide resolved
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

LGTM!
Thanks for spending so much time on getting this right.

Would be great if you could squash all the commits to a few relevant commits if possible.

@JasonTheDeveloper
Copy link
Contributor Author

@darkowlzz thank you so much for the approval! I tried to create separate squash commits to group things into "like" commits but it was taking too long so instead squashed everything into the one commit. Hope that's fine.

@souleb
Copy link
Member

souleb commented Mar 26, 2024

@JasonTheDeveloper do you mind rewriting the commit message. You may want to have a look at https://github.com/fluxcd/flux2/blob/main/CONTRIBUTING.md#format-of-the-commit-message

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Awesome contribution! Thanks @JasonTheDeveloper and @jagpreetstamber 🥇

Introduces a new verification provider `notation` to verify notation signed artifacts. Currently only cosign is supported and that is a problem if the end user utilises notation.

---------

Signed-off-by: Jason <[email protected]>
Signed-off-by: JasonTheDeveloper <[email protected]>
Signed-off-by: Jagpreet Singh Tamber <[email protected]>
Co-authored-by: souleb <[email protected]>
Co-authored-by: Jagpreet Singh Tamber <[email protected]>
Co-authored-by: Sunny <[email protected]>
@JasonTheDeveloper
Copy link
Contributor Author

@souleb something like this? Add verification support for notation signed artifacts

Copy link
Member

@souleb souleb left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks for your outstanding contribution and your willingness to accommodate and work through all the changes requested.

@souleb souleb merged commit 55a2cdb into fluxcd:main Mar 26, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api API related issues and pull requests area/oci OCI related issues and pull requests area/security Security related issues and pull requests
Projects
Status: Since Last Dev Meeting
Development

Successfully merging this pull request may close these issues.

8 participants