Skip to content

http01 is defeated by Ingress auth, cert-manager should have option to create own Ingress when using ingress-shim #235

Closed
helm/charts
#5130

Description

@whereisaaron

/kind feature

What happened:

Created an Ingress with these annotations:

  annotations:
    kubernetes.io/tls-acme: true
    certmanager.k8s.io/cluster-issuer: letsencrypt-staging
    kubernetes.io/ingress.class: nginx-prod
    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: my-basic-auth
    nginx.ingress.kubernetes.io/auth-realm: "Authentication Required"

The certificate was not issued because the ACME requests to /.well-known/acme/ received a 401 response.

172.24.10.56 - [172.24.10.56] - - [06/Jan/2018:23:35:27 +0000] "GET /.well-known/acme-challenge/NzRQOsG_eWiklofEKisjHprBHnPvXL1osIyz1SuKidc HTTP/1.1" 401 195 "-" "Go-http-client/1.1" 180 0.000 [foo-foo-operated-web] - - - -

What you expected to happen:

Certificate and Secret created. I expected the ingress-shim would create and Ingress for the /.well-known/acme/ path. And since that ingress has no auth, the ACME validation would succeed. I get this behavior with k-c-m because the nginx-ingress config scoops off and redirects all /.well-known/acme/ requests to k-c-m, before they hit the per-ingress config.

I think this problem comes up because cert-manager is modifying the existing Ingress (with auth) rather than creating an Ingress of it own for the /.well-known/acme/ path (without any auth).

How to reproduce it (as minimally and precisely as possible):

Add auth header to an Ingress as above.

Anything else we need to know?:

Environment:
kube-aws clusters on AWS.

Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.5", GitCommit:"cce11c6a185279d037023e02ac5249e14daa22bf", GitTreeState:"clean", BuildDate:"2017-12-07T16:16:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8+", GitVersion:"v1.8.4+coreos.0", GitCommit:"4292f9682595afddbb4f8b1483673449c74f9619", GitTreeState:"clean", BuildDate:"2017-11-21T17:22:25Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}

