feat: add support for from-to-www-redirect#337
feat: add support for from-to-www-redirect#337chakravardhan wants to merge 2 commits intokubernetes-sigs:mainfrom
Conversation
…w-redirect annotations
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: chakravardhan The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @chakravardhan. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
@chakravardhan the from-www-redirect seems reasonable to me, but have you how it would work with #299? what happens if you have from-www-redirect and that the ones in #299? I'm hoping #299 merges soon. Otherwise, the implementation seems good at a quick glance. As for force-ssl-redirect, I'm not sure if we want or event need this annotation. My understanding as follows:
The problem is that gateway API doesn't have a "listen on 443 with a runtime-generate self-signed cert". That is, we might redirect to HTTPS, but not have an HTTPS listener at all! Haven't looked at the code too much, but LMK what you think. |
Thanks for your reply! @Stevenjin8 Regarding You are absolutely right. Gateway API doesn't have the concept of generating self-signed listener certificates on the fly like NGINX does. If we force a redirect to 443 without actual TLS secrets configured, most Gateway implementations (like GKE) will just reject the route or fail to open the listener, leading to a broken state. Regarding In our current implementation, we generate an entirely separate Because #299 adds If there is an overlap where a user configures both |
|
@chakravardhan I don't think this is quite right. Do you mind writing an e2e/integration test just to verify that behavior is correct/taking a quick look at https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#redirect-fromto-www ? For example, the annotation can redirect host.com to www.host.com and from www.host.com to host.com, depending on the initial configuration. Also when I run it with apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: httpbin
port:
number: 8000I get apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
annotations:
gateway.networking.k8s.io/generator: ingress2gateway-dev
name: nginx
namespace: default
spec:
gatewayClassName: nginx
listeners:
- hostname: example.com
name: example-com-http
port: 80
protocol: HTTP
status: {}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
annotations:
gateway.networking.k8s.io/generator: ingress2gateway-dev
name: example-ingress-example-com
namespace: default
spec:
hostnames:
- example.com
parentRefs:
- name: nginx
rules:
- backendRefs:
- name: httpbin
port: 8000
matches:
- path:
type: PathPrefix
value: /
name: rule-0
status:
parents: []
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
annotations:
gateway.networking.k8s.io/generator: ingress2gateway-dev
name: example-ingress-example-com-www-redirect
namespace: default
spec:
hostnames:
- example.com
parentRefs:
- name: nginx
rules:
- filters:
- requestRedirect:
hostname: www.example.com
statusCode: 308
type: RequestRedirect
status:
parents: nullWe have two http routes with the same host name, the last httproute should be apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
annotations:
gateway.networking.k8s.io/generator: ingress2gateway-dev
name: example-ingress-example-com-www-redirect
namespace: default
spec:
hostnames:
- - example.com
+ - www.example.com
parentRefs:
- name: nginx
rules:
- filters:
- requestRedirect:
- hostname: www.example.com
+ hostname: example.com
statusCode: 308
type: RequestRedirect
status:
parents: nullAlso, the gateway would need to be updated apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
annotations:
gateway.networking.k8s.io/generator: ingress2gateway-dev
name: nginx
namespace: default
spec:
gatewayClassName: nginx
listeners:
- hostname: example.com
name: example-com-http
port: 80
protocol: HTTP
+ - hostname: www.example.com
+ name: www.example-com-http
+ port: 80
+ protocol: HTTP
status: {} |
What type of PR is this?
/kind feature
What this PR does / why we need it:
When the
from-to-www-redirectannotation is encountered and set to"true", the translator generates a completely separate, dedicatedHTTPRoutefor the redirect.Compatibility with
permanent-redirect(#299)There is a potential edge case where a user specifies both
from-to-www-redirectandpermanent-redirecton the same Ingress resource.How this is handled:
from-to-www-redirect) generates a completely separateHTTPRoutededicated to the www/non-www redirect. Because they operate on differentHTTPRouteobjects or distinct hostnames, they do not overwrite each other during the Intermediate Representation (IR) generation. When emitted, the Gateway API handles this overlap natively and gracefully by selecting the most specificHostnamematch for routing the request.Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?: