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

feat: support running behind reverse proxy with path based routing #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hahahannes
Copy link
Contributor

Fix ##90

Feature

This feature will enable to run MlFlow together with this plugin to run behind a reverse proxy that routes traffic based on the path, e.g. /models. This requires some changes in the backend and frontend to use the prefix path. Ideally this prefix path should not be hardcoded or configured.

URL generation in the backend

We can use Werkzeugs ProxyFix (https://werkzeug.palletsprojects.com/en/stable/middleware/proxy_fix/) to use X-Forwarded-Prefix from the reverse proxy. This will enable url_for to generate the correct URL with the prefix

URL generation in the frontend

The UI needs to be configurable to use a base prefix. This could is done via en environment setting which per default is empty.

How to use the feature

The user has to properly configure their reverse proxy as well as override the base prefix in the UI code.

Required changes at Reverse Proxy

In order to work one needs to adjust his reverse proxy to set the needed header. Also at the moment accessing /models does not work as the requests for the static mlflow files as well as for the current username (https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/hack/menu.html#L42) will ignore the path. I did not want to introduce a new config variable to add the base path here manually so the quick fix is to redirect requests to /models to /models/. Then the relative paths will work again.

proxy_set_header X-Forwarded-Prefix /models;
location /models {
    return 301 /models/;
}

Required changes during build time

As the UI is part of the package, there is no easy way to set the basePrefix in the angular configuration without hardcoding it. Therefore, I am overriding it before building the UI. I have not find a way yet to set it dynamically. I tried overriding the compiled javascript in the pip package but was not successful as the production js code gets optimized

RUN git clone https://github.com/mlflow-oidc/mlflow-oidc-auth
RUN find '.' -name '*.ts' -exec sed -i -e 's@basePrefix: ""@basePrefix:"/models"@g' {} \;
RUN yarn install
RUN yarn release 
RUN python -m pip install .

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

Successfully merging this pull request may close these issues.

1 participant