如何在 mlFlow 服务器上运行身份验证?

hel*_*per 8 nginx basic-authentication mlflow

当我将我的整个模型和参数记录到 mlflow 中时,我认为最好用用户名和密码保护它。

我使用以下代码运行mlflow服务器

mlflow server --host 0.0.0.0 --port 11111 工作完美,在myip:11111我的浏览器中,我输入并看到所有内容(最终是问题所在)

如果我理解文档和以下https://groups.google.com/forum/#!topic/mlflow-users/E9QW4HdS8a8链接正确,我应该使用 nginx 来创建身份验证。

我安装nginx open sourcreapache2-utils

创建的sudo htpasswd -c /etc/apache2/.htpasswd user1用户和密码。

我编辑了我/etc/nginx/nginx.conf的以下内容:

server {
        listen 80;
        listen 443 ssl;

        server_name my_ip;
        root NOT_SURE_WHICH_PATH_TO_PUT_HERE, THE VENV?;
        location / {
            proxy_pass                      my_ip:11111/;
            auth_basic                      "Restricted Content";
            auth_basic_user_file /home/path to the password file/.htpasswd;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但没有出现身份验证。

如果我将 conf 更改为侦听, listen 11111 我会收到一个错误,表明该端口已在使用中(当然,由 mlflow 服务器....)

我的愿望是在任何人都可以使用浏览器通过 mlflow 输入之前有一个身份验证窗口。

很高兴听到任何建议。

hel*_*per 5

这里的问题是,无论是mlflownginx试图运行在相同的端口...

  1. 首先让我们处理nginx:

    1.1 在 /etc/nginx/sites-enable 新建一个文件sudo nano mlflow并删除存在的默认值。

    1.2在mlflow文件中:

server {
    listen YOUR_PORT;
    server_name YOUR_IP_OR_DOMAIN;
    auth_basic           “Administrator’s Area”;
    auth_basic_user_file /etc/apache2/.htpasswd; #read the link below how to set username and pwd in nginx

    location / {
        proxy_pass http://localhost:8000;
        include /etc/nginx/proxy_params;
        proxy_redirect off;
    }
}
Run Code Online (Sandbox Code Playgroud)

1.3. 重启nginxsudo systemctl restart nginx

  1. 在您的服务器上运行 mlflow mlflow server --host localhost --port 8000

现在,如果您尝试在浏览器中访问 YOUR_IP_OR_DOMAIN:YOUR_PORT ,应该会出现一个身份验证弹出窗口,输入您的主机并通过,现在您进入了 mlflow

  1. 现在有 2 个选项可以告诉 mlflow 服务器有关它的信息:

    3.1 设置用户名和密码为环境变量 export MLFLOW_TRACKING_USERNAME=user export MLFLOW_TRACKING_PASSWORD=pwd

    3.2 在你/venv/lib/python3.6/site-packages/mlflowpackages/mlflow/tracking/_tracking_service/utils.py的函数中编辑

def _get_rest_store(store_uri, **_):
    def get_default_host_creds():
        return rest_utils.MlflowHostCreds(
            host=store_uri,
            username=replace with nginx user
            password=replace with nginx pwd
            token=os.environ.get(_TRACKING_TOKEN_ENV_VAR),
            ignore_tls_verification=os.environ.get(_TRACKING_INSECURE_TLS_ENV_VAR) == 'true',
        )
Run Code Online (Sandbox Code Playgroud)

在您使用 mlflow 的 .py 文件中:

import mlflow
remote_server_uri = "YOUR_IP_OR_DOMAIN:YOUR_PORT" # set to your server URI
mlflow.set_tracking_uri(remote_server_uri)
mlflow.set_experiment("/my-experiment")
with mlflow.start_run():
    mlflow.log_param("a", 1)
    mlflow.log_metric("b", 2)
Run Code Online (Sandbox Code Playgroud)

nginx 身份验证文档的链接https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/