認證用戶訪問
本指南解釋如何在 Milvus 中管理用戶認證,包括啟用認證、以用戶身份連接,以及修改用戶憑證。
TLS 和用戶認證是兩種不同的安全方法。如果你在 Milvus 系統中同時啟用了用戶認證和 TLS,你必須提供用戶名、密碼和證書檔路徑。有關如何啟用 TLS 的資訊,請參閱傳輸中的加密。
本頁的程式碼片段使用新的MilvusClient(Python) 與 Milvus 互動。適用於其他語言的新 MilvusClient SDK 將於未來更新中發佈。
啟用使用者驗證
要為您的 Milvus 伺服器啟用使用者驗證,請在 Milvus 配置檔案milvus.yaml
中設定 common.security.authorizationEnabled 為 true。如需有關配置的更多資訊,請參閱Configure Milvus with Docker Compose。
...
common:
...
security:
authorizationEnabled: true
...
若要為您的 Milvus 伺服器啟用使用者驗證,請在 Milvus 配置檔案中設定 authorizationEnabled 為 truevalues.yaml
。有關配置的詳細資訊,請參閱使用 Helm Charts 配置 Milvus。
...
extraConfigFiles:
user.yaml: |+
common:
security:
authorizationEnabled: true
...
要啟用認證,請在Milvus
CRD 中設定spec.common.security.authorizationEnabled
為true
。關於 Milvus CRD 的更多資訊,請參考使用 Milvus Operator 配置 Milvus。
apiVersion: milvus.io/v1beta1
kind: Milvus
metadata:
name: my-release
labels:
app: milvus
spec:
# Omit other fields ...
config:
common:
security:
authorizationEnabled: true
使用驗證連線到 Milvus
啟用認證後,您需要使用使用者名稱和密碼連線到 Milvus。預設情況下,當 Milvus 啟動時,root
使用者會以密碼Milvus
建立。以下是如何使用預設root
使用者在啟用驗證後連線至 Milvus 的範例:
# use default `root` user to connect to Milvus
from pymilvus import MilvusClient
client = MilvusClient(
uri='http://localhost:19530', # replace with your own Milvus server address
token="root:Milvus"
)
建立新使用者
以預設root
使用者身份連線後,您可以如下方式建立並驗證新使用者:
# create a user
client.create_user(
user_name="user_1",
password="P@ssw0rd",
)
# verify the user has been created
client.describe_user("user_1")
# output
# {'user_name': 'user_1', 'roles': ()}
關於建立使用者的更多資訊,請參考create_user()。
使用新使用者連線到 Milvus
使用新創建用戶的憑證進行連接:
# connect to milvus with the newly created user
client = MilvusClient(
uri="http://localhost:19530",
token="user_1:P@ssw0rd"
)
更新用戶密碼
使用下面的代碼更改現有用戶的密碼:
# update password
client.update_password(
user_name="user_1",
old_password="P@ssw0rd",
new_password="P@ssw0rd123"
)
關於更新使用者密碼的更多資訊,請參考update_password()。
如果您忘記舊密碼,Milvus 提供一個設定項目,允許您指定某些使用者為超級使用者。這樣當您重新設定密碼時,就不需要舊密碼了。
預設情況下,Milvus 配置檔案中的common.security.superUsers
欄位是空的,這表示所有使用者在重設密碼時都必須提供舊密碼。不過,您可以指定特定使用者為不需要提供舊密碼的超級使用者。在下面的片段中,root
和foo
被指定為超級使用者。
您應該在管理 Milvus 實例運行的 Milvus 配置文件中添加以下配置項目。
common:
security:
superUsers: root, foo
刪除使用者
要刪除使用者,請使用drop_user()
方法。
client.drop_user(user_name="user_1")
列出所有使用者
列出所有使用者。
# list all users
client.list_users()
限制
- 使用者名稱不得為空,且長度不得超過 32 個字元。必須以字母開頭,且只包含下劃線、字母或數字。
- 密碼必須至少有 6 個字元,長度不得超過 256 個字元。
下一步
- 您可能還想學習如何
- 如果您已準備好在雲上部署您的集群: