Skip to content
MilvusNode SDK
Sections

User & Role Management

Markdown

Copy for agent

This guide covers user and role management, including authentication, authorization, and RBAC operations.

Create a new user:

await client.createUser({
username: 'newuser',
password: 'securepassword',
});

Update user password:

await client.updateUser({
username: 'newuser',
oldPassword: 'securepassword',
newPassword: 'newpassword',
});

Delete a user:

await client.deleteUser({
username: 'newuser',
});

List all users:

const result = await client.listUsers();
console.log('Users:', result.usernames);

Get user information:

const user = await client.describeUser({
username: 'newuser',
});
console.log('User info:', user);

Create a new role:

await client.createRole({
roleName: 'catalog_reader',
});

Delete a role:

await client.dropRole({
roleName: 'catalog_reader',
});

List all roles:

const result = await client.listRoles();
console.log('Roles:', result.results);

Get role information:

const role = await client.describeRole({
roleName: 'catalog_reader',
});
console.log('Role info:', role);

Check if a role exists:

const hasRole = await client.hasRole({
roleName: 'catalog_reader',
});
console.log('Role exists:', hasRole.hasRole);

Assign a user to a role:

await client.addUserToRole({
username: 'newuser',
roleName: 'catalog_reader',
});

Remove a user from a role:

await client.removeUserFromRole({
username: 'newuser',
roleName: 'catalog_reader',
});

Connect as an administrator to a Milvus server with authorization enabled before granting or revoking privileges.

Grant privileges to a role:

import { RbacObjects } from '@zilliz/milvus2-sdk-node';
await client.grantPrivilege({
roleName: 'catalog_reader',
object: RbacObjects.Collection,
objectName: 'my_collection',
privilegeName: 'Load',
});

Revoke privileges from a role:

import { RbacObjects } from '@zilliz/milvus2-sdk-node';
await client.revokePrivilege({
roleName: 'catalog_reader',
object: RbacObjects.Collection,
objectName: 'my_collection',
privilegeName: 'Load',
});

Get granted privileges:

import { RbacObjects } from '@zilliz/milvus2-sdk-node';
const grants = await client.selectGrant({
roleName: 'catalog_reader',
object: RbacObjects.Collection,
objectName: 'my_collection',
});
console.log('Grants:', grants.entities);

List all grants for a role:

const grants = await client.listGrants({
roleName: 'catalog_reader',
});
console.log('Grants:', grants.entities);

Create a privilege group:

await client.createPrivilegeGroup({
group_name: 'readonly_group',
});

Delete a privilege group:

await client.dropPrivilegeGroup({
group_name: 'readonly_group',
});

List all privilege groups:

const groups = await client.listPrivilegeGroups();
console.log(
'Groups:',
groups.privilege_groups.map((group) => group.group_name)
);

Add privileges to a group:

await client.addPrivilegesToGroup({
group_name: 'readonly_group',
privileges: ['DescribeCollection'],
});

Remove privileges from a group:

await client.removePrivilegesFromGroup({
group_name: 'readonly_group',
privileges: ['DescribeCollection'],
});

Grant privileges using RBAC v2:

await client.grantPrivilegeV2({
role: 'catalog_reader',
db_name: 'default',
collection_name: 'my_collection',
privilege: 'Load',
});

Revoke privileges using RBAC v2:

await client.revokePrivilegeV2({
role: 'catalog_reader',
db_name: 'default',
collection_name: 'my_collection',
privilege: 'Load',
});

Backup RBAC configuration:

const backup = await client.backupRBAC();
console.log('Backup:', backup);

Restore RBAC configuration:

await client.restoreRBAC({
RBAC_meta: backup.RBAC_meta,
});

Drop all roles (use with caution):

const results = await client.dropAllRoles();
console.log('Dropped roles:', results);

Supported privilege objects:

  • Collection
  • Global
  • User

Common privilege names:

  • Create
  • Drop
  • Describe
  • Show
  • Load
  • Release
  • Insert
  • Delete
  • Update
  • Search
  • Query
  • Flush
  • Compact
  1. Principle of least privilege: Grant only necessary privileges
  2. Use roles: Group users into roles for easier management
  3. Regular audits: Review user and role assignments regularly
  4. Secure passwords: Enforce strong password policies
  5. Backup RBAC: Regularly backup RBAC configuration