通过Rest API或客户端DLL创建具有'Contributors'类的Azure Devops(安全)组,并具有权限

问题描述 投票:0回答:2

我必须创建具有特定权限的Azure Devops项目级别组。由于团队项目中有多个团队不会互相影响,因此我想创建不同的组,并且不想使用“贡献者”。我设法创建了一个组并检索了该组(身份)。默认权限是(或当然)“未设置”。

获取安全名称空间列表时,可以使用“ QueryAccessControlList”或“ HasPermissions”,但我需要一个字符串令牌和一个IdentityDescriptor列表来获取组的权限。
            var securityNamespaces = securityService.GetSecurityNamespaces();
            foreach (var secns in securityNamespaces)
            {
                secns.QueryAccessControlList(?? string-Token and IdentityDescriptors ?? );
            }

我在哪里可以找到这些参数?

想法是在Web门户中手动配置组,检索设置的权限并将其设置为我的新组。另外,我可以使用tfssecurity.exe。但是/ a +选项需要参数“命名空间令牌操作身份”,我想这是我所缺少的相同“令牌” :-(谁能帮忙?

azure-devops-rest-api
2个回答
2
投票

您可以通过以下REST API创建项目级别的安全组:

POST https://dev.azure.com/{org}/{proId}/_api/_identity/ManageGroup

请求正文:

{"name":"GroupNamehere","description":"Create a Test Group ","tfid":""}

认证使用PAT令牌。

enter image description here

然后您可以使用下面的rest api来设置权限,通过按f12从浏览器中获取此api。

Request URL: https://dev.azure.com/{org}/{proId}/_api/_security/ManagePermissions?__v=5

样品请求正文:

{"updatePackage": "{"IsRemovingIdentity":false,"TeamFoundationId":"be207790-f8ea-4ce0-9bcf-d8b4920c2af7","DescriptorIdentityType":"Microsoft.TeamFoundation.Identity","DescriptorIdentifier":"S-1-9-1551374245-3902060889-2001379654-2338155045-4044170422-1-3881783123-407997253-3219626845-873774695","PermissionSetId":"52d39943-cb85-4d7f-8fa8-c6baac873819","PermissionSetToken":"vstfs:///Classification/TeamProject/59b994e8-4a77-46a1-8b5d-6a25f10d24b6","RefreshIdentities":false,"Updates":[{"PermissionId":1,"PermissionBit":1048576,"NamespaceId":"52d39943-cb85-4d7f-8fa8-c6baac873819","Token":"$PROJECT:vstfs:///Classification/TeamProject/59b994e8-4a77-46a1-8b5d-6a25f10d24b6:"}],"TokenDisplayName":null}"}

Note:请求正文中的"Updates\":[{\"PermissionId\":1,:0表示Not set,1表示Allow,2表示Deny

您还可以参考以下内容:Set version control permissions by REST APIcase1 case2。希望这会有所帮助。


1
投票

休·林斯的答案可能有用,但我并不完全满意。这是一些有用的提示(使用MS DLL和.NET API)。

IGroupSecurityService group_security_service;  // declared deprecated
group_security_service = team_project_collection.GetService<IGroupSecurityService>();
...
// create group
group_security_service.CreateApplicationGroup(prjinfo.Uri, sGroupName, sGroupDescription);
...

我们需要提取组(即贡献者)的权限:

  • 组的IdentityDescriptor
  • 每个使用的安全名称空间的安全令牌

1.IdentityDescriptor

TeamFoundationIdentity tfs_id = identity_management_service.ReadIdentity(IdentitySearchFactor.LocalGroupName,sGroup, MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource);
var desc = tfs_id.Descriptor

2.Token示例在这里:https://docs.microsoft.com/en-us/azure/devops/cli/security_tokens我们必须创建一个字符串,该字符串取决于所使用的安全名称空间。

var securityNamespaces = securityService.GetSecurityNamespaces();

对于每个安全名称空间,令牌的格式各不相同。例如,“项目”名称空间:$PROJECT:vstfs:///Classification/TeamProject/xxxxxxxx-a1de-4bc8-b751-188eea17c3ba'vstfs:///...-Uri来自这里:

prjinfo = common_structure_service4.GetProjectFromName(sTeamProject);
--> prjinfo.Uri

为了调用QueryAccessControlList,我们需要描述符作为数组参数:

IdentityDescriptor[] tfidDescriptors = new IdentityDescriptor[] {desc};

对QueryAccessControlList的调用:

foreach (var secNS in securityNamespaces) 
{
  string sToken = CreateToken(secNS.Description.NamespaceId);
  AccessControlList acl = secNS.QueryAccessControlList(sToken, tfidDescriptors, false);
  foreach (var ace in acl.AccessControlEntries)
  {
     ace.Allow   vs.   ace.Deny  contain bit coded permissions
  }
}

稍后我们可以将权限设置为另一个组。(我们必须将INHERIT和ALLOW / DENY分开)。示例:

...
secNS.RemovePermissions(sToken, desc, inherits);
...
secNS.SetPermissions(sToken, desc, allows, denies, true);

干杯。

© www.soinside.com 2019 - 2024. All rights reserved.