gpt4 book ai didi

powershell - Azure 函数和 Powershell - 无法使用证书登录 AzureRmAccount

转载 作者:行者123 更新时间:2023-12-03 05:55:22 26 4
gpt4 key购买 nike

我正在构建一个 Azure Function(托管在应用服务计划中),它将枚举我的订阅中的 Assets 并使用它们执行某些操作。

我的网站设置方式符合我的预期,但每次登录-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模板后,我按照this Stack Overflow post中的说明上传证书。

考虑到所有准备工作,我希望这能在我的函数中发挥作用:

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 模板来验证他是否使用基于消费的模型。

关于powershell - Azure 函数和 Powershell - 无法使用证书登录 AzureRmAccount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42380511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com