手工修复Azure DevOps无法连接到Azure的问题
點擊上方藍字關注“汪宇杰博客”
今天我在為一個從TFVC遷移到Git的老項目重新配置發布到Azure App Service的CI/CD管線的時候,Azure DevOps竟然爆了。這是一個微軟已知的bug,目前還未修復,我來帶大家看看如何手工workaround這個問題。
首先,部署的時候報錯消息如下:
Failed to get resource ID for resource type 'Microsoft.Web/Sites' and resourcename 'moonglade'. Error: Could not fetch access token for Managed ServicePrincipal. Please configure Managed Service Identity (MSI) for virtual machine'https://aka.ms/azure-msi-docs'.Status code: 400, status message: Bad Request
本質上是因為Azure DevOps到Azure的連接無效,或者過期了。但是當我嘗試重新認證的時候,竟然又爆了:
TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' could not be found.
對此,微軟有個已知bug可以追蹤:https://developercommunity.visualstudio.com/content/problem/412380/tf14045-the-identity-with-type-microsoftidentitymo-1.html
解決方法
進入 Azure Active Directory > App registrations (Preview)
點擊 "+ New registration"
指定一個 Name,如 ediwang-AzureDevOps
選擇 "Accounts in this organizational directory only"
Redirection URL 填: https://VisualStudio/SPN
Description 任意,Expires 建議選 Never
然后把 Client Secrets 里的密鑰復制出來
還有Overview 里的 Application (client) ID 以及 Directory (tenant) ID
然后到 Subscription > Access control (IAM) 里搜索剛才創建的App名字,搜到以后,Add a role assignment
然后安排一個 Owner,Azure這邊就搞定了!
然后回到 Azure DevOps
在 Azure App Service Deploy 的任務里點 Manage?
在 Service Connections 里添加一個 Azure Resource Manager
然后點“use the full version of the service connection dialog.”
選擇和輸入對應的值。其中 Service pricipal client ID 就是剛才復制的 Application (client) ID,Service pricipal key 就是剛才?Client Secrets 里復制的 VALUE
最后點擊 Verify connection,不成功便成仁!
到此為止,就全部搞定了。重新回到你的部署任務里,就能成功選擇目標Azure App Service上的網站了,并且能部署成功。
真是不容易……
總結
以上是生活随笔為你收集整理的手工修复Azure DevOps无法连接到Azure的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【NET CORE微服务一条龙应用】应用
- 下一篇: 如何用EFCore Lazy Loadi