Azure 函数和 Powershell - 无法使用证书登录 AzureRmAccount
Azure functions & Powershell - unable to Login-AzureRmAccount using certificate
我正在构建一个 Azure 函数(托管在应用服务计划中),它将枚举我的订阅中的资产并对它们进行处理。
我已按照我希望它正常运行的方式设置网站,但 Login-AzureRmAccount 每次都出现错误并显示通知
Login-AzureRmAccount : No certificate was found in the certificate store with thumbprint xxxxxxxx
以下是一些相关的文章:
首先我创建证书:
$cert = New-SelfSignedCertificate -CertStoreLocation cert:\currentuser\my -Subject "cn=$appCommonName" ...etc...
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())
$aNewApp = New-AzureRmADApplication -DisplayName $AzureADApplicationName -HomePage $AppHomePage -IdentifierUris $appIDUri -CertValue $keyValue -EndDate $cert.NotAfter -StartDate $cert.NotBefore
#export the cert for use future upload to Azure
$password = ConvertTo-SecureString -String "supersecrettpassword" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath "Export-cert.pfx" -Password $password
Export-Certificate -Type CERT -Cert $cert -FilePath "Export-cert.cer"
稍后我提供我的服务委托人并授予它读取权限
$theSvcPrincipal = New-AzureRmADServicePrincipal -ApplicationId $ApplicationId
$testRole = Get-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName $ApplicationId
通过 ARM 部署的魔力,我在托管 azure 函数的网站上得到了两个应用程序设置:WEBSITE_LOAD_CERTIFICATES
值为 * 和 CertThumbprint
值为指纹我上传到 SSL certificates
区域的证书。
最后,部署ARM模板后,我按照
的说明上传证书
考虑到所有这些准备工作,我希望这能在我的职能中发挥作用:
Login-AzureRmAccount -ServicePrincipal -CertificateThumbprint $env:CertThumbprint -ApplicationId $env:ApplicationId -TenantId $env:TenantId
但是当该行执行时,尽管我在网站上有一个带有匹配指纹的证书,但我得到了 no cert found wiht matching thumbprint
错误。
好吧,这有点尴尬。事实证明,我用来配置应用服务的 ARM 模板使用的是动态 sku:
"properties": {
"name": "[parameters('hostingPlanName')]",
"computeMode": "Dynamic",
"sku": "Dynamic"
}
而不是标准 sku:
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
切换两者后,我就可以访问证书存储区了。
我曾见过 this issue discussed on github,但当一位同事在使用 Azure Web 界面进行预配后能够从托管在动态计划上的函数应用程序访问客户端证书时,我忽略了它。我仍然无法解释他是如何做到的,但我亲眼看到了它,并从他的部署中倾注了 ARM 模板来验证他使用的是基于消费的模型。
我正在构建一个 Azure 函数(托管在应用服务计划中),它将枚举我的订阅中的资产并对它们进行处理。
我已按照我希望它正常运行的方式设置网站,但 Login-AzureRmAccount 每次都出现错误并显示通知
Login-AzureRmAccount : No certificate was found in the certificate store with thumbprint xxxxxxxx
以下是一些相关的文章:
首先我创建证书:
$cert = New-SelfSignedCertificate -CertStoreLocation cert:\currentuser\my -Subject "cn=$appCommonName" ...etc...
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())
$aNewApp = New-AzureRmADApplication -DisplayName $AzureADApplicationName -HomePage $AppHomePage -IdentifierUris $appIDUri -CertValue $keyValue -EndDate $cert.NotAfter -StartDate $cert.NotBefore
#export the cert for use future upload to Azure
$password = ConvertTo-SecureString -String "supersecrettpassword" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath "Export-cert.pfx" -Password $password
Export-Certificate -Type CERT -Cert $cert -FilePath "Export-cert.cer"
稍后我提供我的服务委托人并授予它读取权限
$theSvcPrincipal = New-AzureRmADServicePrincipal -ApplicationId $ApplicationId
$testRole = Get-AzureRmRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName $ApplicationId
通过 ARM 部署的魔力,我在托管 azure 函数的网站上得到了两个应用程序设置:WEBSITE_LOAD_CERTIFICATES
值为 * 和 CertThumbprint
值为指纹我上传到 SSL certificates
区域的证书。
最后,部署ARM模板后,我按照
考虑到所有这些准备工作,我希望这能在我的职能中发挥作用:
Login-AzureRmAccount -ServicePrincipal -CertificateThumbprint $env:CertThumbprint -ApplicationId $env:ApplicationId -TenantId $env:TenantId
但是当该行执行时,尽管我在网站上有一个带有匹配指纹的证书,但我得到了 no cert found wiht matching thumbprint
错误。
好吧,这有点尴尬。事实证明,我用来配置应用服务的 ARM 模板使用的是动态 sku:
"properties": {
"name": "[parameters('hostingPlanName')]",
"computeMode": "Dynamic",
"sku": "Dynamic"
}
而不是标准 sku:
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
切换两者后,我就可以访问证书存储区了。
我曾见过 this issue discussed on github,但当一位同事在使用 Azure Web 界面进行预配后能够从托管在动态计划上的函数应用程序访问客户端证书时,我忽略了它。我仍然无法解释他是如何做到的,但我亲眼看到了它,并从他的部署中倾注了 ARM 模板来验证他使用的是基于消费的模型。