Skip to content

Use upstream golang/crypto functionality for ACME External Account Binding #3850

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

Closed
wants to merge 6 commits into from

Conversation

irbekrm
Copy link
Contributor

@irbekrm irbekrm commented Apr 6, 2021

[Update] I will split this PR into multiple ones to make it easier to code review.

See #3220 for full context.

Up till now we used a fork of golang/crypto with added support for ACME External Account Binding and fetching of ACME preferred certificate chains from @meyskens GitHub account.

This PR:

  • uses upstream golang/crypto functionality for ACME External Account Binding instead of our own
  • uses golang/crypto fork from cert-manager account instead of @meyskens account

Notes:

  • I have forked the latest golang/crypto to cert-manager org and cherry-picked @meyskens commit that implements fetching of alternative certificate chains on top of that. We can use this fork till the same functionality gets implemented upstream

  • The difference between the upstream implementation of ACME EAB and our own that we have used up till now is that in upstream the MAC algorithm value is hardcoded to HS256. This means that the issuer.spec.acme.externalAccountBinding.keyAlgorithm that has been 'required' so far becomes useless. This PR makes the field optional and the validating webhook now returns a warning if it is set. It is now possible (we test for that) to 1) deploy with issuer.spec.acme.externalAccountBinding.keyAlgorithm field set 2) deploy without the field 3) deploy with, then remove.

  • I have removed a bunch of legacy functions for issuer generation from test/e2e/util/util.go as it partially duplicated the functionality in test/test/unit/gen/issuer.go and added some more specific issuer generation functions to test/unit/gen/issuer.go.
    Can we assume that no-one has been importing the legacy functions from test/e2e/util/util.go? I did not find external imports on pkg.go.dev

  • In order for the webhook to be able to return a warning I had to add it to the signature of most validating functions. I assume that this is a functionality that might potentially become useful? (i.e perhaps the warning about empty hostname for self-signed issuer that @SgtCoDFish worked on could have been implemented as a warning)

  • Would it make sense to eventually remove issuer.spec.acme.externalAccountBinding.keyAlgorithm? (In which case that should probabaly be added to the warning message).

This is what the warning looks like:
Screenshot from 2021-04-07 12-38-25

fixes #3822

Deprecate Issuer.spec.acme.externalAccountBinding.keyAlgorithm field. EAB MAC algorithm is now hardcoded to HS256.

@jetstack-bot jetstack-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 6, 2021
@jetstack-bot jetstack-bot requested a review from meyskens April 6, 2021 08:00
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: irbekrm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jetstack-bot jetstack-bot added area/acme Indicates a PR directly modifies the ACME Issuer code area/api Indicates a PR directly modifies the 'pkg/apis' directory approved Indicates a PR has been approved by an approver from all required OWNERS files. area/deploy Indicates a PR modifies deployment configuration area/testing Issues relating to testing labels Apr 6, 2021
@irbekrm irbekrm changed the title WIP Use upstream golang/crypto for ACME External Account Binding [WIP] Use upstream golang/crypto for ACME External Account Binding Apr 6, 2021
@jetstack-bot jetstack-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 6, 2021
@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2021
irbekrm added 5 commits April 7, 2021 14:51
It is hardcoded to HS256 in golang.org/x/crypto

Also, we now use a fork of golang.org/x/crypto
in cert-manager org.

Signed-off-by: irbekrm <irbekrm@gmail.com>
Use test/util/gen instead

Signed-off-by: irbekrm <irbekrm@gmail.com>
Signed-off-by: irbekrm <irbekrm@gmail.com>
Signed-off-by: irbekrm <irbekrm@gmail.com>
…ield is set

Signed-off-by: irbekrm <irbekrm@gmail.com>
@irbekrm irbekrm force-pushed the upstream_acme_eab branch from a0acaf9 to 16f5141 Compare April 7, 2021 14:14
@jetstack-bot jetstack-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2021
@irbekrm irbekrm changed the title [WIP] Use upstream golang/crypto for ACME External Account Binding Use upstream golang/crypto for ACME External Account Binding Apr 7, 2021
@jetstack-bot jetstack-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 7, 2021
@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 7, 2021

/milestone v1.4

