【问题标题】:How to connect-azaccount in Azure DevOps release pipeline如何在 Azure DevOps 发布管道中连接 azaccount
【发布时间】:2019-10-14 11:58:24
【问题描述】:

在发布管道中,我尝试使用 Connect-Azaccount 连接到 Azure AD,因此我可以运行 Get-AzADgroup 来检索一些 Az AD 组名称及其 guid 并输出到变量。

我使用以下内联脚本创建了 Azure Powershell 任务。

(Get-AzADGroup -DisplayName "group-name").origin

【问题讨论】:

  • 如果我的回复有帮助,请标记为答案(在我的回复左侧,有标记选项),谢谢。
  • 嗨,Joy,我还没有尝试过,因为我没有创建 AD 应用程序和服务主体的权限。我会在获得权限后立即更新您。
  • 你也可以使用现有的AD应用,如果你创建一个devops项目,它会自动在你租户的应用注册中创建一个名为organizationname-projectname-513f22f1-befd-xxxxxxcfe90f的AD应用。但您还需要Grant admin consent for xxx 的权限。也许您可以要求您的管理员为您授予 api 权限。:-)
  • 嗨,Joy,我已创建请求让我们的安全团队创建 AD 应用程序。还在等..
  • 嗨,Joy,在 AZ powershell 任务中的 Azure 订阅下,您使用的是服务主体还是托管服务标识服务连接?

标签: azure azure-devops azure-powershell


【解决方案1】:

您似乎需要使用非交互式登录,请按照以下步骤操作。

  1. Create an Azure Active Directory applicationcreate a secret 为应用程序,保存秘密和get values for signing in

  2. 在您的 AD 应用程序中 -> API permissions -> Add a permission -> 选择 Azure Active Directory Graph -> Application permissions -> Directory.Read.All -> 点击 Add permissions -> 点击 Grant admin consent for xxx,请参考截图。

  3. 尝试下面的脚本,使用您在步骤 1 中获得的值,它在我这边工作正常。

    注意:在使用Az powershell 模块时,需要同时使用Task version4.*(preview)

    $azureAplicationId ="<your ad app application id>"
    $azureTenantId= "<your tenant id>"
    $azurePassword = ConvertTo-SecureString "<the secret of your ad app>" -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
    Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 
    #I just test to get all groups, you could do other operations
    Get-AzADGroup 
    

【讨论】:

  • Joy Wang,我已经按照你提到的方法使用了,但是没有登录。检查以下错误:Connect-AzAccount:ClientSecretCredential 身份验证失败:配置问题正在阻止身份验证 - 检查来自服务器的错误消息以获取详细信息。您可以在应用程序注册门户中修改配置。有关详细信息,请参阅aka.ms/msal-net-invalid-client。原始异常:AADSTS7000215:提供的客户端密码无效。
猜你喜欢
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多