Login-AzureRmAccount -ServicePrincipal 上没有证书错误

No certificate error on Login-AzureRmAccount -ServicePrincipal

我已经使用 ARM 模板自动执行了几个步骤 Java/Tomcat 部署,但我没有通过证书自动登录成功。

我使用 OpenSSL 为虚构域“project.company.com”创建了一个自签名证书。按照本文在 AD 中设置应用程序和具有贡献者角色的服务主体后, https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#provide-certificate-through-automated-powershell-script

我遇到错误

“Login-AzureRmAccount:在证书存储区中找不到带有指纹 xxxxxxxxxxxxxxxxxxx 的证书” 以供关注。

看来我在 Azure 订阅级别上遗漏了一些东西。这些确切的步骤适用于 Linux 框中的 Azure CLI,但不适用于 Windows 框中的 Azure PowerShell。

$cert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @("<my-path>/project.company.pfx", "<my-password>")

#$applicationId="xxxxxxxxxxxxxxxxxxxxx"
#$tenantId="dddddddddddddddddddddd"
#$subscriptionId="yyyyyyyyyyyyyyyyyyy"
#Login-AzureRmAccount -CertificateThumbprint $cert.Thumbprint -ApplicationId $applicationId -ServicePrincipal -TenantId $tenantId

$azureAdApplication = Get-AzureRmADApplication -IdentifierUri "https://project.company.com"
$subscription = Get-AzureRmSubscription
Login-AzureRmAccount -CertificateThumbprint $cert.Thumbprint -ApplicationId $azureAdApplication.ApplicationId -ServicePrincipal -TenantId $subscription.TenantId

为了让 Azure cmdlet 检测到正确的证书,您需要将 public 证书(.cer 文件)安装到受信任的根证书颁发机构存储中。

虽然将证书安装到受信任的根证书颁发机构中是可行的,但这是不可取的,因为它会影响您计算机上的其他应用程序的信任度。相反,将证书安装在 LocalMachine\My 商店或 CurrentUser\My 商店中。