使用Azure自动化在{DSC}中正确保护凭证

时间:2016-10-12 08:33:02

标签: powershell azure dsc

您将如何继续保护在Azure自动化中正确使用凭据的DSC配置?

例如:

configuration MyServer {
  param(
    [Parameter(Mandatory=$true)][PSCredential]$MyCredential
  );
  # Some configuration using credentials 
}

通常我会在每个节点上设置公钥和适当的证书,并在编译配置文档时将CertificateFile和Thumbprint传递给ConfigurationData。

在Azure自动化中,我找不到任何好的解决方案。

文档说Azure自动化由它自己加密整个MOF:https://azure.microsoft.com/en-us/documentation/articles/automation-certificates/,文章指定使用PSAllowPlainTextCredentials。

当您将节点注册到它的拉服务器并拉动它的配置时,只要您具有本地管理员权限或读取访问权限,您就可以以纯文本形式读出密码。被拉下/更新。从安全角度来看,这是好的。

我最喜欢的是,理想情况下,将此类公钥/证书上传到Azure自动化凭据,并在启动编译作业时将其用作ConfigurationData的一部分。

然而今天," CertificateFile"期望路径而不是AutomationCertificate,因此我看不到使用Azure自动化中存在的任何公钥启动compilationjob的方法。在运行这份工作时,我无法看到任何引用我的资产证书的方法。

如果可以在Azure自动化的当前状态下使用DSC /使用资源商店使用Azure自动化或Azure密钥保管库来正确保护它的方式,那么是否有任何想法?

3 个答案:

答案 0 :(得分:1)

您应该创建Azure自动化凭据并在配置中引用它,如下所示:

# Compile mof
$ConfigurationData = @{ 
    AllNodes = @(
        @{
            NodeName = $nodeName
            PSDscAllowPlainTextPassword = $true
        }
    )
}

$Parameters = @{
    "nodeName" = $nodeName
    "credential" = $credName ##### Notice this is only the name on Azure Automation Credential Asset, Azure Automation will securely pull those and use in the compilation
}

Start-AzureRmAutomationDscCompilationJob -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName `
    -ConfigurationName $configurationName -Parameters $Parameters -ConfigurationData $ConfigurationData 

您不应该担心PSDscAllowPlainTextPassword,因为Azure自动化确实为您加密了所有内容,它只是DSC不知道(因此您必须将其提供给DSC发动机)。

在DSC中你应该有类似的东西:

Configuration name
    {   
        Param (
        [Parameter(Mandatory)][ValidateNotNullOrEmpty()][String]$nodeName,
        [Parameter(Mandatory)][ValidateNotNullOrEmpty()][pscredential]$credential
        )

        Import-DscResource -Module modules

        Node $nodeName {DOSTUFF}
}

答案 1 :(得分:0)

将凭证从Azure自动化传递到DSC文件的正确方法是使用Azure自动化凭据。

然后在DSC文件中使用命令Get-AutomationPSCredential

示例:

Configuration BaseDSC
{

    Import-DscResource -ModuleName xActiveDirectory
    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName XNetworking

    $Credential = Get-AutomationPSCredential -Name "CredentialName"

    Node $AllNodes.Nodename
    { ...

凭据在Azure自动化中加密存储,并在运行编译作业时放入Azure自动化中的加密MOF文件中。

此外,可以在Azure自动化中更新密码,然后通过重新编译在MOF中更新密码。

无法从Azure以明文检索密码。

答案 2 :(得分:-1)

使用安全凭据并创建Windows服务器用户,然后使用dsc将其添加到Administrator组:

**解决方案(PowerShell DSC)**

首先:通过天蓝色门户或使用任何天蓝色模块在自动化帐户中创建凭据 主页>资源组> ...>自动化帐户>凭据

Configuration user_windows_user
{
    param
    (     
    [Parameter()][string]$username,
    [Parameter()]$azurePasswordCred  **#name (string)of the credentials**
  )

   $passwordCred = Get-AutomationPSCredential -Name $azurePasswordCred
   Node "localhost"
   {
         User UserAdd
        {
            Ensure = "Present"  # To ensure the user account does not exist, set Ensure to "Absent"
            UserName = $username
            FullName = "$username-fullname"
            PasswordChangeRequired = $false
            PasswordNeverExpires = $false
            Password = $passwordCred # This needs to be a credential object

        }
        Group AddtoAdministrators
        {
           GroupName = "Administrators"
           Ensure = "Present"
           MembersToInclude = @($username)
        }

   }
} # end of Configuration 

#
$cd = @{
    AllNodes = @(
        @{
            NodeName = 'localhost'
            PSDscAllowPlainTextPassword = $true
        }
    )
}
  • 以azure automation>配置上传Dsc文件
  • 编译配置(提供输入-username,凭据名称(字符串)
  • 将配置添加到节点并等待配置部署
相关问题