添加和管理安全组

Azure DevOps Services

安全组用于管理权限和访问权限,如 权限、访问权限和安全组入门。 例如,为参与者组或项目管理员组的成员分配了这些组允许的权限。

Azure DevOps 预配置了默认安全组。 可以使用 az devops 安全组 命令为组织或项目添加和管理安全组。 使用此命令执行以下任务。

  • 创建新的安全组
  • 查看安全组和安全组详细信息
  • 更新或删除安全组
  • 管理组和用户的安全组成员身份

Note

本文仅适用于 Azure DevOps Services。 For Azure DevOps Server, you can manage security groups using the TFSSecurity command.

Prerequisites

Category Requirements
Permissions 项目集合管理员组的成员。 组织所有者是此组的自动成员。 有关令牌的详细信息,请参阅 安全命名空间和权限参考
Tools Azure DevOps CLI 扩展。 使用 az login登录。

安全组命令

Command Description
az devops security group create 创建 Azure DevOps 安全组。
az devops security group delete 删除 Azure DevOps 安全组。
az devops security group list 列出项目或组织中的所有组。
az devops security group show 显示组详细信息。
az devops security group update 更新安全组的名称和说明。
az devops security group membership add 将成员添加到安全组。
az devops security group membership list 列出组或用户的成员身份。
az devops security group membership remove 从安全组中删除成员。

对于所有命令,以下参数是可选的,本文中提供的示例中未列出。

  • detect: Automatically detect organization. 接受的值:false、true。 默认值为 true。
  • org: Azure DevOps organization URL. 可以使用 az devops configure -d organization=ORG_URL 配置默认组织。 如果未配置为默认或通过 git 配置选取,则为必需。示例:--org https://dev.azure.com/MyOrganizationName/

创建安全组

可以使用 az devops 安全组 create 命令创建安全组。

az devops security group create [--description]
                                [--email-id]
                                [--groups]
                                [--name]
                                [--origin-id]
                                [--project]
                                [--scope {organization, project}]

Optional parameters

  • description: Description of the new security group.
  • email-id: Create new group using the email address as a reference to an existing group from a Microsoft Entra backed provider. Required if name or origin-id is missing.
  • groups: A comma-separated list of descriptors referencing groups you want the newly created group to join.
  • name: Name of the new security group. Required if origin-id or email-id is missing.
  • origin-id: Create new group using the OriginID as a reference to an existing group from a Microsoft Entra backed provider. Required if name or email-id is missing.
  • project: Name or ID of the project in which the group should be created.
  • scope: Create group at project or organization level. Accepted values are organization and project (default).

Example

The following command creates the Account Management security group in the project MyFirstProject and shows the result in table format.

az devops security group create --name "Account Management" --project MyFirstProject --description "Management team focused on creating and maintaining customer services" --output table

Name                                 Description
-----------------------------------  ---------------------------------------------------------------------
[MyFirstProject]\Account Management  Management team focused on creating and maintaining customer services

删除安全组

可以使用 az devops 安全组 delete 命令删除安全组。

az devops security group delete --id
                                [--yes]

Parameters

  • id: Required. 安全组描述符。 若要获取描述符,请使用 az devops 安全组列表 命令。
  • yes: Optional. 不要提示确认。

Example

以下命令将删除具有指定描述符的安全组,并且不会提示进行确认。

az devops security group delete --id vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMC0wLTAtMC0x --yes

列出安全组

可以使用 az devops 安全组 list 命令列出项目或组织中的所有安全组。

az devops security group list [--continuation-token]
                              [--project]
                              [--scope {organization, project}]
                              [--subject-types]

Optional parameters

  • continuation-token: If there are more results that can't be returned in a single page, the result set will contain a continuation token for retrieval of the next set of results.
  • project: List groups for a particular project.
  • scope: List the groups at project or organization level. Accepted values are organization and project (default).
  • subject-types: A comma-separated list of user subject subtypes to reduce the retrieved results. 可以将描述符的初始部分(在点前)作为筛选器,例如 vssgp,aadgp。

Example

The following command lists the name and descriptor for all security groups in MyFirstProject, and shows the results in table format.

az devops security group list --project MyFirstProject --output table

