授予角色特權或特權群組
建立角色後,就可以授予角色權限。本指南介紹如何授予角色特權或特權群組。
授予角色一個特權或特權群組
Milvus 2.5 引入了新版本的 API,簡化了授予操作。向角色授予權限時,不再需要查找對象類型。以下是參數和相對應的解釋。
role_name:需要授予特權或特權群組的目標角色名稱。
Resource: 資源:特權的目標資源,可以是特定的實體、資料庫或集合。下表解釋如何在
client.grantV2()
方法中指定資源。
層級 | 資源 | 授予方法 | 註解 |
---|---|---|---|
收集 | 特定的收藏集 | client.grant_privilege_v2(role_name="roleA", privilege="CollectionAdmin", collection_name="col1", db_name="db1") | 輸入目標集合的名稱,以及目標集合所屬資料庫的名稱。 |
特定資料庫下的所有集合 | client.grant_privilege_v2(role_name="roleA", privilege="CollectionAdmin", collection_name="*", db_name="db1") | 輸入目標資料庫的名稱和通配符 | |
**Database** | 特定資料庫 | client.grant_privilege_v2(role_name="roleA", privilege="DatabaseAdmin", collection_name="*", db_name="db1") | 輸入目標資料庫的名稱和通配符 |
目前實例下的所有資料庫 | client.grant_privilege_v2(role_name="roleA", privilege="DatabaseAdmin", collection_name="*", db_name="*") | 輸入 | |
** 實例** | 目前的實體 | client.grant_privilege_v2(role_name="roleA", privilege="ClusterAdmin", collection_name="*", db_name="*") | 輸入 |
權限:您需要賦予角色的特定權限或權限群。目前,Milvus 提供 56 種可授予的特權。下表列出了 Milvus 中的特權。
下表中的類型欄是用戶為了方便您快速查找特權,僅用於分類目的。在授予特權時,您不需要瞭解其類型。您只需輸入相應的特權。
類型 | 特權 | 說明 | 客戶端的相關 API 描述 |
---|---|---|---|
資料庫權限 | 列出資料庫 | 檢視目前實例中的所有資料庫 | |
描述資料庫 | 檢視資料庫的詳細資訊 | ||
建立資料庫 | 建立資料庫 | ||
丟棄資料庫 | 丟棄資料庫 | ||
更改資料庫 | 修改資料庫的屬性 | ||
收集權限 | GetFlushState | 檢查資料集沖洗作業的狀態 | |
取得載入狀態 | 檢查集合的載入狀態 | ||
取得載入進度 | 檢查集合的載入進度 | ||
顯示收藏集 | 檢視所有具有收藏權限的收藏集 | ||
列出別名 | 檢視集合的所有別名 | ||
描述收藏集 | 檢視集合的詳細資訊 | ||
描述別名 | 檢視別名的詳細資訊 | ||
取得統計資料 | 取得集合的統計資料(例如集合中的實體數量 | ||
建立集合 | 建立一個集合 | 建立集合 | |
丟棄集合 | 丟棄收藏集 | ||
載入 | 載入集合 | ||
釋放 | 釋放集合 | ||
刷新 | 將集合中的所有實體暫存到封存的區段。任何在 flush 操作之後插入的實體都會儲存在新的區段中。 | ||
壓縮 | 手動觸發壓縮 | ||
重新命名集合 | 重新命名集合 | ||
建立別名 | 為集合建立別名 | ||
刪除別名 | 刪除集合的別名 | ||
全部清除 | 清除資料庫中的所有集合 | ||
分區權限 | 有分割區 | 檢查磁碟分割是否存在 | |
顯示分割區 | 檢視集合中的所有磁碟分割 | ||
建立磁碟分割 | 建立磁碟分割 | ||
丟棄磁碟分割 | 刪除磁碟分割 | ||
索引權限 | 索引詳細資料 | 檢視索引的詳細資料 | |
建立索引 | 建立索引 | ||
刪除索引 | 刪除索引 | ||
資源管理權限 | 負載平衡 | 達成負載平衡 | |
建立資源群組 | 建立資源群組 | ||
丟棄資源群組 | 刪除資源群組 | ||
更新資源群組 | 更新資源群組 | ||
描述資源群組 | 檢視資源群組的詳細資訊 | ||
列出資源群組 | 檢視目前實例的所有資源群組 | ||
轉移節點 | 在資源群組之間轉移節點 | ||
傳送複本 | 在資源群組之間傳輸複本 | ||
備份 RBAC | 為目前實例中所有 RBAC 相關作業建立備份 | 備份 RBAC | |
還原 RBAC | 還原當前實例中所有 RBAC 相關作業的備份 | 還原 RBAC | |
實體權限 | 查詢 | 進行查詢 | |
搜尋 | 進行搜尋 | ||
插入 | 插入實體 | ||
刪除 | 刪除實體 | ||
上移 | 插入實體 | ||
匯入 | 大量插入或匯入實體 | ||
RBAC 權限 | 建立所有權 | 建立使用者或角色 | |
更新使用者 | 更新使用者的密碼 | ||
刪除所有權 | 刪除使用者密碼或角色 | ||
選擇所有權 | 檢視授予特定角色的所有使用者 | ||
管理所有權 | 管理使用者或角色,或授予使用者角色 | ||
選擇使用者 | 檢視授予使用者的所有角色 | ||
建立特權群組 | 建立特權群組 | ||
刪除特權群組 | 刪除特權群組 | ||
列出特權群組 | 檢視目前實例中的所有特權群組 | ||
操作特權群組 | 在特權群組中加入特權或移除特權 |
下面的示例演示了如何在collection_01
上授予預設資料庫下的PrivilegeSearch
特權,以及授予角色role_a
名為privilege_group_1
的特權群組。
from pymilvus import MilvusClient
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
client.grant_privilege_v2(
role_name="role_a",
privilege="Search"
collection_name='collection_01'
db_name='default',
)
client.grant_privilege_v2(
role_name="role_a",
privilege="privilege_group_1"
collection_name='collection_01'
db_name='default',
)
client.grant_privilege_v2(
role_name="role_a",
privilege="ClusterReadOnly"
collection_name='*'
db_name='*',
)
import io.milvus.v2.service.rbac.request.GrantPrivilegeReqV2
client.grantPrivilegeV2(GrantPrivilegeReqV2.builder()
.roleName("role_a")
.privilege("Search")
.collectionName("collection_01")
.dbName("default")
.build());
client.grantPrivilegeV2(GrantPrivilegeReqV2.builder()
.roleName("role_a")
.privilege("privilege_group_1")
.collectionName("collection_01")
.dbName("default")
.build());
client.grantPrivilegeV2(GrantPrivilegeReqV2.builder()
.roleName("role_a")
.privilege("ClusterReadOnly")
.collectionName("*")
.dbName("*")
.build());
import "github.com/milvus-io/milvus-sdk-go/v2/client"
client.GrantV2(context.Background(), "role_a", "collection_01", "Search", entity.WithOperatePrivilegeDatabase("default"))
client.GrantV2(context.Background(), "role_a", "collection_01", "privilege_group_1", entity.WithOperatePrivilegeDatabase("default"))
client.GrantV2(context.Background(), "role_a", "*", "ClusterReadOnly", entity.WithOperatePrivilegeDatabase("*"))
const { MilvusClient, DataType } = require("@zilliz/milvus2-sdk-node")
const address = "http://localhost:19530";
const token = "root:Milvus";
const client = new MilvusClient({address, token});
await milvusClient.grantPrivilege({
roleName: 'role_a',
object: 'Collection',
objectName: 'collection_01',
privilegeName: 'Search'
});
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/grant_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "Search",
"collectionName": "collection_01",
"dbName":"default"
}'
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/grant_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "privilege_group_1",
"collectionName": "collection_01",
"dbName":"default"
}'
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/grant_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "ClusterReadOnly",
"collectionName": "*",
"dbName":"*"
}'
描述角色
下面的示例演示了如何使用 describe_role 方法查看授予角色 role_a 的权限。
from pymilvus import MilvusClient
client.describe_role(role_name="role_a")
import io.milvus.v2.service.rbac.response.DescribeRoleResp;
import io.milvus.v2.service.rbac.request.DescribeRoleReq
DescribeRoleReq describeRoleReq = DescribeRoleReq.builder()
.roleName("role_a")
.build();
DescribeRoleResp resp = client.describeRole(describeRoleReq);
List<DescribeRoleResp.GrantInfo> infos = resp.getGrantInfos();
import "github.com/milvus-io/milvus-sdk-go/v2/client"
client.ListRoles(context.Background())
const { MilvusClient, DataType } = require("@zilliz/milvus2-sdk-node")
await milvusClient.describeRole({roleName: 'role_a'});
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/describe" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a"
}'
以下是一個輸出範例。
{
"role": "role_a",
"privileges": [
{
"collection_name": "collection_01",
"db_name": "default",
"role_name": "role_a",
"privilege": "Search",
"grantor_name": "root"
},
"privilege_group_1"
]
}
撤銷角色的特權或特權群組
以下範例示範如何撤銷collection_01
在預設資料庫下的特權PrivilegeSearch
,以及授予角色role_a
的特權群組privilege_group_1
。
from pymilvus import MilvusClient
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
client.revoke_privilege_v2(
role_name="role_a",
privilege="Search"
collection_name='collection_01'
db_name='default',
)
client.revoke_privilege_v2(
role_name="role_a",
privilege="privilege_group_1"
collection_name='collection_01'
db_name='default',
)
client.revoke_privilege_v2(
role_name="role_a",
privilege="ClusterReadOnly"
collection_name='*'
db_name='*',
)
import io.milvus.v2.service.rbac.request.RevokePrivilegeReqV2
client.revokePrivilegeV2(RevokePrivilegeReqV2.builder()
.roleName("role_a")
.privilege("Search")
.collectionName("collection_01")
.dbName("default")
.build());
client.revokePrivilegeV2(RevokePrivilegeReqV2.builder()
.roleName("role_a")
.privilege("privilege_group_1")
.collectionName("collection_01")
.dbName("default")
.build());
client.revokePrivilegeV2(RevokePrivilegeReqV2.builder()
.roleName("role_a")
.privilege("ClusterReadOnly")
.collectionName("*")
.dbName("*")
.build());
import "github.com/milvus-io/milvus-sdk-go/v2/client"
client.RevokeV2(context.Background(), "role_a", "collection_01", "Search", entity.WithOperatePrivilegeDatabase("default"))
client.RevokeV2(context.Background(), "role_a", "collection_01", "privielge_group_1", entity.WithOperatePrivilegeDatabase("default"))
client.RevokeV2(context.Background(), "role_a", "*", "ClusterReadOnly", entity.WithOperatePrivilegeDatabase("*"))
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/revoke_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "Search",
"collectionName": "collection_01",
"dbName":"default"
}'
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/revoke_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "Search",
"collectionName": "collection_01",
"dbName":"default"
}'
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/roles/revoke_privilege_v2" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"roleName": "role_a",
"privilege": "ClusterReadOnly",
"collectionName": "*",
"dbName":"*"
}'