MLflow 身份验证 Python API
mlflow.server.auth.client
- class mlflow.server.auth.client.AuthServiceClient[source]
Bases:
object已启用默认基本身份验证插件的 MLflow 跟踪服务器的客户端。建议使用
mlflow.server.get_app_client()来实例化此类。更多信息请参阅 https://mlflow.org.cn/docs/latest/auth.html。- add_role_permission(role_id: int, resource_type: str, resource_pattern: str, permission: str) mlflow.server.auth.entities.RolePermission[source]
- assign_role(username: str, role_id: int) mlflow.server.auth.entities.UserRoleAssignment[source]
- create_role(workspace: str, name: str, description: Optional[str] = None) mlflow.server.auth.entities.Role[source]
- create_user(username: str, password: str)[source]
创建新用户。
- 参数
username – 用户名。
password – 用户密码。不能为空字符串。
- 引发
mlflow.exceptions.RestException – 如果用户名已被占用。
- 返回
from mlflow.server.auth.client import AuthServiceClient client = AuthServiceClient("tracking_uri") user = client.create_user("newuser", "newpassword") print(f"user_id: {user.id}") print(f"username: {user.username}") print(f"password_hash: {user.password_hash}") print(f"is_admin: {user.is_admin}")
- delete_role(role_id: int) None[source]
- delete_user(username: str)[source]
删除特定用户。
- 参数
username – 用户名。
- 引发
mlflow.exceptions.RestException – 如果用户不存在
from mlflow.server.auth.client import AuthServiceClient client = AuthServiceClient("tracking_uri") client.create_user("newuser", "newpassword") client.delete_user("newuser")
- get_role(role_id: int) mlflow.server.auth.entities.Role[source]
- get_user(username: str)[source]
获取具有特定用户名的用户。
- 参数
username – 用户名。
- 引发
mlflow.exceptions.RestException – 如果用户不存在
- 返回
from mlflow.server.auth.client import AuthServiceClient client = AuthServiceClient("tracking_uri") client.create_user("newuser", "newpassword") user = client.get_user("newuser") print(f"user_id: {user.id}") print(f"username: {user.username}") print(f"password_hash: {user.password_hash}") print(f"is_admin: {user.is_admin}")
- get_user_permission(username: str, resource_type: str, resource_id: str) mlflow.server.auth.entities.GetUserPermissionResult[source]
- grant_user_permission(username: str, resource_type: str, resource_id: str, permission: str) None[source]
- list_all_roles() list[mlflow.server.auth.entities.Role][source]
- list_role_permissions(role_id: int) list[mlflow.server.auth.entities.RolePermission][source]
- list_role_users(role_id: int) list[mlflow.server.auth.entities.UserRoleAssignment][source]
- list_roles(workspace: str) list[mlflow.server.auth.entities.Role][source]
- list_user_roles(username: str) list[mlflow.server.auth.entities.Role][source]
- remove_role_permission(role_permission_id: int) None[source]
- revoke_user_permission(username: str, resource_type: str, resource_id: str) None[source]
- unassign_role(username: str, role_id: int) None[source]
- update_role(role_id: int, name: Optional[str] = None, description: Optional[str] = None) mlflow.server.auth.entities.Role[source]
- update_role_permission(role_permission_id: int, permission: str) mlflow.server.auth.entities.RolePermission[source]
- update_user_admin(username: str, is_admin: bool)[source]
更新特定用户的管理员状态。
- 参数
username – 用户名。
is_admin – 新的管理员状态。
- 引发
mlflow.exceptions.RestException – 如果用户不存在
from mlflow.server.auth.client import AuthServiceClient client = AuthServiceClient("tracking_uri") client.create_user("newuser", "newpassword") client.update_user_admin("newuser", True)
- update_user_password(username: str, password: str, current_password: Optional[str] = None)[source]
更新特定用户的密码。
- 参数
username – 用户名。
password – 新密码。
current_password – 用户当前密码。用户修改自身密码(自助服务)时必填;否则服务器将拒绝请求。管理员修改他人密码时可忽略此参数。
- 引发
mlflow.exceptions.RestException – 如果用户不存在,或者需要
current_password但缺失或不正确。
from mlflow.server.auth.client import AuthServiceClient client = AuthServiceClient("tracking_uri") client.create_user("newuser", "newpassword") # Admin path — no current_password needed. client.update_user_password("newuser", "anotherpassword") # Self-service path — current_password required. client.update_user_password( "newuser", "thirdpassword", current_password="anotherpassword" )
mlflow.server.auth.entities
- class mlflow.server.auth.entities.ExperimentPermission(experiment_id, user_id, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.GatewayEndpointPermission(endpoint_id, user_id, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.GatewayModelDefinitionPermission(model_definition_id, user_id, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.GatewaySecretPermission(secret_id, user_id, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.GetUserPermissionResult(allowed: bool, permission: str)[source]
Bases:
object响应
GET /mlflow/users/permissions/get的数据结构。allowed对应Permission.can_use(常规访问层级);permission是解析后的有效权限名称。- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.RegisteredModelPermission(name, user_id, permission, workspace=None)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.Role(id_, name, workspace, description=None, permissions=None)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.RolePermission(id_, role_id, resource_type, resource_pattern, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.ScorerPermission(experiment_id, scorer_name, user_id, permission)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]
- class mlflow.server.auth.entities.User(id_, username, password_hash, is_admin)[source]
Bases:
object- classmethod from_json(dictionary)[source]
- to_json()[source]