Name                                     Descriptor
---------------------------------------  --------------------------------------------------------------------------------------------------------------------------------------------------
[MyFirstProject]\Contributors            vssgp.Uy0xLTktMTU1MTM3NDI0NS0zMjgyMTE0Mzg4LTcyMDc3NjM2LTI5MzA1OTM5MTEtMTI2ODYyOTM0My0xLTE0MzUxMDc1MzctMzkwMDAzNTkwNS0zMTk5MDU1NDY1LTM4MDE2ODQ3MzM
[MyFirstProject]\Project Valid Users     vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMC0wLTAtMC0z
[MyFirstProject]\Account Management      vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMS0zNDU1MDI4NTE4LTI5Nzg5OTAxNTYtMjI4OTU2NzYyOS0xOTM2NDU3NTYw
[MyFirstProject]\Project Team            vssgp.Uy0xLTktMTU1MTM3NDI0NS0zMjgyMTE0Mzg4LTcyMDc3NjM2LTI5MzA1OTM5MTEtMTI2ODYyOTM0My0xLTM0OTQwNjM0ODktMjg4NDE3MTA4Mi0yMjkxMTIwNTYwLTM3NDc2NDkyNA
[MyFirstProject]\Readers                 vssgp.Uy0xLTktMTU1MTM3NDI0NS0zMjgyMTE0Mzg4LTcyMDc3NjM2LTI5MzA1OTM5MTEtMTI2ODYyOTM0My0xLTQ0MzQzMTA1My0yMTcyODUzNTc2LTI1MjY0NzgwNjMtMzY1NjU0NjczNQ
[MyFirstProject]\Account Administrators  vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMS02NTAxNzIxNjctMzk4MTU5MTEwNC0zMjE1MTIzNjI0LTEyMTMyOTQwNQ
[MyFirstProject]\Project Administrators  vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMC0wLTAtMC0x
[MyFirstProject]\Build Administrators    vssgp.Uy0xLTktMTU1MTM3NDI0NS0zMjgyMTE0Mzg4LTcyMDc3NjM2LTI5MzA1OTM5MTEtMTI2ODYyOTM0My0xLTI0MDEzNTE5NjItMzM2NTg2MzA5LTI2Mzg2ODkzMDktMzk5NTQ3OTU3MQ

显示安全组详细信息

可以使用 az devops 安全组 show 命令显示安全组的详细信息。

az devops security group show --id

Parameters

  • id: Required. 安全组描述符。

Example

以下命令以表格式显示 项目有效用户 安全组的详细信息。

az devops security group show --id vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMC0wLTAtMC0z --output table

Name                                  Description
------------------------------------  ------------------------------------------------------
[MyFirstProject]\Project Valid Users  Members of this group have access to the team project.

更新安全组

可以使用 az devops 安全组 update 命令更新安全组的名称和说明。

az devops security group update --id
                                [--description]
                                [--name]

Parameters

  • id: Required. 安全组描述符。
  • description: Optional. 安全组的新说明。 Required if name is missing.
  • name: Optional. 安全组的新名称。 Required if description is missing.

Example

以下命令使用指定的描述符更改安全组的名称,并使用 YAML 格式显示结果。

az devops security group update --id vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMS0zNDU1MDI4NTE4LTI5Nzg5OTAxNTYtMjI4OTU2NzYyOS0xOTM2NDU3NTYw --name "Management Team" --output yaml

description: Management team focused on creating and maintaining customer services
descriptor: vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMS0zNDU1MDI4NTE4LTI5Nzg5OTAxNTYtMjI4OTU2NzYyOS0xOTM2NDU3NTYw
displayName: Management Team
domain: vstfs:///Classification/TeamProject/5417a1c3-4b04-44d1-aead-50774b9dbf5f
isCrossProject: null
isDeleted: null
isGlobalScope: null
isRestrictedVisible: null
legacyDescriptor: null
localScopeId: null
mailAddress: null
origin: vsts
originId: 8fe47a49-bfab-4356-9a85-90c5e62110be
principalName: '[MyFirstProject]\Management Team'
scopeId: null
scopeName: null
scopeType: null
securingHostId: null
specialType: null
subjectKind: group
url: https://vssps.dev.azure.com/fabrikam/_apis/Graph/Groups/vssgp.Uy0xLTktMTU1MTM3NDI0NS0xODI5NDgwMzA1LTEzNjM2MTczNTEtMjI0NzE1OTUyMC03ODEzNDk2MjItMS0zNDU1MDI4NTE4LTI5Nzg5OTAxNTYtMjI4OTU2NzYyOS0xOTM2NDU3NTYw

