ServicePrincipalAuthentication 类

使用服务主体而不是用户标识管理身份验证。

服务主体身份验证适用于自动化工作流,例如 CI/CD 方案。 这种类型的身份验证将身份验证过程与任何特定的用户登录分离,并允许托管访问控制。

类 ServicePrincipalAuthentication 构造函数。

继承
ServicePrincipalAuthentication

构造函数

ServicePrincipalAuthentication(tenant_id, service_principal_id, service_principal_password, cloud='AzureCloud', _enable_caching=True)

参数

tenant_id
str
必需

服务标识所属的 Active Directory 租户。

service_principal_id
str
必需

服务主体 ID。

service_principal_password
str
必需

服务主体密码/密钥。

cloud
str
默认值: AzureCloud

目标云的名称。 可以是“AzureCloud”、“AzureChinaCloud”或“AzureUSGovernment”之一。 如果未指定云,则使用“AzureCloud”。

tenant_id
str
必需

服务标识所属的 Active Directory 租户。

service_principal_id
str
必需

服务主体 ID。

service_principal_password
str
必需

服务主体密码/密钥。

cloud
str
必需

目标云的名称。 可以是“AzureCloud”、“AzureChinaCloud”或“AzureUSGovernment”之一。 如果未指定云,则使用“AzureCloud”。

_enable_caching
默认值: True

注解

服务主体身份验证涉及到在 Azure Active Directory 中创建应用注册。 首先生成客户端机密,然后为服务主体授予对机器学习工作区的角色访问权限。 然后,使用 ServicePrincipalAuthentication 类来管理身份验证流。


   import os
   from azureml.core.authentication import ServicePrincipalAuthentication

   svc_pr_password = os.environ.get("AZUREML_PASSWORD")

   svc_pr = ServicePrincipalAuthentication(
       tenant_id="my-tenant-id",
       service_principal_id="my-application-id",
       service_principal_password=svc_pr_password)


   ws = Workspace(
       subscription_id="my-subscription-id",
       resource_group="my-ml-rg",
       workspace_name="my-ml-workspace",
       auth=svc_pr
       )

   print("Found workspace {} at location {}".format(ws.name, ws.location))

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/manage-azureml-service/authentication-in-azureml/authentication-in-azureml.ipynb 获取

若要了解如何创建服务主体并允许服务主体访问机器学习工作区,请参阅设置服务主体身份验证