@jetstack-bot jetstack-bot added this to the v1.4 milestone Apr 7, 2021
Signed-off-by: irbekrm <irbekrm@gmail.com>
@irbekrm irbekrm requested review from JoshVanL and wallrj April 7, 2021 15:53
@irbekrm irbekrm changed the title Use upstream golang/crypto for ACME External Account Binding Use upstream golang/crypto functionality for ACME External Account Binding Apr 8, 2021
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

I've not run this locally yet: I think this all looks good, but honestly there's so much going on I could easily have missed several things. You could make the case for splitting this into several different PRs:

  1. Use cert-manager/crypto instead of meyskens/crypto
  2. Add support for warnings being returned during validation
  3. Deprecate the keyAlgorithm field and return a warning when it's set
  4. Remove legacy functions for issuer generation from test/e2e/util/util.go

I think 4 stands out to me as being well worth splitting out into a separate PR. I think my preference would be to make 1 its own standalone PR too since it stands out to me as being such an important thing (because the fork makes me really, really nervous).

type ValidateFunc func(req *admissionv1.AdmissionRequest, obj runtime.Object) field.ErrorList
type ValidateUpdateFunc func(req *admissionv1.AdmissionRequest, oldObj, obj runtime.Object) field.ErrorList
type ValidateFunc func(req *admissionv1.AdmissionRequest, obj runtime.Object) (field.ErrorList, []string)
type ValidateUpdateFunc func(req *admissionv1.AdmissionRequest, oldObj, obj runtime.Object) (field.ErrorList, []string)
Copy link
Member

Choose a reason for hiding this comment

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

it might be helpful to document in a comment on these types what the new []string return value is for, so that it's obvious at a glance. Likewise in the definitions of func (r *Registry) Validate and func (r *Registry) ValidateUpdate below and other instances of those types of function.

Copy link
Member

Choose a reason for hiding this comment

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

Further to that, we have field.ErrorList which has the notion of a path, helping to point people at where exactly an error is.

It seems a shame to not have that kind of rich information for warnings. Maybe even something like this could work:

type WarningList field.ErrorList

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks- I agree that splitting makes sense!
Would it makes sense if it was:

  1. Removes legacy functions (so that it's more straightforward to write e2e tests for 2)
  2. Use cert-manager/crypto instead of meyskens/crypto + deprecates the keyAlgorithm- this would allow us to fork upstream golang/crypto & cherry-pick alternative cert chains (current verson from meyskens has an older version of golang/crypto with our custom functionality for ACME EAB) and once we use upstream for ACME EAB we have to get rid of keyAlgorithm at least partially.
  3. Implements warnings

Copy link
Member

Choose a reason for hiding this comment

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

That sounds spot on 👍

@@ -68,8 +68,7 @@ var _ = framework.CertManagerDescribe("ACME Certificate (HTTP01)", func() {
validations := f.Helper().ValidationSetForUnsupportedFeatureSet(unsupportedFeatures)

BeforeEach(func() {
acmeIssuer := util.NewCertManagerACMEIssuer(issuerName, f.Config.Addons.ACMEServer.URL, testingACMEEmail, testingACMEPrivateKey)
Copy link
Member

Choose a reason for hiding this comment

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

am I correct these changes are related to:

I have removed a bunch of legacy functions for issuer generation ...

if so, I can see why that's a valuable change but this is already a pretty huge PR and these changes to use gen here feel quite distant from the goal of this specific PR; they should maybe be in their own PR, to make everything easier to review?

or have I missed how these changes are linked to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it here because I was adding some e2e tests for issuers and without removing the legacy I would have to either use & update the legacy functions for issuer generation or have two different ways of doing this in one file.
I will create a separate PR with these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#3873 PRs in just the removal of legacy functions.

@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 9, 2021

/retest

@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 9, 2021

/test pull-cert-manager-e2e-v1-20

@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 9, 2021

/test pull-cert-manager-bazel

@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 9, 2021

/test pull-cert-manager-bazel

@irbekrm
Copy link
Contributor Author

irbekrm commented Apr 9, 2021

Closing this as I am splitting it into 3 separate PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme Indicates a PR directly modifies the ACME Issuer code area/api Indicates a PR directly modifies the 'pkg/apis' directory area/deploy Indicates a PR modifies deployment configuration area/testing Issues relating to testing dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use go/x/crypto functionality for ACME External Account Binding
3 participants