ServicePrincipalAuthentication Classe

Gère l’authentification à l’aide d’un principal de service au lieu d’une identité d’utilisateur.

L’authentification du principal du service est adaptée aux flux de travail automatisés comme pour les scénarios CI/CD. Ce type d’authentification dissocie le processus d’authentification de toute connexion utilisateur spécifique et permet un contrôle d’accès géré.

Constructeur ServicePrincipalAuthentication de classe.

Héritage
ServicePrincipalAuthentication

Constructeur

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

Paramètres

tenant_id
str
Obligatoire

Locataire Active Directory auquel appartient l’identité du service.

service_principal_id
str
Obligatoire

ID du principal du service.

service_principal_password
str
Obligatoire

Mot de passe/clé du principal de service.

cloud
str
valeur par défaut: AzureCloud

Nom du cloud cible. Il peut s’agir de « AzureCloud », « AzureChinaCloud » ou « AzureUSGovernment ». Si aucun cloud n’est spécifié, « AzureCloud » est utilisé.

tenant_id
str
Obligatoire

Locataire Active Directory auquel appartient l’identité du service.

service_principal_id
str
Obligatoire

ID du principal de service.

service_principal_password
str
Obligatoire

Mot de passe/clé du principal de service.

cloud
str
Obligatoire

Nom du cloud cible. Il peut s’agir de « AzureCloud », « AzureChinaCloud » ou « AzureUSGovernment ». Si aucun cloud n’est spécifié, « AzureCloud » est utilisé.

_enable_caching
valeur par défaut: True

Remarques

Pour permettre l’authentification du principal de service, créez une inscription d’application dans Azure Active Directory. Commencez par générer un secret client, puis accordez au principal de service un accès en fonction du rôle à votre espace de travail Machine Learning. Ensuite, vous utilisez la classe ServicePrincipalAuthentication pour gérer votre flux d’authentification.


   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))

Un exemple complet est disponible à l’adresse https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/manage-azureml-service/authentication-in-azureml/authentication-in-azureml.ipynb

Pour en savoir plus sur la création d’un principal de service et autoriser le principal du service à accéder à un espace de travail Machine Learning, consultez Configurer l’authentification du principal de service.