将成员添加到组

可以使用 az devops 安全组成员身份添加 命令将成员添加到安全组。

az devops security group membership add --group-id
                                        --member-id

Parameters

  • group-id: Required. 要向其添加成员的组的描述符。
  • member-id: Required. 要添加的用户的组或电子邮件地址的描述符。

Example

以下命令将用户 contoso@contoso.com 添加到指定的安全组,并按表格式显示结果。

az devops security group membership add --group-id vssgp.Uy0xLTktMTU1MTM3NDI0NS0yMjc3MTY5NTAtOTkzNjA1MTg2LTI1ODQxNTkyOTktMjYzMDUyNzA2OC0xLTQxNDY0Mzc4MzktMzgxMDM2MDM5MS0yNjE0MjU5MzI3LTI5MjI2MTc3OTA --member-id contoso@contoso.com --output table

Name                                 Type    Email
-----------------------------------  ------  -------------------
[MyFirstProject]\Account Management  group
contoso@contoso.com                  user    contoso@contoso.com

列出组或用户的成员身份

可以使用 az devops 安全组成员身份列表 命令列出组或用户的成员身份。

az devops security group membership list --id
                                         [--relationship {memberof, members}]

Parameters

  • id: Required. 需要其成员身份详细信息的安全组描述符或用户电子邮件地址。
  • relationship: Optional. Get member of or members information for the group. The accepted values are memberof and members.

Examples

以下命令列出指定安全组的成员,并按表格式显示结果。

az devops security group membership list --id vssgp.Uy0xLTktMTU1MTM3NDI0NS0yMjc3MTY5NTAtOTkzNjA1MTg2LTI1ODQxNTkyOTktMjYzMDUyNzA2OC0xLTQxNDY0Mzc4MzktMzgxMDM2MDM5MS0yNjE0MjU5MzI3LTI5MjI2MTc3OTA --output table

Name                 Type    Email                Descriptor
-------------------  ------  -------------------  ----------------------------------------------------
contoso@contoso.com  user    contoso@contoso.com  msa.NDMzMmNjOWYtYzY4Zi03YTNlLTk2ZTktYmYwM2U4NjgxOTRh

下面是列出 Fabrikam Fiber 项目的 EMail 团队成员的另一个示例。

az devops security group membership list --id "[Fabrikam Fiber]\Email" --output table
Name               Type    Email                       Descriptor
-----------------  ------  --------------------------  ----------------------------------------------------
Christie Church    user    fabrikamfiber1@hotmail.com  msa.OThjODMzM2ItMmI4Ny03YTkwLThmZGItYWQwYmQ1YWE4MzJk
Raisa Pokrovskaya  user    fabrikamfiber5@hotmail.com  msa.ZmUwYjk5NmYtZTAyNS03NzBkLTgxNmYtMzk1NDQwYzViMzgw

从组中删除成员

可以使用 az devops 安全组成员身份删除 命令从安全组中删除成员。

az devops security group membership remove --group-id
                                           --member-id
                                           [--yes]

Parameters

  • group-id: Required. 需要从中删除成员的组的描述符。
  • member-id: Required. 要删除的用户的组或电子邮件地址的描述符。
  • yes: Optional. 不要提示确认。

Example

以下命令从指定的安全组中删除用户 contoso@contoso.com,而无需提示确认。

az devops security group membership remove --group-id vssgp.Uy0xLTktMTU1MTM3NDI0NS0yMjc3MTY5NTAtOTkzNjA1MTg2LTI1ODQxNTkyOTktMjYzMDUyNzA2OC0xLTQxNDY0Mzc4MzktMzgxMDM2MDM5MS0yNjE0MjU5MzI3LTI5MjI2MTc3OTA --member-id contoso@contoso.com --yes