emissary-ingress / emissary

open source Kubernetes-native API gateway for microservices built on the Envoy Proxy

Home Page:https://www.getambassador.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redirects don't work with hosts that use mappingSelector.

leandrorosa opened this issue · comments

Describe the bug
Redirects are not being picked by emissary when it is associated with a Host by mappingSelector.
If the mappingSelector is removed from the Host it works.

To Reproduce
Create two hosts like this:

apiVersion: getambassador.io/v3alpha1
kind: Host
metadata:
  name: emissary-api-host
  namespace: emissary-ingress
spec:
  mappingSelector:
    matchLabels:
      type: api
  hostname: api.emissary.com
---
apiVersion: getambassador.io/v3alpha1
kind: Host
metadata:
  name: emissary-frontend-host
  namespace: emissary-ingress
spec:
  mappingSelector:
    matchLabels:
      type: frontend
  hostname: frontend.emissary.com

And then create a redirect like this:

apiVersion: getambassador.io/v3alpha1
kind:  Mapping
metadata:
  name: testing-redirect
  namespace: emissary-ingress
  labels:
    type: frontend
spec:
  hostname: '*'
  prefix: /redirect/test
  service: www.getambassador.io
  host_redirect: true
  prefix_redirect: /company/about-us

The redirect will not work.
If the mappingSelector is removed from the hosts it works.

Expected behavior
Redirects being applied with the mappingSelector.

Versions (please complete the following information):

  • Emissary-ingress: 3.9.1
  • Kubernetes environment: AKS
  • Version 1.25.6

Hi @leandrorosa, I think this is because of the wildcard hostname in the Mapping. "If the Host defines a mappingSelector and the Mapping also defines a hostname, both must match. Mapping with a hostname of "*" will associate with any Host that has no mappingSelector." A wildcard is probably not considered a match.

HI @cindymullins-dw,
We started to have a similar issue after upgrading from 3.1.0 to 3.7.2

We have one host:

apiVersion: getambassador.io/v3alpha1
kind: Host
metadata:
  name: wildcard
spec:
  ambassador_id: ["ambassador"]
  hostname: '*'
  acmeProvider:
    authority: none         
  requestPolicy:
    insecure:
      action: Route
  mappingSelector:
    matchLabels:
      foo: bar

Adding here 2 example of mappings, 1 of them with host_redirect: true

apiVersion: getambassador.io/v3alpha1
kind: Mapping
metadata:
  name: jobs-redirect
  labels:
    foo: bar
spec:
  ambassador_id: ["ambassador"]
  host_redirect: true
  precedence: 200
  prefix: /jobs
  prefix_redirect: /careers
  service: XYZ.com
  timeout_ms: 60000

and

apiVersion: getambassador.io/v3alpha1
kind: Mapping
metadata:
  name: no-host-redirect
  labels:
    foo: bar
spec:
  ambassador_id: ["ambassador"]
  precedence: 200
  prefix: /test
  prefix_redirect: /testing
  service: XYZ.com
  timeout_ms: 60000

Only the one with the host_redirect isn't working ( we don't see it in the envoy/envoy.json)

After we removed the mappingSelector from the host resource and added hostname: * in the mapping it started to work.
Another solution was to add DISABLE_STRICT_LABEL_SELECTORS: "true" environment variable.

Is there any issue with host_redirect mapping?

Versions:

  • ambassador edge stack 3.7.2 (emissary ingress 3.7.2)
  • Kubernetes environment: EKS, 1.27