將Azure ExpressRoute with Microsoft Peering環境下的Windows VM加入Azure Arc管理清單

將Azure ExpressRoute with Microsoft Peering環境下的Windows VM加入Azure Arc管理清單

我們公司是混合雲架構,採用 Azure ExpressRoute 來進行「地與雲之間安全的連線」,這在此 Blog 提到多次。

ExpressRoute connection overview

從圖來看,Azure ExpressRoute 本身還有兩種選擇,採用 Microsoft Peering 與 Private Peering,差異細節不是這裡的重點,就先跳過。簡單以安全性來說,Microsoft Peering 安全性高於 Private Peering,因此我們選擇 Microsoft Peering 線路架構來實踐。你可以把 Microsoft Peering 想成一個完全黑箱,中間的線路沒有第三者碰得到,而且能存取內容也僅是微軟官方的雲服務(Microsoft 365、Azure Public Service等),A 存取 B 服務,僅此而已,沒了。

前面,我們花了很多功夫進行各類型的 Azure Arc 整合的 PoC。但進入到企業實際內部發現,原本來 PoC 無法實行。以「如何在Azure Arc加入多台地端VM伺服器」為例,它為 Windows 提供的 PowerShell ,我們在跑安裝指令碼的過程是會去下載外部資源。

try {
    # 在此新增服務主體應用程式識別碼及祕密
    $ServicePrincipalId="ServicePrincipalId";
    $ServicePrincipalClientSecret="ServicePrincipalClientSecret";

    $env:SUBSCRIPTION_ID = "SUBSCRIPTION_ID";
    $env:RESOURCE_GROUP = "RESOURCE_GROUP";
    $env:TENANT_ID = "TENANT_ID";
    $env:LOCATION = "LOCATION";
    $env:AUTH_TYPE = "AUTH_TYPE";
    $env:CORRELATION_ID = "CORRELATION_ID";
    $env:CLOUD = "AzureCloud";
    

    [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072;

    # 下載安裝套件
    Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/azcmagent-windows" -TimeoutSec 30 -OutFile "$env:TEMP\install_windows_azcmagent.ps1";

    # 安裝混合式代理程式
    & "$env:TEMP\install_windows_azcmagent.ps1";
    if ($LASTEXITCODE -ne 0) { exit 1; }

    # 執行連線命令
    & "$env:ProgramW6432\AzureConnectedMachineAgent\azcmagent.exe" connect --service-principal-id "$ServicePrincipalId" --service-principal-secret "$ServicePrincipalClientSecret" --resource-group "$env:RESOURCE_GROUP" --tenant-id "$env:TENANT_ID" --location "$env:LOCATION" --subscription-id "$env:SUBSCRIPTION_ID" --cloud "$env:CLOUD" --correlation-id "$env:CORRELATION_ID";
}
catch {
    $logBody = @{subscriptionId="$env:SUBSCRIPTION_ID";resourceGroup="$env:RESOURCE_GROUP";tenantId="$env:TENANT_ID";location="$env:LOCATION";correlationId="$env:CORRELATION_ID";authType="$env:AUTH_TYPE";operation="onboarding";messageType=$_.FullyQualifiedErrorId;message="$_";};
    Invoke-WebRequest -UseBasicParsing -Uri "https://gbl.his.arc.azure.com/log" -Method "PUT" -Body ($logBody | ConvertTo-Json) | out-null;
    Write-Host  -ForegroundColor red $_.Exception;
}

我們用手動執行來還原現場一下:

PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072;

PS C:\> Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/azcmagent-windows" -TimeoutSec 30 -OutFile "$env:TEMP\install_windows_azcmagent.ps1";
Invoke-WebRequest : Unable to connect to the remote server
At line:1 char:1
+ Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/azcmagent-win ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

PS C:\> Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/AzureConnectedMachineAgent" -TimeoutSec 30 -OutFile "$env:TEMP\install_windows_azcmagent.ps1";
Invoke-WebRequest : Unable to connect to the remote server
At line:1 char:1
+ Invoke-WebRequest -UseBasicParsing -Uri "https://aka.ms/AzureConnecte ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

"Unable to connect to the remote server" 說慘也不是慘,這些下載點用 nslookup 反查看似都和 Azure 有關,但在 Microsoft Peering 架構黑箱下,不能連就是不能連。黑箱只有「我和你」,因為接觸不到第三方存取的可能性,因此安全性高,但也造成一些方便性問題。就像這裡,要下載自己 Azure 服務的安裝檔都無法下載。

那要怎麼在 Azure ExpressRoute + Microsoft Peering 架構下導入 Azure Arc 呢?

對不起,就目前 Azure Arc文件 所寫,只能用 Private Peering。我們不死心,跑去問 Azure Arc 支援小組,一開始得到的 Yes,只能用 Private Peering。我們只好去抱怨一下,怎麼更安全的 Microsoft Peering 不能用?早期 Log Analytics agent 是沒有這方面問題的。

Azure Arc針對企業在導入Azure Arc,有一組技術支援小組在協助處理導入問題。但怎麼找到他們,嗯,請洽你們的微軟業務。

支援組又跑去找產品組,一段時間後,終於得到 Microsoft Peering 也支援 Azure Arc 的使用,而是已經上線支援(官網文件未來會更新)。開心是開心,但 Microsoft Peering 本身架構的關係,無法自動化安裝的問題我還是要先解決。

離線安裝Azure Connected Machine Agent

我細細研究官方提供的 PowerShell 指令碼,發現應該手動可以進行離線的安裝與設定。

首先我們下手動下載 https://aka.ms/AzureConnectedMachineAgent 安裝檔,然後複制到伺服器上進行安裝。

手動進行Azure Arc連線設定(2)

官方提供 PowerShell 指令碼裡為我們提供了重要的連線設定方式:

& "$env:ProgramW6432\AzureConnectedMachineAgent\azcmagent.exe" connect --service-principal-id "$ServicePrincipalId" --service-principal-secret "$ServicePrincipalClientSecret" --resource-group "$env:RESOURCE_GROUP" --tenant-id "$env:TENANT_ID" --location "$env:LOCATION" --subscription-id "$env:SUBSCRIPTION_ID" --cloud "$env:CLOUD" --correlation-id "$env:CORRELATION_ID";

參數都正確的話,就能在 Azure ExpressRoute + Microsoft Peering 環境下,手動將 Windows VM 給順利加入 Azure Arc 管理清單中了。

手動進行Azure Arc連線驗證

我們進行第 2 次 PoC 驗證時,出現問題。在同一網路下,不同 Windows 主機上,採用一樣的離線安裝 Agent 與 azcmagent.exe connect 設定時,出現錯誤。並且,原先連線成功的那一台主機,移除 Agent 與重新連線設定,也出現一樣的錯誤。

PS C:\> & "$env:ProgramW6432\AzureConnectedMachineAgent\azcmagent.exe" connect --service-principal-id "$ServicePrincipalId" --service-principal-secret "$ServicePrincipalClientSecret" --resource-group "$env:RESOURCE_GROUP" --tenant-id "$env:TENANT_ID" --location "$env:LOCATION" --subscription-id "$env:SUBSCRIPTION_ID" --cloud "$env:CLOUD" --correlation-id "$env:CORRELATION_ID";
INFO    Connecting machine to Azure... This might take a few minutes.
INFO    Testing connectivity to endpoints that are needed to connect to Azure... This might take a few minutes.
INFO    Exit Code:  AZCM0026: Network Error
INFO    For troubleshooting, see https://aka.ms/arc/azcmerror
FATAL   required endpoints unavailable: https://agentserviceapi.guestconfiguration.azure.com

azcmagent.exe 有提供一些測試命令:

PS C:\> azcmagent.exe check --location "eastasia"
INFO    Testing connectivity to endpoints that are needed to connect to Azure... This might take a few minutes.
ENDPOINT                                              |REACHABLE  |PRIVATE  |TLS      |PROXY
https://agentserviceapi.guestconfiguration.azure.com  |false      |false    |unknown  |not used
https://ea.his.arc.azure.com                          |true       |false    |TLS 1.3  |not used
https://eastasia-gas.guestconfiguration.azure.com     |true       |false    |TLS 1.3  |not used
https://gbl.his.arc.azure.com                         |true       |false    |TLS 1.3  |not used
https://login.microsoftonline.com                     |true       |false    |TLS 1.3  |not used
https://login.windows.net                             |true       |false    |TLS 1.3  |not used
https://management.azure.com                          |true       |false    |TLS 1.3  |not used
https://pas.windows.net                               |true       |false    |TLS 1.2  |not used

跟錯誤訊息是相符合的。我們只能反應給支援組,看要怎麼解決此連線問題。(2024/2/1)

  • 2024/2/22 參考「解決ExpressRoute下agentserviceapi.guestconfiguration.azure.com無法連線造成azcmagent連線失敗」,已解決。

參考:

沒有留言:

張貼留言

感謝您的留言,如果我的文章你喜歡或對你有幫助,按個「讚」或「分享」它,我會很高興的。