Skip to content

Host component of bind_url should be used in dynamic rules but isn't #216

Description

@Kirill888

Bug description

Not sure if this is a "bug" or misunderstanding of configuration, or a missing feature to be honest.

My use case

  • Externally managed traefik proxy that handles some other services besides jupyterhub
  • External access via https with SNI (routing based on Host even when using TLS)
  • Using FileProvider, generating only dynamic rules

Dynamic routing rules generated by traefik-proxy ignore domain supplied in .public_url configuration.

Expected behaviour

I expect routing rules to include Host() component if that was configured in JupyterHub.bind_url, instead Host rule is only included when jupyterhub runs with host based routing.

If bind_url="https://example.com", I expect dynamic routing rules to be

Host(`example.com`)&&(PathPrefix(`/{ROUTESPEC}/`)||Path(`/{ROUTESPEC}`))  

Actual behaviour

generated dynamic routing rules only include PathPrefix and Path rules. Confirmed by code inspection here:

if routespec.startswith("/"):
# Path-based route, e.g. /proxy/path/
host = ""
path = routespec
else:
# Host-based routing, e.g. host.tld/proxy/path/
host, slash, path = routespec.partition("/")
path = slash + path
path_no_slash = path.rstrip("/")
path_rule = f"PathPrefix(`{path}`)"
if path_no_slash:
# include exact Path('/prefix') so that both /prefix/ and /prefix
# are served correctly
path_rule = f"( {path_rule} || Path(`{path_no_slash}`) )"
if host:
rule = f"Host(`{host}`) && {path_rule}"
else:
rule = path_rule

I think generate_rule function should take host argument extracted from .public_url configuration and if that is not empty include it in the rule.

How to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Your personal set up

  • OS:
  • Version(s):
Full environment
# paste output of `pip freeze` or `conda list` here
Configuration
# jupyterhub_config.py
Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions