Skip to content

Experimental Gateway API support for ACME HTTP-01 Solving - #4276

Merged
jetstack-bot merged 15 commits into
cert-manager:masterfrom
jakexks:gateway-http01
Aug 3, 2021
Merged

jetstack-bot merged 15 commits into
cert-manager:masterfrom
jakexks:gateway-http01

Conversation

@jakexks

@jakexks jakexks commented Jul 29, 2021 •

Copy link
Copy Markdown
Member

What this PR does / why we need it:
The cert-manager ACME HTTP01 solver currently uses Ingress to solve incoming challenges. Although Ingress is widely used, many people prefer to use different API Gateways or service meshes to route traffic to their cluster; users have been asking for support of Istio VirtualService and Gloo VirtualService.

The sig-network Gateway API aims to provide a common set of CRDs that can be implemented by various controllers. By supporting these common CRDs in cert-manager, users should now be able to solve ACME HTTP01 challenges with their preferred solution.

This PR adds a new field to the ACMESolver section of Issuers or ClusterIssuers which will tell cert-manager to create Gateway API HTTPRoutes with user-supplied labels. Implementations of the gateway API can look at these HTTPRoutes to solve challenges:

Example Gateway configuration using HAProxy: (click to expand)
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: GatewayClass
metadata:
  name: haproxy-acmesolver
spec:
  controller: haproxy-ingress.github.io/controller
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: Gateway
metadata:
  name: acmesolver
  namespace: haproxy-ingress
spec:
  gatewayClassName: haproxy-acmesolver
  listeners:
  - protocol: HTTP
    port: 80
    routes:
      kind: HTTPRoute
      selector:
        matchLabels:
          usemeto: solve-challenges
      namespaces:
        from: All

Example Issuer configuration:

apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: test-gateway-issuer
  namespace: default
spec:
  acme:
    email: [email protected]
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      name: example-secret-key
    solvers:
    - http01:
        gatewayHTTPRoute:
          labels:
            usemeto: solve-challenges
        

Note that the Gateway API is in its alpha stage. This means the stability of the gateway solver field is not guaranteed.

Which issue this PR fixes :
Fixes #4118

Special notes for your reviewer:

Release note:

cert-manager now supports the sig-network Gateway API to solve HTTP01 challenges.

/kind feature

@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. area/acme Indicates a PR directly modifies the ACME Issuer code area/acme/http01 Indicates a PR modifies ACME HTTP01 provider 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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 29, 2021
@munnerz

munnerz commented Jul 29, 2021

Copy link
Copy Markdown
Member

Should this be implemented in a similar manner to how we expect Istio's VirtualService solving to be implemented? (i.e. out of tree) - given that the Gateway API is likely to be added as a set of CRDs, and is still in the alpha stages, I feel like it may be a little unfair on the Istio case if this were merged into our core-codebase (and sort of opens up floodgates for more implementations afterwards).

From my understanding, the gateway API will not supersede Istio's VirtualService in future either, though I may be wrong :)

@jakexks

jakexks commented Jul 29, 2021 •

Copy link
Copy Markdown
Member Author

We don't expect to support Istio VirtualService ever!

This feature came out of the research into out-of-tree HTTP01 solving. It seems that the wider cloud-native community is coalescing around the Gateway API (in addition to their own APIs), and is already gaining wide adoption even in the alpha form: https://gateway-api.sigs.k8s.io/references/implementations/ .

We talked about it amongst the team and decided that having support for this one CRD in-tree would be better that supporting individual solutions. While it will never expose all the features of each service mesh or API router, the primitives are suitable enough for routing HTTP01 challenges, and this will be enough for people using any of the various implementations to be able to use cert-manager's ACME solver.

The alternative is making a pluggable HTTP-01 API and implementing this there. I think cert-manager is due a big refactor where all controllers become plugins and you could then pick and choose which features you want in your binary like Caddy, but that's for a future discussion

@jakexks jakexks changed the title Gateway API support for ACME HTTP-01 Solving [WIP] Gateway API support for ACME HTTP-01 Solving Jul 29, 2021
@jetstack-bot jetstack-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 29, 2021
Comment thread cmd/controller/app/controller.go Resolved

@irbekrm irbekrm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks really good to me!

Mostly interested if users will be ok with having to have a listener block for port 80 on the Gateway for the ACME challenge. I wonder if it may not be nice if that part too was done by cert-manager and maybe if it could be not permanent.
Just to consider alternatives, do you think it might make sense for cert-manager to modify the Gateway as well as creating the HTTPRoute or even allow for optionally creating a temp Gateway for this?

I was experimenting with deploying this with Contour, but got an error in the logs, but I guess that's expected since this is WIP

E0730 07:19:52.246505       1 sync.go:185] cert-manager/controller/challenges "msg"="propagation check failed" "error"="not implemented" "dnsName"="kuard.irbe-krumina-gcp.jetstacker.net" "resource_kind"="Challenge" "resource_name"="cm-test-ffx6l-425789567-139583572" "resource_namespace"="projectcontour" "resource_version"="v1" "type"="HTTP-01" 

Comment thread pkg/apis/acme/v1/types_issuer.go Resolved
Comment thread deploy/crds/crd-challenges.yaml Outdated
class:
description: The Gateway class to use when creating HTTPRoute resources to solve ACME challenges that use this challenge solver.
type: string
labels:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: also mark this field as required, so that it appears as such when running kubectl explain, like here

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.

How do I do this 😅 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you literally add it to the deploy/crds/crd-challenges.yaml file. Not whole of it is auto-generated (I think)

Comment thread pkg/apis/acme/v1alpha2/types_issuer.go Resolved
Comment thread cmd/controller/app/controller.go Resolved
Comment thread devel/addon/haproxy/install.sh Resolved
Comment thread pkg/issuer/acme/http/httproute.go Resolved
@jetstack-bot jetstack-bot added the area/testing Issues relating to testing label Jul 30, 2021
@jakexks

jakexks commented Jul 30, 2021

Copy link
Copy Markdown
Member Author

Mostly interested if users will be ok with having to have a listener block for port 80 on the Gateway for the ACME challenge. I wonder if it may not be nice if that part too was done by cert-manager and maybe if it could be not permanent.
Just to consider alternatives, do you think it might make sense for cert-manager to modify the Gateway as well as creating the HTTPRoute or even allow for optionally creating a temp Gateway for this?

I'm not sure. I feel like it's the responsibility of the cluster administrator to setup the Gateways and users can just use HTTPRoutes, which makes me feel like we should not mutate the Gateway and this way is cleaner.

@jakexks

jakexks commented Jul 30, 2021

Copy link
Copy Markdown
Member Author

My self review is a worry about the cert-manager API. We know that the gateway API is evolving and the field will not be stable. Is it OK to have a cert-manager.io/v1 resource not be compatible with a future cert-manager.io/v1 resource, as long as we make it very clear to users of the gateway API that this is experimental?

Comment thread pkg/internal/apis/acme/types_issuer.go Resolved
@irbekrm

irbekrm commented Jul 30, 2021

Copy link
Copy Markdown
Contributor

idr, if we these were ran already

/test pull-cert-manager-e2e-v1-22
/test pull-cert-manager-e2e-v1-16
/test pull-cert-manager-upgrade-v1-21

@irbekrm

irbekrm commented Jul 30, 2021

Copy link
Copy Markdown
Contributor

/test pull-cert-manager-e2e-v1-17
/test pull-cert-manager-e2e-v1-18
/test pull-cert-manager-e2e-v1-19
/test pull-cert-manager-e2e-v1-20

Just in case

@irbekrm irbekrm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've tested this e2e with Contour and seems to work nicely 🥳

My self review is a worry about the cert-manager API. We know that the gateway API is evolving and the field will not be stable. Is it OK to have a cert-manager.io/v1 resource not be compatible with a future cert-manager.io/v1 resource, as long as we make it very clear to users of the gateway API that this is experimental?

I guess the Kubernetes-native way would be to create an alpha CRD version for our Issuer type?

