istio: httpsRedirect breaks cert-manager acme challenge, which was working in Istio 1.6
Bug description After upgrading from 1.6.2 to 1.7.2 then cert-manager acme challenges failed to complete. I finally worked out that if I deleted the istio gateway resource for that host then the certificate request completed.
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-istio
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: hostmaster@example.com
privateKeySecretRef:
name: letsencrypt-istio
solvers:
- selector: {}
http01:
ingress:
class: istio
The order, challenge and ingress are all created and the acme pod starts but it just never completes.
[ ] Docs [ ] Installation [X] Networking [ ] Performance and Scalability [ ] Extensions and Telemetry [ ] Security [ ] Test and Release [X] User Experience [ ] Developer Infrastructure
Expected behavior Certificate requests complete successfully as they did in version 1.6.2
Version (include the output of istioctl version --remote
and kubectl version --short
and helm version
if you used Helm)
$ istioctl version --remote
client version: 1.7.2
control plane version: 1.7.2
data plane version: 1.7.2 (57 proxies)
$ kubectl version --short Client Version: v1.17.3 Server Version: v1.17.3
How was Istio installed? istioctl upgrade -f istio-operator.yaml
Environment where bug was observed (cloud vendor, OS, etc) Kubernetes 1.17.3 on-premise on Centos 7
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 13
- Comments: 34 (12 by maintainers)
Commits related to this issue
- Fix issues around tlsRedirect * Fixes https://github.com/istio/istio/issues/27315 * Fixes https://github.com/istio/istio/issues/27157 This partially reverts https://github.com/istio/istio/pull/24958... — committed to howardjohn/istio by howardjohn 3 years ago
- Fix issues around tlsRedirect (#29895) * Fix issues around tlsRedirect * Fixes https://github.com/istio/istio/issues/27315 * Fixes https://github.com/istio/istio/issues/27157 This partially reverts... — committed to istio/istio by howardjohn 3 years ago
- Fix issues around tlsRedirect (#29895) * Fix issues around tlsRedirect * Fixes https://github.com/istio/istio/issues/27315 * Fixes https://github.com/istio/istio/issues/27157 This partially reverts... — committed to howardjohn/istio by howardjohn 3 years ago
- Fix issues around tlsRedirect (#29895) (#30134) * Fix issues around tlsRedirect * Fixes https://github.com/istio/istio/issues/27315 * Fixes https://github.com/istio/istio/issues/27157 This partiall... — committed to istio/istio by howardjohn 3 years ago
- Attempt to HTTPS redirect in apps instead of Istio Istio won't automatically exclude .well-known paths, for cert-manager. See this issue: https://github.com/istio/istio/issues/27643 — committed to code-supply/code-supply by camelpunch 3 years ago
For anyone looking for a solution, here might be one. This has also be mentioned in https://discuss.istio.io/t/how-to-redirect-to-https-except-for-well-known-acme-challenge/9011/4.
Enabling
cert-manager.io/issue-temporary-certificate
generates a self-signed certificate until a valid one is available. Let’s Encrypt states that they follow HTTPS redirects without checking the certificate.@coldguy101
Thank you for your post. It didn’t quite work for me, but it got me to this solution which is working for me. Here is the complete declaration.
Definitely. This is actually not low priority in my opinion, but its really hard to fix unfortunately
To supplement @sneko 's answer above, we can do a better match for http01 requests.
FROM:
TO:
@coldguy101 what is the full definition you used for the VirtualService? Maybe it’s possible to do a wildcard VirtualService matching ALL 80 ports EXCEPT with the prefix
/.well-known/acme-challenge/
(to do the redirection of scheme).Also, just wanted to know if the Istio team is aware of the best practise to use right now? The issue looks important but staled?
Thank you,
@howardjohn Is there any updates on this issue? I would rather not split VS and gateway into four resources as you show above if update is on its way.
Thanks.
The solution from @sazzle2611 is the correct one. I’ve written a bit more in detail about why and how it works: https://gruchalski.com/posts/2023-07-09-istio-cert-manager-lets-encrypt-and-https-redirect/.
— BELOW A POTENTIAL SIMPLE HACKY SOLUTION 😃 —
Every 3 months I’m like struggling hard with Istio and CertManager and I’m so sad after years it’s still a real pain even for really simple use cases (using
httpsRedirect: true
for example). Hope a proper solution will come out one day!My solution:
/.well-known/acme-challenge/
(due to limitation of the RE2 regex It’s a bit hacky but working!)gateway.yaml
🏎️💨
This worked for us, we changed tls httpsRedirect to false (or commented it out) in the gateway and then added this as the first rule under http in the virtual service
We have so far changed about 50 configs to this in the last 6 months and not had a problem yet
Just ran into this problem also. My work-around was to stop using
in my Istio Gateway spec, and instead use a VirtualService matcher to do the redirection.
Doing this allowed cert-manager to insert its own HTTP routes, and when those get cleaned up automatically, revert back to the standard redirect.
Your theory sounds correct to me just based on my observation.
Here is my fully Gateway config:
And in case it’s useful the ingress that was generated by cert-manager:
Thank you for your attention on this, it is much appreciated!
I think to do it we would need to stop using RequireTLS in envoy, and instead use route_action.https_redirect and a match on
:scheme
. This is not only a big change, but its broken in envoy currently: https://github.com/envoyproxy/envoy/issues/14587. So would likely be a while until fixed.