2017-12-19 9 views
0

Azure Web AppsがAzure Key Vaultにアクセスできるように、私たちはサービス主体の証明書とアプリケーション登録を使用します。私のAzureアプリケーションの登録/サービスプリンシパルクレデンシャルはいつ期限切れになりますか?

証明書を生成した後、次のAzure PowerShellを使用してアプリケーション登録とサービスプリンシパルを作成し、サービスプリンシパルにAzure Key Vaultへのアクセス権を与えます。 Webアプリケーションはこの証明書をロードし、それを使って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) 

それは、現在の日付と現在の日付と1年にStartDateEndDateを設定します。後知恵で私はそれが証明書の開始日と終了日となっているべきだと思う:

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

私の質問がある - $now.AddYears(1)後に何が起こりますか?証明書は3年間有効期限が切れて作成されましたが、アプリケーション登録/サービスプリンシパルは先にEndDateで作成されましたが、それはどういう意味ですか?

+2

私はこのシナリオをテストしていませんが、私は*推測*それはもう1年後にその証明書で署名要求を受け付けませんでしょう。 – juunas

答えて

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

+0

あなたが正しいとしたら、エラーは 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:AADSTS70002:認証情報の検証中にエラーが発生しました。 AADSTS50012:クライアントのアサーションに無効なシグネチャが含まれています。 [理由 - 使用されたキーは期限切れです。クライアントで使用されているキーのサムプリント: 'XXXXXXXCERTIFICATETHUMBPRINTXXXXX'、Foundキー 'Start = 02/10/2017、End = 02/10/2018、Thumbprint = XXXXXXXXX'、設定されたキー:[Key0 :開始= 02/10/2017、終了= 02/10/2018、サムプリント= XXXXXXXXXX;]] '。より長い期限(同じ証明書)を持つ 'New-AzureRmADAppCredential'を使用すると、そのジョブが実行されました。 – tjrobinson

関連する問題