Looking at some implementations of Gateway API where it's integrated into the standard config, I see that it is sometimes marked as 'experimental', see i.e Traefik's configuration here and I'm also getting more convinced that we need to give some stronger indication of it being experimental.
I still think that adding a field named 'experimental..' that will later be deprecated is not much better than adding a field whose behaviour may change.
Maybe marking the issuer.spec.acme.solvers.http01.gateway as in '[Experimental]' in the description and also adding to the description which particular version of Gateway API it supports would be sufficient?


// Gateway contains configuration for the Gateway API controller
// being used during HTTP-01 tests.
Gateway Gateway

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit/Suggestion: either call this GatewayController or rename the one above to Ingress

@irbekrm

irbekrm commented Jul 30, 2021

Copy link
Copy Markdown
Contributor

I'm not sure. I feel like it's the responsibility of the cluster administrator to setup the Gateways and users can just use HTTPRoutes, which makes me feel like we should not mutate the Gateway and this way is cleaner.

It feels like because cert-manager syncs Gateways and creates Secrets for Gateways (in the namespace of the Gateway) modifying the Gateway would not be much different. But also, I think changing/modifying how this works could be done in the future when we know better how people want to use it.

Comment thread cmd/controller/app/controller.go Outdated
switch {
case apierrors.IsNotFound(err):
gatewayAvailable = false
log.Info("the Gateway API CRDs do not seem to be present, cert-manager will keep retrying watching for them")

@maelvls maelvls Jul 30, 2021 •

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 need to restart cert-manager to get the Gateway API solver/shim to work, right?

Is it still going to complain about the reflector not being able to list *v1alpha1.Gateway even though gatewayAvailable = false?

@maelvls

maelvls commented Aug 2, 2021 •

Copy link
Copy Markdown
Member

Irbe: Will users be ok with having to have a listener block for port 80 on the Gateway for the ACME challenge? Do you think it might make sense for cert-manager to modify the Gateway as well as creating the HTTPRoute or even allow for optionally creating a temp Gateway for this?

Is having a listener on port 80 really a requirement for solving a challenge? Yes, that's definitely a requirement. I was able to use a single listener on 443 with both haproxy-ingress and traefik. That might be due to HAProxy and Traefik forwarding traffic to 443 when no 80 listener is defined 🤔

Jake: I feel like it's the responsibility of the cluster administrator to setup the Gateways and users can just use HTTPRoutes, which makes me feel like we should not mutate the Gateway and this way is cleaner.

Maybe we should write that in the documentation: a listener on port 80 is required, and we advise using a dedicated label meant for the HTTPRoutes that will be created:

apiVersion: networking.x-k8s.io/v1alpha1
kind: Gateway
metadata:
  name: example-traefik
  annotations:
    cert-manager.io/issuer: letsencrypt-traefik
spec:
  gatewayClassName: traefik
  listeners:
  - protocol: HTTP
    port: 80
    routes:
      kind: HTTPRoute
      selector:
        matchLabels:
          gateway: http01-solver-traefik # 🔥 Dedicated to HTTPRoutes for challenges.
      namespaces:
        from: All

Or maybe people don't need to bother with a separate port 80 listener...

Most importantly, we shall send an event on the Issuer to notify the user that this issuer may not work due to the labels given not being compatible with one of the port 80 listeners.

For the ingress HTTP-01 solver, the ingress controller must also be configured "by the operator" to accept connections on port 80 (cert-manager is not able to "temporarily" add port 80 to the proxy's configuration since it doesn't know how to configure proxies)

@maelvls

maelvls commented Aug 2, 2021 •

Copy link
Copy Markdown
Member

Is it OK to have a cert-manager.io/v1 resource not be compatible with a future cert-manager.io/v1 resource, as long as we make it very clear to users of the gateway API that this is experimental?

I am also worried about this. Currently, the Gateway API is at v1alpha1, and
they are probably going to go through at least one other breaking version e.g.
v1beta1 before going v1 in a few years.

With an experimental field:

kind: Issuer
spec:
  acme:
    solvers:
      - http01:
          # Everything under this field may be removed or changed in the future,
          # and the only supported Gateway API version is `v1alpha1`.
          experimental:
            httpRoute:
              labels:
                gateway: example-haproxy
  1. Would we only support the latest version of the Gateway API, or would we have a version flag to let the user decide which apiVersion to be used when creating the temporary HTTPRoute?
  2. Imagining that v1beta1 changes the semantics of the label selector on the HTTPRoute, would we deprecate the labels field and have another one e.g. labels2?

After all, since our API surface seems quite small, maybe we don't need to worry that much about labels breaking (pretty sure the label selector mechanism is here to stay). What I am more worried about is how to support various versions (v1alpha1 currently, v1alpha2 very soon, and probably v1beta1 and v1).

@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 Aug 3, 2021
@irbekrm

irbekrm commented Aug 3, 2021

Copy link
Copy Markdown
Contributor

These all should pass now

/test pull-cert-manager-e2e-v1-22
/test pull-cert-manager-e2e-v1-19
/test pull-cert-manager-e2e-v1-20
/test pull-cert-manager-upgrade-v1-21

@maelvls maelvls 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.

🎉🎉

To close the above discussions, here is what we went with:

Gateway shim

  • To be able to use the gateway shim feature, users have to pass --controllers=*,gateway-shim.
  • When cert-manager is started with the gateway shim feature turned on but the Gateway API CRDs are not yet installed, the user will be warned that the CRD should be installed.
  • The user can install the CRD after starting cert-manager, and cert-manager will pick it up.

Gateway HTTP-01 solver

  • To be able to use the gateway solver, users need to install the Gateway API CRDs,
  • When cert-manager is started without the CRDs installed, cert-manager says that the Gateway HTTP-01 solver support is disabled due to the CRDs no being installed,
  • In order to install the CRDs after cert-manager is running, you have to restart cert-manager.

Name of the field in the Issuer, Gateway API breaking the Issuer API

In previous discussion, we had talked about nesting the Gateway API solver configuration on the Issuer under an experimental field, but we did not go with this idea. Instead, the API documentation says [Experimental]. The Issuer configuration looks like this:

kind: Issuer
spec:
  acme:
    solvers:
      - http01:
          gatewayHTTPRoute:
            ServiceType: ClusterIP
            labels:
              gateway: example-haproxy
            # We decided not to add "podTemplate".

The podTemplate field was not added, I'll link the discussion TBD

/lgtm
/hold

@jetstack-bot jetstack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 3, 2021
@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jakexks, maelvls

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

The pull request process is described here

Details 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 removed the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jakexks

jakexks commented Aug 3, 2021

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-e2e-v1-16
/test pull-cert-manager-e2e-v1-17
/test pull-cert-manager-e2e-v1-18

Signed-off-by: Jake Sanders <[email protected]>
@irbekrm

irbekrm commented Aug 3, 2021

Copy link
Copy Markdown
Contributor

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jetstack-bot jetstack-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jakexks

jakexks commented Aug 3, 2021

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-e2e-v1-16
/test pull-cert-manager-e2e-v1-17
/test pull-cert-manager-e2e-v1-18

Comment thread devel/run-e2e.sh Resolved
@jakexks

jakexks commented Aug 3, 2021

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-e2e-v1-16
/test pull-cert-manager-e2e-v1-21

"Pod got deleted unexpectedly" 😖

@irbekrm

irbekrm commented Aug 3, 2021

Copy link
Copy Markdown
Contributor

Probably a flake

/test pull-cert-manager-bazel

@irbekrm

irbekrm commented Aug 3, 2021

Copy link
Copy Markdown
Contributor

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jakexks

jakexks commented Aug 3, 2021

Copy link
Copy Markdown
Member Author

/hold cancel

@jetstack-bot jetstack-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 3, 2021
@jetstack-bot
jetstack-bot merged commit d647e54 into cert-manager:master Aug 3, 2021
@jetstack-bot jetstack-bot added this to the v1.5 milestone Aug 3, 2021
@inteon inteon mentioned this pull request Aug 6, 2021
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/http01 Indicates a PR modifies ACME HTTP01 provider code 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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. 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.

Support for solving HTTP01 challenges with the Gateway API

6 participants