Как вставить сертификат pfx с паролем в учетную запись автоматизации с ARM - PullRequest
1 голос
/ 14 июня 2019

Я хотел бы отправить ARM сертификат pfx с паролем в учетной записи автоматизации

{
    "type": "certificates",
    "apiVersion": "2015-10-31",
    "name": "AzureRunAsCertificate",
    "location": "[resourceGroup().location]",
    "dependsOn": ["[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"],
    "properties": {
        "base64Value": "MIII4QIBAzCCCKcGCSqGSIb3..........kdHQQIXbFXVHGs6qACAggA",
        "isExportable": true,
        "thumbprint": "5FF426ABD6D26E592783944A9A3FF5EF80A9045C"
     }
},

У меня ошибка запроса, когда я пытаюсь

Microsoft.Automation / automationAccounts / сертификаты InternalServerError Подробности операции

Имеете ли вы представление о синтаксисе для указания пароля?

1 Ответ

0 голосов
/ 15 июня 2019

Вот пример из документации:

$AutomationAccountName = "<automation account name>"
$PfxCertPath = '<PFX cert path'
$CertificatePassword = '<password>'
$certificateName = '<certificate name>'
$AutomationAccountName = '<automation account name>'
$flags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable `
    -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet `
    -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet
# Load the certificate into memory
$PfxCert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($PfxCertPath, $CertificatePassword, $flags)
# Export the certificate and convert into base 64 string
$Base64Value = [System.Convert]::ToBase64String($PfxCert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12))
$Thumbprint = $PfxCert.Thumbprint


$json = @"
{
    '`$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#',
    'contentVersion': '1.0.0.0',
    'resources': [
        {
            'name': '$AutomationAccountName/$certificateName',
            'type': 'Microsoft.Automation/automationAccounts/certificates',
            'apiVersion': '2015-10-31',
            'properties': {
                'base64Value': '$Base64Value',
                'thumbprint': '$Thumbprint',
                'isExportable': true
            }
        }
    ]
}
"@

$json | out-file .\template.json
New-AzureRmResourceGroupDeployment -Name NewCert -ResourceGroupName TestAzureAuto -TemplateFile .\template.json

в основном вам нужно экспортировать его с паролем, используя System.Security.Cryptography:

# Load the certificate into memory
$PfxCert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($PfxCertPath, $CertificatePassword, $flags)
# Export the certificate and convert into base 64 string
$Base64Value = [System.Convert]::ToBase64String($PfxCert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12))

и затем вы можете передать его в шаблон base64Value свойство

https://docs.microsoft.com/en-us/azure/automation/shared-resources/certificates#creating-a-new-certificate

...