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

Incorrect routing priority with wildcard host #3094

Closed
dsem opened this issue Dec 14, 2017 · 5 comments
Closed

Incorrect routing priority with wildcard host #3094

dsem opened this issue Dec 14, 2017 · 5 comments
Labels

Comments

@dsem
Copy link

dsem commented Dec 14, 2017

Summary

I believe the incorrect routing priority applied when there are two APIs configured, one with the hosts defined with a preceding wildcard, e.g., *.domain.com, and another with a matching host and a uris defined, e.g., hosts: subdomain.domain.com uris: /api.

Steps To Reproduce

  1. Create an API with a wildcard host rule:
    POST /apis
    {
        "name": "api-1",
        "hosts": "*.domain.com",
        "upstream_url": "upstream_one.com"
    }
    
  2. Create an API with a host rule that uses a subdomain with the same domain and a uris rule:
    POST /apis
    {
       "name": "api-2",
        "hosts": "subdomain.domain.com",
        "uris": "/api",
        "upsteam_url": "upstream_two.com"
    }
    
  3. Make a request to subdomain.domain.com/api. This request matches both APIs. Since api-2 defines two rules and api-1 only defines one, the request should be routed to api-2. However, in my tests, it's getting routed to api-1 at upstream_one.com

Additional Details & Logs

I observe this on a new orchestration of Kong following the guide in the kong-dist-kubernetes repo. This is running kong 0.11.2 backed by cassandra.

@dsem dsem changed the title Incorrect routing priority with wildcard host. Incorrect routing priority with wildcard host Dec 14, 2017
@kikito kikito added the task/needs-investigation Requires investigation and reproduction before classifying it as a bug or not. label Dec 18, 2017
@crejb
Copy link

crejb commented Feb 7, 2018

I've encountered a problem which appears to be similar. The scenario is the same except that both APIs have uris configured. The API with the subdomain specified in the host works, but the API with the wildcard specified does not work.

Steps To Reproduce

  1. Create an API with a wildcard host rule:
POST /apis
{
    "name": "api-1",
    "hosts": ["*.domain.com"],
    "uris": ["/api/api1"],
    "upstream_url": "http://upstream_one.com/"
}
  1. Create an API with a specific subdomain in the host rule:
POST /apis
{
    "name": "api-2",
    "hosts": ["subdomain.domain.com"],
    "uris": ["/api/api2"],
    "upstream_url": "http://upstream_two.com/"
}
  1. Request to subdomain.domain.com/api/api1 returns 404 no API found with those values
  2. Request to subdomain.domain.com/api/api2 works

@bungle
Copy link
Member

bungle commented Jan 3, 2019

I tried to reproduce what @dsem reported with 1.0.0 without success (using routes and services instead of deprecated apis). So I guess it might have been fixed already.

The issue with @crejb is what I can reproduce, so I mark this as a bug.

@thibaultcha
Copy link
Member

A new PR has been opened addressing this: #4775

@thibaultcha
Copy link
Member

Will be part of Kong 1.3.

@sudheer-jerripotula
Copy link

How can do this in DB less mode?? When I use regex in domain part in kong.yaml kong is throwing an error. I came across https://docs.konghq.com/hub/flash/set-dynamic-upstream-host/ which is not compatible in DB less mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants