【问题标题】:DSC problems with Credentials and build 10586凭证和内部版本 10586 的 DSC 问题
【发布时间】:2015-11-30 19:57:13
【问题描述】:

最新的 windows 10 版本推出了更新版本的 powershell (10586)。

除了https://dscottraynsford.wordpress.com/2015/11/15/windows-10-build-10586-powershell-problems/ 记录的证书所需的更改之外,我在尝试应用配置时似乎还有一个问题:

WarningMessage 应用部分配置 [PartialConfiguration]ExternalIntegrationConfiguration 时发生错误。错误信息是: 解密失败..

使用相同的证书,我可以使用 build 10.0.10240.16384 成功创建 MOF,并成功应用它。所以看看这两个 MOF 之间的区别,我发现 build 10586 构建的 MOF 看起来像:

instance of MSFT_Credential as $MSFT_Credential6ref
{
Password = "-----BEGIN CMS-----
    \nBase64 encrypted
\n-----END CMS-----";
UserName = "SomeUser";
};

而不是以前在 build (10.0.10240.16384) 中的样子:

instance of MSFT_Credential as $MSFT_Credential6ref
{
Password = "Base64 encrypted";
UserName = "SomeUser";
};

所以内容不同。我确实检查了是否可以使用 Get-CmsMessage 和 unprotect-CmsMessage 解密凭据,并且可以。所以公钥/私钥的东西看起来不错。

是否应该对正在应用配置的机器进行更新?我没有看到任何新的 powershell 版本。

任何想法都将不胜感激。

【问题讨论】:

    标签: powershell dsc powershell-5.0


    【解决方案1】:

    2015 年 12 月 18 日更新:在正在配置的节点上安装 2015 年 12 月 17 日发布的 Windows Management Framework (WMF) 5.0 RTM 版本将解决此错误。 WMF 5.0 可以下载here.

    MS 已更改 PSDesiredStateConfiguration 中的 Get-EncryptedPassword 函数,以便为 MOF 中的密码字段生成新格式。如果 WMF 尚未升级以支持密码,这将防止 DSC 节点解密密码。但由于 MS 尚未发布更新以允许 WMF 读取这种新格式,因此这应该被视为完全损坏的版本。

    我设法找到了解决方法: 将 PSDesiredStateConfiguration 模块从 10586 之前的机器(例如带有最新 WMF 5.0 的 Windows Server 2012 R2)复制到 Built 10586 机器上的 PowerShell 模块文件夹。

    例如 将 C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration 文件夹替换为旧版本

    注意:您需要拥有此文件夹的所有权并授予自己写入权限,因为默认情况下只有 TrustedInstaller 可以写入此文件夹。

    就我而言,此版本的 PSDesiredStateConfiguration 已完全损坏,您最好将其回滚,直到 MS 可以修复它。这还将修复一些其他报告的问题(模块版本、新证书策略要求)。

    仅供参考,这是更改凭据加密的更改代码:

    PSDesiredStateConfiguration.psm1 中的旧代码:

        # Cast the public key correctly
        $rsaProvider = [System.Security.Cryptography.RSACryptoServiceProvider]$cert.PublicKey.Key
    
        # Convert to a byte array
        $keybytes = [System.Text.Encoding]::UNICODE.GetBytes($Value)
    
        # Add a null terminator to the byte array
        $keybytes += 0
        $keybytes += 0
    
        try
        {
            # Encrypt using the public key
            $encbytes = $rsaProvider.Encrypt($keybytes, $false)
    
            # Reverse bytes for unmanaged decryption
            [Array]::Reverse($encbytes)
    
            # Return a string
            [Convert]::ToBase64String($encbytes)
        }
        catch
        {
            if($node)
            {
                $errorMessage = $LocalizedData.PasswordTooLong -f $node
            }
            else
            {
                $errorMessage = $LocalizedData.PasswordTooLong -f 'localhost'
            }
    
            $exception = New-Object -TypeName System.InvalidOperationException -ArgumentList $errorMessage
            Write-Error -Exception $exception -Message $errorMessage -Category InvalidOperation -ErrorId PasswordTooLong
            Update-ConfigurationErrorCount
        }
    

    PSDesiredStateConfiguration.psm1 中的新代码:

        # Encrypt using the public key
        $encMsg =Protect-CmsMessage -To $CmsMessageRecipient -Content $Value
    
        # Reverse bytes for unmanaged decryption
        #[Array]::Reverse($encbytes)
    
        #$encMsg = $encMsg -replace '-----BEGIN CMS-----','' 
        #$encMsg = $encMsg -replace "`n",'' 
        #$encMsg = $encMsg -replace '-----END CMS-----','' 
    
        return $encMsg
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 2011-05-08
      • 2011-03-26
      相关资源
      最近更新 更多