Create service principal programmatically in Azure Python API

后端 未结 1 1653
刺人心
刺人心 2020-12-20 06:39

How can I, using the Azure Python API, create a full set of credentials that can later be used to start and deallocate all VMs in a named resource group, without any other

相关标签:
1条回答
  • 2020-12-20 07:06

    Your need the azure-graphrbac package to create a Service Principal:

    • https://docs.microsoft.com/python/api/overview/azure/activedirectory

    The closer to a sample might be this unittest:

    • https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/graphrbac/azure-graphrbac/tests/test_graphrbac.py

    For role and permissions, you need azure-mgmt-authorization:

    • https://docs.microsoft.com/python/api/overview/azure/authorization

    Best sample for this one, is probably the sub-part of this sample:

    • https://github.com/Azure-Samples/compute-python-msi-vm#role-assignement-to-the-msi-credentials

    "msi_identity" is a synonym of "service principal" in your context.

    Note that all of this is supported by the CLI v2.0:

    • https://docs.microsoft.com/cli/azure/ad/sp
    • https://docs.microsoft.com/cli/azure/role/assignment

    It might be interested to test the CLI in --debug mode and sniffing in the code repo at the same time:

    • https://github.com/Azure/azure-cli

    (full disclosure, I work at MS in the Azure SDK for Python team)

    0 讨论(0)
提交回复
热议问题