DSC - 客户端错误 - 无法获取私钥

DSC - client error - The private key could not be aquired

我在 WMF5 下有一个 Windows 2012R2 DSC Pull 服务器和一个在 WMF5.1 下的 Windows 2008R2 客户端。由于需要访问网络资源,凭据由 Pull 服务器编码到 MOF 中,并使用驻留在 Cert:\LocalMachine\My

中的证书进行加密

基于 https://msdn.microsoft.com/en-us/powershell/dsc/securemof 密钥是使用以下方法创建的:

New-SelfsignedCertificateEx `
-Subject "CN=${ENV:ComputerName}.${ENV:UserDnsDomain}" `
-EKU 'Document Encryption' `
-KeyUsage 'KeyEncipherment, DataEncipherment' `
-SAN ${ENV:ComputerName}.${ENV:UserDnsDomain} `
-FriendlyName 'DSC Credential Encryption certificate' `
-Exportable `
-StoreLocation 'LocalMachine' `
-StoreName 'My' `
-KeyLength 2048 `
-ProviderName 'Microsoft Enhanced Cryptographic Provider v1.0' `
-AlgorithmName 'RSA' `
-SignatureAlgorithm 'SHA256' `
-NotBefore $effDate `
-NotAfter $expiryDate

我已导出此证书,并将其导入客户端计算机,也在 Cert:\LocalMachine\My 中使用此命令

certutil -addstore My C:\DSC\DscPublicKey.cer

两台机器都可以找到带有以下代码的证书(运行 使用交互式管理员用户)

$Cert =  Get-ChildItem -Path cert:\LocalMachine\My | Where-Object {
    (
        ($_.Issuer -eq $IssuerCN) -and ($_.Subject -eq $IssuerCN)
    )
} 
Write-Host " Thumbprint : " $Cert.Thumbprint

我可以在 Pull 服务器上的 MOF 中看到加密的凭据。加密似乎按预期工作。

在客户端,MOF 处理日志显示了一个 MSFT_DSCMetaConfiguration 的实例,其中包含用于加密的匹配 CertificateID,并且 LCM 已初始化为具有提取正确证书的功能。

function Get-LocalEncryptionCertificateThumbprint 
{ 
    (dir Cert:\LocalMachine\my) | %{
        # Verify the certificate is for Encryption and valid 
        If (($_.Issuer -eq $encryCertCN ) -and ($_.Subject -eq $encryCertCN )  )
        { 
            return $_.Thumbprint 
        } 
    } 
}

但是,Get-DSCConfigurationStatus 显示失败状态。当我查看日志时,我看到错误

Status = "Failure";
Error = "The private key could not be acquired.";

我所有的管道阶段最终都从 InDesiredState = False; 切换到 InDesiredState = True;(我假设 DSC这样做是为了避免永远尝试做一些它没有希望实现的事情。

此时我唯一的想法是客户端的证书不在 SYSTEM 用户可以访问的位置 - 但我无法确定这是原因。

如果 Cert:\LocalMachine\My 位置不正确 - 证书应该安装在哪里?

编辑:

证书在 PULL 服务器上创建,.CER 文件导出并手动导入到目标节点(目前 - 最终将在 AD 中处理)。我也试过导出完整的 PFX 并将其导入目标节点,结果相同。

在这一点上,我怀疑生成的证书是自签名的,不足以达到目的...

基于一些假设,您正在 Pull 服务器上创建证书,包括 public 和私钥。然后仅在目标节点上导入 public 密钥(.cer 文件)。问题是 Pull Server 不是需要私钥的机器。目标节点需要私钥。该过程应该更像这样。

  1. 正在配置的目标节点上创建证书,包括 public 和私钥。参见 Securing the MOF File - Creating the Certificate on the Target Node
  2. 正在导出 public 密钥
  3. 在 Pull 服务器上导入 public 密钥
  4. 在 Pull 服务器上编译配置
  5. 目标节点上的配置运行不知何故

这被认为是一种不好的做法,但如果您想拥有一个证书,则过程如下所示:

  1. 正在 Pull 服务器上创建证书,包括 public 和私钥。参见 Securing the MOF File - Creating the Certificate on the Target Node
  2. 正在使用 Export-PfxCertificate
  3. 导出完整证书
  4. 将密钥安全地传输到目标节点(这通常不安全,为什么这是一种不好的做法)
  5. 正在配置的目标节点导入pull key
  6. 在 Pull 服务器上编译配置
  7. 目标节点上的配置运行不知何故