【问题标题】:How to assign a user to an Azure Resource Group如何将用户分配到 Azure 资源组
【发布时间】:2020-06-19 10:38:10
【问题描述】:

我正在尝试创建一个新的资源组、一个新的 Active Directory 用户,然后将该用户作为贡献者分配给资源组。

到目前为止,我已经使用Microsoft.Azure.Management.ResourceManager 成功创建了资源组,并使用Microsoft.Graph 创建了 AD 用户。我可以在 Azure 中看到它们并且可以同时访问它们。

但是,我无法清楚地找到如何在资源管理器或图形 API 中使用 C# 将用户分配到资源组。

我可以在此处查看其他所有操作 > https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal

我认为这是 Graph API 调用 graphClient.DeviceManagement.RoleAssignments 但是,从属性中我无法清楚地看到我将资源组详细信息放在哪里。

这是我在下面的尝试,但出现错误: 请求不适用于目标租户

var roleAssignment = await graphClient.DeviceManagement.RoleAssignments.Request().AddAsync(new DeviceAndAppManagementRoleAssignment
                {
                    DisplayName = "Test Role",
                    Members = new List<string>
                    {
                        createdUser.Id // GUID of new User
                    },
                    ResourceScopes = new List<string>
                    {
                        "/subscriptions/04cbb440-e619-4c8f-869f-8dc4d7dd6e42/resourceGroups/NewResourceGroup" // ID of Resource Group
                    },
                    RoleDefinition = new RoleDefinition
                    {
                        RolePermissions = new List<RolePermission> {

                            new RolePermission {
                                ResourceActions = new List<ResourceAction>
                                {
                                    new ResourceAction {
                                        AllowedResourceActions = new List<string> {"*"},
                                        NotAllowedResourceActions = new List<string>
                                        {
                                            "Microsoft.Authorization/*/Delete",
                                            "Microsoft.Authorization/*/Write",
                                            "Microsoft.Authorization/elevateAccess/Action"
                                        }
                                      }
                                }
                            }
                        }
                    }
                }).ConfigureAwait(false);

有人可以告诉我如何轻松做到这一点或去哪里看吗?

【问题讨论】:

标签: c# azure azure-active-directory azure-resource-manager azure-ad-graph-api


【解决方案1】:

据我所知,我们应该使用Azure management REST API 来管理对Azure 资源的访问。

RBAC Graph API 用于 Intune 需要租户的有效 Intune 许可证。它管理 Intune 中基于角色的访问。

【讨论】:

  • 我正在寻找的是一种通过 SDK 而不是 API 来执行此操作的方法。
猜你喜欢
  • 2021-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
  • 2020-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多