Activity

  1. added
    kind/feature
    on Jan 7, 2018
  2. euank commented on Jan 7, 2018

    @euank
    Contributor

    I think this might be a little hairier due to the existence of many ingress controllers with various featuresets.

    I know of at least one ingress controller which does not merge ingress rules with the same host (the nginxinc one).

    How ingresses are merged is implementation dependent as well, so e.g. nginx might do the right tihng and apply auth to one, but not the other, but it would also be unsurprising if a similar ingress applied auth to both if it had merged them for having the same host.

    I worry that the only way to handle this well with how ingress controllers currently behave is to do one of:

    1. Have ingress specific logic for differences like this
    2. Only support a ingress controllers which are common and behave well with whatever cert-manager chooses to do, even if some others don't
    3. Entirely punt this to the user/ingress side of it, requiring user+ingress to be able to 'whitelist' the well-known path.

    I think all of those options are somewhat reasonable. 2 seems like the best for a number of reasons, but if we're going with it, we should probably explicitly document the behaviour we expect and the ingress controllers we know work.

    That being said, I don't entirely like changing behaviour of cert-manager, which should be generic, to work around an nginx-ingress-controller-specific quirk, so 3 seems a little more idealistically pretty.

    I'm curious, could you make this work with 3 now by simply creating two ingress objects with the same host yourself, one with the auth annotations, and the other with the tls annotation and an arbitrary path/service which can be public (e.g. /.well-known/placeholder -> 'default-backend' or such?)

  3. munnerz commented on Jan 7, 2018

    @munnerz
    Member
  4. whereisaaron commented on Jan 7, 2018

    @whereisaaron
    ContributorAuthor

    Thanks for the discussion @euank @munnerz.

    Both strategies - new Ingress or patch the existing Ingress - seem clean and valid to me. I am certainly not suggesting one is wrong or always preferred.

    @munnerz an Ingress annotation to choose which 'strategy' sounds excellent, with the user being able to choose which strategy (new Ingress or patch existing Ingress) best fits the behavior of their ingress controller, without cert-manager having to pay attention or care which ingress controller implementation is being used.

    I agree the CLI flag would be a bit limiting if cert-manager aims to be a global cluster service, as multiple different ingress controller implementations are likely running in the same cluster for different application requirements.

    @euank I think this is option '4' :-) Don't try to accommodate ingress controller foibles, punt that by letting the user control cert-manager's behavior.

    @munnerz thanks for the tip about ingressClass vs ingress, that's already great control of the strategy used. I'll try it out.

  5. whereisaaron commented on Jan 7, 2018

    @whereisaaron
    ContributorAuthor

    @munnerz that ingressClass / ingress strategy choice in Certificate resources is awesome! I realize that with that option I can issue certificates via http01 validation before even deploying the application or its Ingress. That's something I could only do with dns01 validation before.

    An Ingress annotation equivalent to that strategy choice would still be very convenient. Especially for helm deployments, where most charts offer to inject Ingress annotations, but don't (yet :-) have an option to create cert-manager Certificate resources.

    @euank @munnerz I can also confirm it works with authenticated apps under nginx-ingress, where you deploy the app with an authenticated Ingress first, then create the Certificate with ingressClass and http01. The authentication is correctly not applied to the Ingress+path that cert-manager creates, and the certificate is validated an issues, whilst the app remains authenticated. That's good news for renewals too.

    So if the Ingress strategy annotation is added, you could deploy a typical helm chart, using its Ingress annotation setting, to deploy an authenticated HTTPS application.

  6. changed the title [-]https01 is defeated by Ingress auth, cert-manager should create own Ingress[/-] [+]https01 is defeated by Ingress auth, cert-manager should have option to create own Ingress[/+] on Jan 7, 2018
  7. changed the title [-]https01 is defeated by Ingress auth, cert-manager should have option to create own Ingress[/-] [+]https01 is defeated by Ingress auth, cert-manager should have option to create own Ingress when using ingress-shim[/+] on Jan 8, 2018
  8. changed the title [-]https01 is defeated by Ingress auth, cert-manager should have option to create own Ingress when using ingress-shim[/-] [+]http01 is defeated by Ingress auth, cert-manager should have option to create own Ingress when using ingress-shim[/+] on Jan 8, 2018
  9. munnerz commented on Jan 8, 2018

    @munnerz
    Member

    So it seems this issue specifically only effects people that do not want to manually configure their Certificate resources and instead use ingress-shim functionality to enable TLS on ingresses.

    This again boils down to the issue of differences in ingress implementations. An annotation is a nice and easy escape hatch, and given the current default behaviour works on 'vanilla' ingresses for all ingress controllers (afaik), I think it'd be an acceptable addition.

    We can pluck the ingress class value from the ingress itself, unless there's some use case for allowing a different class to be used? I'd rather not overcomplicate the API surface and make it harder to use if we can avoid it.

  10. whereisaaron commented on Jan 8, 2018

    @whereisaaron
    ContributorAuthor

    True. Creating a Certificate resource is the way to do this with cert-manager. The annotation comes in a different section of the documentation under 'hacks we support to make it easy for people to adopt cert-manager' 😄

    These annotations allow users to e.g. deploy a stable Helm chart without forking and modifying your own version to add Certificates. Or else organizing a separate chart or deployment for the Certificate.

  11. argusua commented on Feb 16, 2018

    @argusua

    Also, when using nginx-ingress-controller with enabled ssl-redirect, we got http response 308 for /.well-known/acme/ urls and renewing certificates functionality doesn't work.

  12. monotek commented on Feb 22, 2018

    @monotek

    Just run into exactly the same problem.
    Imho this is a bug and not a feature.
    In Kube-Lego this was not a problem.

  13. munnerz commented on Feb 22, 2018

    @munnerz
    Member

    kube-lego managed to avoid this as you would explicitly configure the 'nginx ingress controller' as an option that worked cluster-wide. This means that we'd always create additional Ingress resources and not expose the choice (without changing CLI flags on kube-lego).

    As mentioned before, an annotation to switch this behaviour would work well, but overloading annotations and pushing all this understanding onto end-users is painful.

    What we need to decide to do something here:

    • Do we set ingressClass or ingress by default?
      • Set ingress by default (what we do today): works for all kinds of ingress controller, including renewal, so long as additional annotations (e.g. auth) are not specified.
      • Set ingressClass by default: works only for nginx-like ingress controllers out of the box, and the user will then be forced to provide an additional annotation (eg certmanager.k8s.io/acme-http01-strategy: "in-place" or certmanager.k8s.io/edit-in-place) when using an ingress controller like GCE.

    Whichever we choose, we need to ensure it is well documented. Having to understand so much about what is going on under the hood defeats the point of the abstractions we're trying to create, and eventually only serves to frustrate users (as they get to the point they understand the whole flow, and now they can't force cert-manager to do exactly what they want).

    We need to also bare in mind that these annotations may be used for issuers other than ACME too (e.g. CA based issuer, and the upcoming Vault issuer). These issuers won't respect or have any need for this annotation, so this really is ACME specific.

    Keen to hear thoughts on this, and I'm happy to integrate a solution.

  14. whereisaaron commented on Feb 22, 2018

    @whereisaaron
    ContributorAuthor

    The clean abstraction only exists in an annotation-free environment (know any? 😄 ). As soon as we have any behavior annotations:

    1. cert-manager has to be cloud-provider and/or ingress controller aware, before it can automatically do the right thing, and/or
    2. cert-manager needs enough manual control over strategy and annotations, so that users who understand under-the-hood can tell cert-manager the correct strategy.

    If we want to spare users the need to understand what they are doing, we have to build in cloud-provider and annotation-aware auto-magical behaviors, to see what cloud-provider, ingress controller, and annotation that user has decided to use, and pick the cert-manager strategy to navigate that.

    And then the power users are going to want to be able to turn that auto-magical behavior off and specify exactly the strategy and annotations they want.

  15. whereisaaron commented on Feb 22, 2018

    @whereisaaron
    ContributorAuthor

    In my mind, cert-manager creating and deleting its own Ingress resource for validation is always the better/clean default as opposed to modifying another application's Ingress. Where it can be avoided, I'd rather keep a clean separation between cert-manager and the applications' resources.

    So I personally would default to creating an Ingress. I would include the kubernetes.io/ingress.class because is pretty much blessed now it has been promoted to the stable 'kubernetes.io' namespace. I would let power users add whatever additional annotations to the Ingress they think helpful.

    The for the automatical behaviour, if cert-manager detects a problem environment, like GCE, or the nginxinc ingress controller (hard I guess?). It could log and switch to modifying Ingresses by default. I see these environments as edge cases, where the Ingress model doesn't work as intended.

    Specifically specifying either ingressClass or ingress is going to lock the behavior and override the default. But we could try to detect and log when the user has painted themselves into a corner. It could be enough to give them a bunch of ideas or a help-page URL in the log message whenever the validation pre-check fail.

  16. 13 remaining items

  17. whereisaaron commented on Feb 24, 2018

    @whereisaaron
    ContributorAuthor

    @monotek I don't think that is true at all, rather you've suddenly a whole lot of choices and power that kube-lego never gave you. We do need good documentation and a good helm chart to make the migration and the learning curve for the new capabilities easy for people.

    kube-lego only supports one issuer, one issuing protocol, one ingress controller, and one validation strategy. If that is all you need, and it works, then you're golden. If not, you're screwed. cert-manager supports multiple issuers (of multiple types), multiple protocols, multiple ingress controllers, and multiple validation strategies. Coming from kube-lego this is a bunch choices you just didn't even have before.

    What I think is the problem is how to help migrating users so they don't have to think about these new choices if they are just replacing kube-lego. I think we need to improve with the helm chart to have a default install that emulates the kube-lego simplicity and makes those choices for you, defaulting to (only) way kube-lego works, e.g. creates a default ClusterIssuer for Let's Encrypt using 'http01'.

  18. tuananh commented on Mar 12, 2018

    @tuananh

    defaulting to (only) way kube-lego works, e.g. creates a default ClusterIssuer for Let's Encrypt using 'http01'.

    I think that would be awesome. There are probably many kube-lego users coming here.

  19. eseliger commented on Mar 20, 2018

    @eseliger

    did you guys already decide on a way to handle this issue? would be down to help on the implementation as we really need this 🙂

  20. tankovich commented on Mar 20, 2018

    @tankovich

    We're running into the ingress-shim issue as well. We can manually create the certificate resource with the ingressClass: nginx spec without issue, but would like to use the ingress-shim. Is there currently a way to implement this via adding ingress-shim annotation(s) to specify NGINX as the ingress controller (Helm deploy)?

  21. smelchior commented on Mar 26, 2018

    @smelchior

    I am also running into this issue coming from kube-lego. Adding an option / annotation to make ingress-shim create the certificates with ingressClass: nginx would be awesome!

  22. LuckySB commented on Mar 29, 2018

    @LuckySB

    kubernetes dashboard with user authorithation need annotation
    nginx.ingress.kubernetes.io/secure-backends: "true"
    so acme request send to cert-pod via https...

    i create certifcate by hand:

    apiVersion: certmanager.k8s.io/v1alpha1
    kind: Certificate
    metadata:
      name: k8dash-domain-tld
      namespace: kube-system
    spec:
      secretName: k8dash-domain-tld
      issuerRef:
        name: letsencrypt
        kind: ClusterIssuer
      commonName: k8dash.domain.tld
      dnsNames:
      - k8dash.domain.tld
      acme:
        config:
        - http01:
            ingressClass: nginx
          domains:
          - k8dash.domain.tld
    
  23. Justkant commented on Apr 4, 2018

    @Justkant

    Hi @munnerz
    Is someone working on adding support for ingress annotations that switches the ingress-shim behavior ?
    So that we don't need to manually create/maintain Certificate Resources

  24. munnerz commented on Apr 4, 2018

    @munnerz
    Member

    @Justkant not currently as far as I am aware. My time is completely pre-occupied trying to get ready for acmev2, Vault and the upcoming 0.3 release.

    This would be a great first contribution from anyone looking to get involved 😄

  25. Justkant commented on Apr 4, 2018

    @Justkant

    Ok, I try to look at what I can do.
    I'm not a golang dev but we learn everyday by trying 😄

  26. Tim-Schwalbe commented on Apr 12, 2018

    @Tim-Schwalbe

    Hi, I created a certificate with the ingress-shim and edited the certificate afterwards to ingressClass: nginx. Should this work and renew the certificate with basic-auth enabled?

  27. Jokero commented on Apr 18, 2018

    @Jokero

    nginx-ingress 0.13.0 introduced no-auth-locations option with default value /.well-known/acme-challenge, so now it's possible and very easy to use nginx-ingress with basic auth + cert-manager with ingress-shim.
    More details are here kubernetes/ingress-nginx#2243

  28. monotek commented on Apr 19, 2018

    @monotek

    Imho this can be closed.
    Works for me with nginx-ingress 0.13.0 image :-)

  29. Justkant commented on Apr 19, 2018

    @Justkant

    IMHO We should wait for #493 to be merge

  30. munnerz commented on Jun 5, 2018

    @munnerz
    Member

    Closing as we've now got this option (and it is default in v0.3!) 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions