通过 Python sdk 将所有者添加到 Azure AD 组

Adding Owners to Azure AD Group via Python sdk

我正在尝试创建一个 AD 安全组并向该组添加一个所有者。我在 python 中执行此操作。

我可以创建群组,但无法将所有者添加到群组。我正在使用服务主体来执行此操作。

下面是我的代码

from azure.graphrbac import GraphRbacManagementClient
from azure.common.credentials import ServicePrincipalCredentials
from azure.graphrbac.models import GroupCreateParameters, GroupAddMemberParameters

credentials = ServicePrincipalCredentials(
 client_id="service_principal",
 secret="keyof_service_principal",
 resource="https://graph.windows.net",
 tenant = ''   
    )

 tenant_id = ""
 graphrbac_client = GraphRbacManagementClient(
 credentials,
 tenant_id
    )

 group = GroupCreateParameters(display_name="GroupName", mail_nickname="GroupMail-at-microsoft.com")
 graphrbac_client.groups.create(group)

但是当我尝试执行 add_owner 时,它抛出了一个错误。

graphrbac_client.groups.add_owner(groupId, owner)
Traceback (most recent call last):
File "<stdin>", line 1, in <module> AttributeError: 'GroupsOperations' object has no attribute 'add_owner'
>>> dir(graphrbac_client.groups)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_client', '_deserialize', '_serialize', 'add_member', 'api_version', 'config', 'create', 'delete', 'get', 'get_group_members', 'get_member_groups', 'is_member_of', 'list', 'models', 'remove_member']

我在目录中没有看到 add_owner。

谢谢,

成功了,

我安装了 0.40 版 graphrbac 附带的 azure 模块

$pip freeze | grep rbac
  azure-graphrbac==0.40.0

检查 azure-graphrbac 当前版本为 0.60

我不得不单独卸载 azure-graphrbac 并使用 pip 重新安装当前版本。那解决了问题。

虽然它抛出了与 azure 模块不兼容的错误,但我暂时不认为这是一个问题。

azure 4.0.0 has requirement azure-graphrbac~=0.40.0, but you'll have azure-graphrbac 0.60.0 which is incompatible.