我的Azure应用程序注册/服务主体凭据何时到期?

我的Azure应用程序注册/服务主体凭据何时到期?,azure,azure-powershell,azure-keyvault,Azure,Azure Powershell,Azure Keyvault,为了让我们的Azure Web应用程序能够访问Azure密钥库,我们使用证书和服务主体的应用程序注册 生成证书后,我们使用以下Azure PowerShell创建应用程序注册和服务主体,然后授予服务主体访问Azure密钥库的权限。然后,Web应用程序加载此证书并使用它向Azure Key Vault进行身份验证。一切都很好 $subscriptionId=读取主机-提示'subscriptionId' 选择AzureRmSubscription-SubscriptionId$Subscripti

为了让我们的Azure Web应用程序能够访问Azure密钥库,我们使用证书和服务主体的应用程序注册

生成证书后,我们使用以下Azure PowerShell创建应用程序注册和服务主体,然后授予服务主体访问Azure密钥库的权限。然后,Web应用程序加载此证书并使用它向Azure Key Vault进行身份验证。一切都很好

$subscriptionId=读取主机-提示'subscriptionId'
选择AzureRmSubscription-SubscriptionId$SubscriptionId
$resourceGroupName=读取主机-提示“资源组名称”
$vaultName=读取主机-提示“Vault名称”
$certificateName=读取主机-提示“证书名称”
$applicationName=读取主机-提示“应用程序名称”
$certificatePath=加入路径(获取位置)“$certificateName.cer”
$certificate=新对象System.Security.Cryptography.X509Certificates.X509Certificate2
$certificate.Import($certificatePath)
$rawCertData=[System.Convert]::ToBase64String($certificate.GetRawCertData())
$now=[System.DateTime]::UtcNow
$application=New AzureRmADApplication-DisplayName$applicationName-HomePage“https://$applicationName”-IdentifierURI“https://$applicationName”-CertValue$rawCertData-StartDate$now-EndDate$now.AddYears(1)
$servicePrincipal=New AzureRmADServicePrincipal-ApplicationId$application.ApplicationId
设置AzureRmKeyVaultAccessPolicy-ResourceGroupName$ResourceGroupName-VaultName$VaultName-ServicePrincipalName“https://$applicationName”-PermissionsToSecrets获取
问题在于这一行:

$application=New AzureRmADApplication-DisplayName$applicationName-HomePage“https://$applicationName”-IdentifierURI“https://$applicationName”-CertValue$rawCertData-StartDate$now-EndDate$now.AddYears(1)
它将
StartDate
EndDate
设置为当前日期和当前日期加1年。事后看来,我认为应该是证书的开始和结束日期:

$application=New AzureRmADApplication-DisplayName$applicationName-HomePage“https://$applicationName”-IdentifierURI“https://$applicationName”-CertValue$rawCertData-StartDate`$certificate.NotBefore-EndDate$certificate.NotAfter

我的问题是-在
$now.AddYears(1)
之后会发生什么?
证书的创建期限为3年,但应用程序注册/服务负责人的创建日期为更早的
结束日期
-但这意味着什么?

从文档中,这是凭证的有效结束日期,因此我假设凭证将在该时间停止工作

在此之前,您可以使用新的AzureRmADAppCredential滚动秘密


我尚未测试此方案,但我猜它在1年后将不再接受使用该证书签名的请求。如果您是对的,您得到的错误是
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS70002:验证凭据时出错。AADSTS50012:客户端断言包含无效签名。[原因-使用的密钥已过期,客户端使用的密钥指纹:'xxxxxxx CertificateThumbprintxxxxx',找到的密钥'Start=02/10/2017,End=02/10/2018,Thumbprint=XXXXXXXXX',配置的密钥:[Key0:Start=02/10/2017,End=02/10/2018,Thumbprint=XXXXXXXXX;]
。使用有效期更长的新AzureRmADAppCredential(同一证书)完成了这项工作。