AI

Enable Authentication in Milvus

Security is an essential feature in any database. In Milvus, we can enhance the security by allowing the authentication in the Milvus cluster. This allows any client that connects to the cluster to provide the correct credentials before performing any actions on the server.

We can implement the authentication in Milvus using various methods such as username/password authentication, token-based authentication, or integration with external authentication systems like OAuth or LDAP. It is good to keep in mind that the various authentication methods may vary depending on the Milvus version.

This tutorial teaches how to configure the username and password authentication on the Milvus cluster.

Requirements:

To follow along with this post, ensure that you have the following:

  1. Access to Milvus server that runs on the Docker
  2. Permission to make modifications to the container

With the given requirements met, we can proceed to the next steps.

Enable the User Authentication with Docker

If you wish to run Milvus as a Docker container, you can enable the authentication by editing the Docker Compose file.

Start by downloading the Docker Compose file for Milvus as shown in the following command:

wget https://raw.githubusercontent.com/milvus-io/milvus/v2.2.10/configs/milvus.yaml

 

Once downloaded, modify the resulting YAML file and add the authentication by setting the “common.security.authorizationEnabled” in “milvus.yaml” to true.

You can then use the docker-compose command to run the Milvus container with the enabled username and password authentication on the cluster.

By default, Milvus creates a root user with the password of Milvus upon launching the instance.

Create an Authenticated User

Instead of using the default username and password credential of root/Milvus, it is recommended to create a different user to allow you to login in with custom credentials.

You can use the PyMilvus module to perform this action. The code is as follows:

from pymilvus import utility
utility.create_user('username', 'password', using='default')

 

The create_user() method accepts the target server’s username, password, and alias parameters.

Connect to the Milvus Server

Once you configured your target username and password, you can log in as the authenticated user with the code as follows:

from pymilvus import connections
connections.connect(
  alias='default',
  host='localhost',
  port='19530',
  user='username',
  password='password',
)

 

Conclusion

We learned how to enable the username and password authentication on the Milvus cluster by editing the Docker Compose configuration file.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list