Credentials和build 10586的DSC问题

时间:2015-11-30 19:57:13

标签: powershell dsc powershell-v5.0

最新的windows 10 build推出了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之间的区别,我看到构建10586构建的MOF看起来像:

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

而不是它在构建中的情况(10.0.10240.16384):

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

所以内容不同。我确实检查过是否可以使用Get-CmsMessage和unprotect-CmsMessage解密凭证,我可以。所以公钥/私钥似乎很好。

是否应该对要应用配置的计算机进行更新?我没有看到任何新的PowerShell构建。

任何想法都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

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

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

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

E.g。 用旧版本替换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