是否可以通过REST API在变量组上设置权限?

时间:2019-09-17 18:24:08

标签: azure-devops-rest-api

我很好奇是否有人知道如何通过REST API为变量组设置权限(添加/删除组)。我知道有安全性名称空间,但是它需要资源guid,而且我不确定如何为特定变量组获取该名称空间?

3 个答案:

答案 0 :(得分:1)

恐怕无法通过api设置变量组权限。

我们只能从下面的变量组api获取组ID,响应中没有资源ID。

 https://dev.azure.com/{organization}/{project}/_apis/distributedtask/variablegroups?api-version=5.1-preview.1

当我尝试使用F12 chrome获取http请求跟踪时。请求网址末尾有一个值,看起来像源ID。它是项目ID与变量组ID的组合。不知道这是否是您正在寻找的资源向导。

https://dev.azure.com/ / _ apis / securityroles / scopes / distributedtask.variablegroup / roleassignments / resources / 39e13f04-cb4e-4fa8-b2f1-0ee8f4fc82c5%241

答案 1 :(得分:1)

您要使用令牌“ Library / $ project_id”将安全名称空间“ Library”(需要convert设置为正确的namespace_id),理论上,您可以将ACL设置为该令牌有效地设置权限来管理您的Ado项目中的变量组(例如,创建新的变量组)

POST https://dev.azure.com/{organization}/_apis/accesscontrollists/{securityNamespaceId}?api-version=5.1

有关ACL管理REST API,请参见https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20lists/set%20access%20control%20lists?view=azure-devops-rest-5.1

示例请求:

"value": [
    {
      "inheritPermissions": true,
      "token": "Library/$project_id",
      "acesDictionary": {
        "Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1204400969-2402986413-2179408616-0-0-0-0-1": {
          "descriptor": "Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1204400969-2402986413-2179408616-0-0-0-0-1",
          "allow": 31,
          "deny": 0
        }
      }
    }
]

我之所以说“理论上”,是因为目前有关该主题的Microsoft文档还很不完整(例如,请参阅我在github问题上的comment,要求澄清变量组身份验证机制)。

警告-请谨慎处理ACL更改请求,因为您最终可能会删除Ado项目上所有用户的权限,并且很难将其更改回去。

答案 2 :(得分:0)

我设法逆向执行此操作的工程师。如果有人对它的工作方式感到好奇,请随意查看我整理的Azure DevOps的Powershell库-https://github.com/ravensorb/Posh-AzureDevOps