In order for you to setup authentication for mlflow Tracking Server using nginx, you essentially need to do the following;
- should be nginx/nginx plus (but nginx will serve this purpose)
- you need two ports to be opened one for tracking server to run by default(11111 in your case) other one to run airflow with password protection(say 8080 and it could be any port which has to be opened by firewall)
- create a auth file by using htpasswd utility under the
/etc/nginx
directory by using the command sudo htpasswd -c /etc/nginx/.htpasswd user_name
and enter the password when it prompted.
- Make sure you have changed the permission to 644 to this file, otherwise your proxy redirection will work, but you might hit the 500 error after you enter the username and password, this is because of auth file is not accessible by the service.
Now, you can go to sudo nano /etc/nginx/sites-enabled/default
file comment everything inside the file and create a separate server block and put down the below configuration, you wonder why you need to edit this file alone? then i highly recommend to check this out this discussion Difference between sites-enabled and sites-available? After you made the change, your configuration file typically looks like this
server {
listen 8080;
location / {
proxy_pass http://localhost:11111;
auth_basic "Administrator’s Area";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
Once you finished the above, you can check the diagnosis of the configuration then you need to restart the nginx server
sudo nginx -t
sudo service nginx restart
Now, you can check with your new port which is 8080 in your case, hopefully it should work.
You have to also set the environment variables for mlflow to use the updated credentials while you run your training jobs.
In your code add the below lines,
import os
# Set username and password when authentication was added
os.environ['MLFLOW_TRACKING_USERNAME'] = <MLFLOW_TRACKING_USERNAME>
os.environ['MLFLOW_TRACKING_PASSWORD'] = <MLFLOW_TRACKING_PASSWORD>
Additional Tip:
- You can also add ssl in the configuration, so that you can use https protocal instead of http, assume you have certificates. If you don't have you can create self signed one or use some of the free tools like certibot, etc..
Then your configuration would be similar like this, you have to add this certificates beneath port listening part;
listen 8080 ssl;
#server_name YOUR_IP_OR_DOMAIN;
ssl_certificate /etc/nginx/certificate/certificate.crt;
ssl_certificate_key /etc/nginx/certificate/certificate.key;
- Sometimes, though you did everything as per the procedure, but authentication might not reflect. In such case, you need to change the owner of the auth file to 'www-data user' from root.
Hope this post will helps while setting up first time and in debugging.
Thank you.