Skip to content
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

HTTPRequestRedirectFilter allows for wildcard hostnames #949

Closed
stevesloka opened this issue Nov 30, 2021 · 7 comments · Fixed by #956
Closed

HTTPRequestRedirectFilter allows for wildcard hostnames #949

stevesloka opened this issue Nov 30, 2021 · 7 comments · Fixed by #956
Labels
area/webhook good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@stevesloka
Copy link
Contributor

What happened:

Looking through the HTTPRequestRedirectFilter spec, the Hostname used has a default kubebuilder validation regex which would allow a user to specify a redirect of *.foo.com which might not make sense as a redirect hostname.

Controllers could catch this and set a condition, we could update the field to use a new hostname type which removes the ability to have a wildcard in the value, or maybe there's a use-case I'm not thinking of that folks would want this?

What you expected to happen:

Hostnames with wildcards would be rejected.

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

Here's a sample HTTPRoute:

kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1alpha2
metadata:
  name: kuard
  namespace: projectcontour
  labels:
    app: kuard
spec:
  parentRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: contour
  hostnames:
  - "local.projectcontour.io"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    filters:
      - requestRedirect:
          hostname: "*.stevesloka.com"
          scheme: https
          statusCode: 302
        type: RequestRedirect
    backendRefs:
    - kind: Service
      name: kuard
      port: 80

Right now Contour configures Envoy:

$ curl -i local.projectcontour.io                                                                                                                                 
HTTP/1.1 302 Found
location: https://*.stevesloka.com/
vary: Accept-Encoding
date: Tue, 30 Nov 2021 17:37:35 GMT
server: envoy
content-length: 0

But doesn't route properly:
image

@stevesloka stevesloka added the kind/bug Categorizes issue or PR as related to a bug. label Nov 30, 2021
@hbagdi
Copy link
Contributor

hbagdi commented Nov 30, 2021

Controllers could catch this and set a condition, we could update the field to use a new hostname type which removes the ability to have a wildcard in the value, or maybe there's a use-case I'm not thinking of that folks would want this?

// Hostname is the hostname to be used in the value of the `Location`
// header in the response.
// When empty, the hostname of the request is used.
//
// Support: Core
//
// +optional
Hostname *Hostname `json:"hostname,omitempty"`

My reading of the spec is the hostname of the request should be used as is - not the hostname defined in the route rule. So if the request is foo.example.com and the route hostname is *.example.com, the location header has foo.exampl.com as the hostname.

@stevesloka
Copy link
Contributor Author

I agree with what you said @hbagdi, maybe we're confusing two different bits.

In my example above, my route hostname is local.projectcontour.io which is matched on the incoming request, but the route match has a redirect to *.stevesloka.com, so the response has the HTTP 302 set with a Location: *.stevesloka.com which would be invalid (or just not make much sense).

@youngnick
Copy link
Contributor

Yeah, I agree that the hostname in a redirect shouldn't be able to be a wildcard, it should be a precise hostname.

@hbagdi
Copy link
Contributor

hbagdi commented Dec 2, 2021

Ah, I understood this wrong.
This needs an update to the validation function for HTTPRoute which then should be executed in the validation webhook.

@hbagdi hbagdi added area/webhook good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Dec 2, 2021
@stevesloka
Copy link
Contributor Author

Could we just introduce a new type referenced here (

Hostname *Hostname `json:"hostname,omitempty"`
) which removes the wildcard from the beginning? This way you would't need the admission controller change at all and just rely on the kubebuilder validation.

Happy to work on this!

@robscott
Copy link
Member

robscott commented Dec 3, 2021

Could we just introduce a new type

Agree, this is probably the best approach. Maybe we have WildcardHostname to represent the current value and Hostname that does not allow for wildcard values.

@stevesloka
Copy link
Contributor Author

Yup makes sense to me. I can take this up and get it updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/webhook good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants