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

问题描述 投票:0回答:1

为了使我们的Azure Web Apps可以访问Azure Key Vault,我们将证书和应用程序注册与服务主体一起使用。

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

$subscriptionId = Read-Host -Prompt 'SubscriptionId'
Select-AzureRmSubscription -SubscriptionId $subscriptionId
$resourceGroupName = Read-Host -Prompt 'Resource group name'
$vaultName = Read-Host -Prompt 'Vault name'
$certificateName = Read-Host -Prompt 'Certificate name'
$applicationName = Read-Host -Prompt 'Application name'

$certificatePath = Join-Path (Get-Location) "$certificateName.cer"
$certificate = New-Object 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" -IdentifierUris "https://$applicationName" -CertValue $rawCertData -StartDate $now -EndDate $now.AddYears(1)

$servicePrincipal = New-AzureRmADServicePrincipal -ApplicationId $application.ApplicationId

Set-AzureRmKeyVaultAccessPolicy -ResourceGroupName $resourceGroupName -VaultName $vaultName -ServicePrincipalName "https://$applicationName" -PermissionsToSecrets get

问题是这一行:

$application = New-AzureRmADApplication -DisplayName $applicationName -HomePage "https://$applicationName" -IdentifierUris "https://$applicationName" -CertValue $rawCertData -StartDate $now -EndDate $now.AddYears(1)

它将StartDateEndDate设置为当前日期和当前日期加1年。事后我认为它应该是证书的开始和结束日期:

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

我的问题是 - 在$now.AddYears(1)之后会发生什么?证书创建时间为3年,但申请注册/服务委托人是使用较早的EndDate创建的 - 但这意味着什么?

azure azure-powershell azure-keyvault
1个回答
1
投票

从文档中,它是凭证的有效结束日期,因此我认为凭证将在那时停止工作。

https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermadapplication?view=azurermps-5.1.1

您可以使用New-AzureRmADAppCredential在此之前滚动密码。

https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermadappcredential?view=azurermps-5.1.1

© www.soinside.com 2019 - 2024. All rights reserved.