2017-02-13 11 views
0

以下のスクリプトは、自己署名入りの証明書を生成し、パスワード保護されたpfxを作成し、その証明書を鍵保管庫に追加します。 スクリプトの後でARMテンプレートを実行すると、以下のエラーで失敗します。 しかし、UI(Azureポータル)にpfxを手動でアップロードして正しいパスワードを入力すると、ARMテンプレートが正常に展開されます。 これを取得する方法はありますか?キーボルトのAzure証明書がアプリサービスに有効でない

PowerShellのコード(ポータルで生成されたPFXをアップロードするとき、エラーがスローされません):

# Generate the certificate in the local store 
$cert = New-SelfSignedCertificate -CertStoreLocation "cert:\CurrentUser\My" -Subject "CN=$certificateName" -KeyExportPolicy Exportable 

# Get the raw value of the certificate 
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData()) 

Export-PfxCertificate -Cert $cert -Password $certPasswordSecure -FilePath "d:/temp/SelfSigned.pfx" 

$secret = ConvertTo-SecureString -String $keyValue -AsPlainText –Force 
$secretContentType = 'application/x-pkcs12' 

Set-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretNameCertificate -SecretValue $keyValue -ContentType $secretContentType 

エラー:

New-AzureRmResourceGroupDeployment : 21:22:36 - Resource Microsoft.Web/certificates 'testCertificate' failed with message '{ 
    "Code": "BadRequest", 
    "Message": "The parameter KeyVault Certificate has an invalid value.", 
    "Target": null, 
    "Details": [ 
    { 
     "Message": "The parameter KeyVault Certificate has an invalid value." 
    }, 
    { 
     "Code": "BadRequest" 
    }, 
    { 
     "ErrorEntity": { 
     "Code": "BadRequest", 
     "Message": "The parameter KeyVault Certificate has an invalid value.", 
     "ExtendedCode": "51008", 
     "MessageTemplate": "The parameter {0} has an invalid value.", 
     "Parameters": [ 
      "KeyVault Certificate" 
     ], 
     "InnerErrors": null 
     } 
    } 
    ], 
    "Innererror": null 
}' 
At line:3 char:1 
+ New-AzureRmResourceGroupDeployment -Name TestKeyVaultDeploy -Resource ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception 
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet 

New-AzureRmResourceGroupDeployment : 21:23:11 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations 
for details. Please see https://aka.ms/arm-debug for usage details. 
At line:3 char:1 
+ New-AzureRmResourceGroupDeployment -Name TestKeyVaultDeploy -Resource ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception 
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet 

New-AzureRmResourceGroupDeployment : 21:23:11 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations 
for details. Please see https://aka.ms/arm-debug for usage details. 
At line:3 char:1 
+ New-AzureRmResourceGroupDeployment -Name TestKeyVaultDeploy -Resource ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception 
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet 

ARM証明書リソース:

{ 
      "type": "Microsoft.Web/certificates", 
      "name": "testCertificate", 
      "apiVersion": "2016-03-01", 
      "location": "[resourceGroup().location]", 
      "properties": { 
       "keyVaultId": "[parameters('masterKeyVaultId')]", 
       "keyVaultSecretName": "[parameters('servicePrincipalCertSecretName')]", 
       "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('appServicePlanName'))]" 
      } 
     }, 

答えて

0

アップロード時に証明書ポリシーが不足している可能性がありますか? しかし、本当にあなたが新しい証明書を生成しているのであれば、証明書をローカルで生成するのはなぜか、キーボルト自体で生成するだけです。

$credential = Get-Credential 

login-azurermaccount -Credential $credential 
$vaultName = 'my-vault-full-of-keys' 
$certificateName = 'my-new-cert' 
$policy = New-AzureKeyVaultCertificatePolicy -SubjectName "CN=mememe.me" -IssuerName Self -ValidityInMonths 120 
Add-AzureKeyVaultCertificate -VaultName $vaultName -Name $certificateName -CertificatePolicy $policy 
関連する問題