【问题标题】:How to assign group permissions to Azure DevOps Service Connections via API?如何通过 API 将组权限分配给 Azure DevOps 服务连接?
【发布时间】:2020-05-27 20:49:40
【问题描述】:

我通过 terraform Azure DevOps 模块创建服务连接。这很好用,但它们主要是我自己可以访问的,和我手动创建的一样。

我的团队成员也应该能够访问和修改这些服务连接,并且不同团队的成员应该能够查看服务连接。不幸的是,我还没有找到如何通过 azure cli 为服务连接分配特定权限的方法。

到目前为止我做了什么: 我发现很难理解文档(例如https://docs.microsoft.com/en-us/cli/azure/ext/azure-devops/devops/security/permission?view=azure-cli-latest#ext-azure-devops-az-devops-security-permission-update):

  • 我已经用az devops security permission namespace list --organization=https://dev.azure.com/myname 生成了“命名空间”列表。这给了我
  {
    "actions": [
      {
        "bit": 1,
        "displayName": "Use Service Connection",
        "name": "Use",
        "namespaceId": "x-x-x-x"
      },
      {
        "bit": 2,
        "displayName": "Administer Service Connection",
        "name": "Administer",
        "namespaceId": "x-x-x-x"
      },
      {
        "bit": 4,
        "displayName": "Create Service Connection",
        "name": "Create",
        "namespaceId": "x-x-x-x"
      },
      {
        "bit": 8,
        "displayName": "View Authorization",
        "name": "ViewAuthorization",
        "namespaceId": "x-x-x-x"
      },
      {
        "bit": 16,
        "displayName": "View Service Connection",
        "name": "ViewEndpoint",
        "namespaceId": "x-x-x-x"
      }
    ],
    "dataspaceCategory": "Default",
    "displayName": "ServiceEndpoints",
    "elementLength": -1,
    "extensionType": null,
    "isRemotable": false,
    "name": "ServiceEndpoints",
    "namespaceId": "x-x-x-x",
    "readPermission": 0,
    "separatorValue": "/",
    "structureValue": 1,
    "systemBitMask": 0,
    "useTokenTranslator": true,
    "writePermission": 2
  },
  • 我用az devops security group create --name 'Some group name' --description 'Something to describe this group'创建了一个群;这可行,尽管它不是 AAD 组。
  • 我尝试使用az devops security permission update --organization=https://dev.azure.com/myname --id="x-x-x-x" --subject="my.colleague@example.org" 为我的同事添加权限,但它要求我提供令牌作为参数。我在文档中找不到任何关于如何生成令牌的信息,我也不知道它是否真的有帮助,或者这个命令是否适合我的目标。

有什么提示吗?

【问题讨论】:

    标签: azure-devops permissions serviceconnection


    【解决方案1】:

    令牌是代表 Azure DevOps 中资源的任意字符串。令牌格式因资源类型而异,但层次结构和分隔符在所有令牌之间是通用的。

    代币详情可以参考Security tokens for permissions management,上面列出了Token examples for different namespaces

    另一个示例供您参考(参考jessehouwing's blog):

    az login
    
    az extension add --name "azure-devops"
    
    
    
    # Find the group identifier of the group you want to set permissions for
    
    
    
    $org = "gdbc2019-westeurope"
    
    
    
    # There is a weird edge case here when an Azure DevOps Organization has a Team Project with the same name as the org.
    
    # In that case you must also add a query to filter on the right domain property `?@.domain == '?'`  
    
    
    
    $subject = az devops security group list `
    
        --org "https://dev.azure.com/$org/" `
    
        --scope organization `
    
        --subject-types vssgp `
    
        --query "graphGroups[?@.principalName == '[$org]\Project Collection Administrators'].descriptor | [0]"
    
    
    
    $namespaceId = az devops security permission namespace list `
    
        --org "https://dev.azure.com/$org/" `
    
        --query "[?@.name == 'Git Repositories'].namespaceId | [0]"
    
    
    
    $bit = az devops security permission namespace show `
    
        --namespace-id $namespaceId `
    
        --org "https://dev.azure.com/$org/" `
    
        --query "[0].actions[?@.name == 'PullRequestBypassPolicy'].bit | [0]"
    
    
    
    az devops security permission update `
    
        --id $namespaceId `
    
        --subject $subject `
    
        --token "repoV2/" `
    
        --allow-bit $bit `
    
        --merge true `
    
        --org https://dev.azure.com/$org/
    

    此外,您还可以查看类似问题中的步骤:Update permissions for Azure DevOps group for EventSubscription through Azure CLI?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 2020-01-06
      • 2021-01-29
      • 1970-01-01
      • 2019-03-04
      • 2022-01-01
      相关资源
      最近更新 更多