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

Is it possible to set permissions on variable groups via the REST API?

我很好奇是否有人知道如何通过 REST API 为变量组设置权限(add/remove 组)。我知道有安全命名空间,但它需要资源 GUID,我不确定如何为特定变量组获取它?

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

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

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

当我尝试使用 F12 chrome 获取 http 请求跟踪时。请求末尾有一个值 url 看起来像源 ID。它是项目 ID 与变量组 ID 的组合。不知道这是否是您要查找的资源 guid。

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

我设法逆向工程谁来做这件事。如果有人对它的工作原理感到好奇,请随时谈谈我为 Azure DevOps 整理的 powershell 库 -- https://github.com/ravensorb/Posh-AzureDevOps

你想要安全 namespace "Library"(你需要 convert 它来正确 namespace_id )和 token "Library/$project_id/VariableGroup/$variable_group_id"

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/VariableGroup/$variable_group_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
        }
      }
    }
]

警告 1 - 目前关于该主题的 Microsoft 文档还很不完整(例如,参见我的 comment 关于 github 的问题,要求澄清变量组身份验证机制)。

警告 2 - 小心更改项目中所有变量组的 ACL 请求(例如 token=Library/$project_id/ ),因为您最终可能会删除 Ado 项目中所有用户的权限,这可能很难将其改回。