【问题标题】:Securing Credentials properly in DSC using Azure Automation使用 Azure 自动化在 DSC 中正确保护凭据
【发布时间】:2016-10-12 08:33:01
【问题描述】:

您将如何继续保护在 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。

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

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

但是今天,“CertificateFile”需要一个路径而不是 AutomationCertificate,因此我看不到使用 Azure 自动化中存在的任何公钥启动编译作业的方法。在运行作业时,我看不到任何引用我的资产证书的方式。

如果这在当前 Azure 自动化状态下可行,以及他们使用 DSC/pull 使用 Azure 自动化或 Azure Key vault 的资产存储正确保护它的方式,有什么想法吗?

【问题讨论】:

  • 您使用的是哪个版本的 Azure DSC 扩展?您是否尝试过至少 2.20,指定 Wmfversion = ‘5.1PP’ 并查看是否仍然发生这种情况?

标签: powershell azure dsc


【解决方案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}
}

【讨论】:

  • 这就是我写的我正在做的事情。如果您查看 C:\windows\temp 并打开其中一个校验和(适用于 mof 的应用),您将看到以纯文本形式传递给服务器的凭据。这是我试图避免的事情。如果您像使用普通拉取服务器一样使用证书和指纹进行设置;它将被加密。
  • 好吧,在这种情况下,您必须预编译 mof 并将它们上传到 azure 自动化
  • 是的,这将是我的后备计划。我希望我不必使用 Import-AzureRmAutomationDscNodeConfiguration 并且在开始编译作业时有一种引用自动化证书或 Key Vault 证书的好方法;所以我可以在一个地方处理这一切。
  • 很遗憾没有
【解决方案2】:

将凭据从 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 以明文形式检索密码。

【讨论】:

  • 为什么这么难?您可以简单地使用一个参数并在编译时将其映射到您的凭据。
  • 很难?这是超级简单而且安全的。 +1
【解决方案3】:

使用安全凭证并为 Windows 服务器创建用户并使用 dsc 添加到管理员组:

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

首先:在自动化帐户中从 Azure 门户或使用任何 azure 模块创建凭据 主页>资源组> ...> 自动化帐户 > 凭据

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>configuration 中上传 Dsc 文件
  • 编译配置(提供输入-用户名,凭证名称(字符串)
  • 向节点添加配置,等待配置部署

【讨论】:

    猜你喜欢
    • 2017-09-16
    • 2016-06-12
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2017-06-04
    • 2022-01-14
    • 2016-07-15
    • 2019-03-15
    相关资源
    最近更新 更多