2017-06-16 3 views
1

読み取り専用ドメインコントローラになるマシン上でローカルに実行できるDSCスクリプトを作成しようとしています。 xActiveDirectory DSCリソースはRODCの作成を提供しないため、スクリプトリソースを使用してInstall-ADDSDomainControllerを使用する必要があります。読み取り専用ドメインコントローラのDSC設定にSecureString変数を渡す

Safe Mode Administratorのパスワードを入力する必要があるときに問題が発生します。このパラメータはSecureStringのみを受け入れますが、DSC設定にセキュアな文字列を渡す際に問題があります。私はCredentialパラメーターのPSCredentialオブジェクトを渡すことができますが、Safe Modeパラメーターはそれを受け入れず、別の変数が必要です。私は現時点で問題なく動作しているように思われる自己署名証明書で証明書を暗号化しています。

マイDSCコード、私が働いていた非そのうちセキュリティで保護された文字列を作成するための別の方法をテストした下部のコメントアウト行のカップルがあります:

get-childitem cert:\localmachine\my | where-object {$_.Subject -like "*CN=DscEncryptionCert*"} | remove-item 

$cert = New-SelfSignedCertificate -Type DocumentEncryptionCertLegacyCsp -DnsName 'DscEncryptionCert' -HashAlgorithm SHA256 
$cert | Export-Certificate -FilePath "c:\RODC\DscPublicKey.cer" -Force 

$thumbprint = (get-childitem cert:\localmachine\my | where-object {$_.Subject -like "*CN=DscEncryptionCert*"}).Thumbprint 


$ConfigData= @{ 
    AllNodes = @(  
      @{ 
       NodeName = "localhost" 

       CertificateFile = "C:\RODC\localhost.cer" 

       Thumbprint = $thumbprint 
      }; 
     );  
    } 




configuration RODC 

{ 
    param(
     [Parameter()]$DomainName, 
     [Parameter()]$ReplicationSourceDC, 
     [Parameter()]$SiteName, 
     [Parameter()]$Thumbprint, 
     [PSCredential]$PSCredential = $PSCredential, 
     [Parameter(Mandatory=$true)] 
     [ValidateNotNullOrEmpty()] 
     [System.Security.SecureString]$safemodepassword = $safemodepassword 
     ) 

    Import-DscResource -module 'PSDesiredStateConfiguration' 

    Node localhost 

    { 

     LocalConfigurationManager 
      { 
      CertificateId = $Thumbprint 
      } 

     WindowsFeature ADDSInstall 
      { 
      Ensure = 'Present' 
      Name = 'AD-Domain-Services' 
      IncludeAllSubFeature = $true 
      } 

     script installRODC 
      { 
      DependsOn = '[WindowsFeature]ADDSInstall' 
      SetScript = 
       { 
       Import-Module ADDSDeployment 
       Install-ADDSDomainController ` 
       -AllowPasswordReplicationAccountName @("test\Allowed RODC Password Replication Group") ` 
       -NoGlobalCatalog:$false ` 
       -Credential:$PSCredential ` 
       -CriticalReplicationOnly:$false ` 
       -DenyPasswordReplicationAccountName @("BUILTIN\Administrators", "BUILTIN\Server Operators", "BUILTIN\Backup Operators", "BUILTIN\Account Operators", "test\Denied RODC Password Replication Group") ` 
       -DomainName:$using:DomainName ` 
       -InstallDns:$true ` 
       -NoRebootOnCompletion:$false ` 
       -ReadOnlyReplica:$true ` 
       -ReplicationSourceDC:$using:ReplicationSourceDC ` 
       -SiteName $using:SiteName ` 
       -Force:$true ` 
       -SafeModeAdministratorPassword:$safemodepassword 
       } 
      TestScript = 
       { 
       if((get-wmiobject win32_computersystem).domainrole -eq 4){$true}else{$false} 
       } 
      GetScript = 
       { 
       Return @{result = (get-wmiobject win32_computersystem).domainrole} 
       } 
      } 

    } 

} 

$PSCredential = Get-Credential 
$safemodepassword = Read-Host -assecurestring "Please enter the Safe Mode Administrator password" 
#$safemodepassword = ConvertTo-SecureString "[email protected]" -AsPlainText -Force 
#$safemodepassword = New-Object System.Management.Automation.PSCredential ("Administrator", $password) 

RODC -DomainName test.local -ReplicationSourceDC DC1.test.local -Sitename Site11 -PSCredential $PSCredential -safemodepassword $safemodepassword 

Set-DscLocalConfigurationManager -path .\RODC -Verbose -Force 

Start-DscConfiguration -path .\RODC -Verbose -force 

私がいるかどうかを確認するために書いた簡単なテスト

$PSCredential = Get-Credential 
$safemodepassword = Read-Host -assecurestring "Please enter the Safe Mode Administrator password" 

$DomainName = "test.local" 
$ReplicationSourceDC = "DC1.test.local" 
$Sitename = "Site11" 


Install-ADDSDomainController ` 
-AllowPasswordReplicationAccountName @("test\Allowed RODC Password Replication Group") ` 
-NoGlobalCatalog:$false ` 
-Credential:$PSCredential ` 
-CriticalReplicationOnly:$false ` 
-DenyPasswordReplicationAccountName @("BUILTIN\Administrators", "BUILTIN\Server Operators", "BUILTIN\Backup Operators", "BUILTIN\Account Operators", "test\Denied RODC Password Replication Group") ` 
-DomainName:$DomainName ` 
-InstallDns:$true ` 
-NoRebootOnCompletion:$false ` 
-ReadOnlyReplica:$true ` 
-ReplicationSourceDC:$ReplicationSourceDC ` 
-SiteName $SiteName ` 
-Force:$true ` 
-SafeModeAdministratorPassword:$safemodepassword 

私が得る主なエラーは次のとおりです:

PowerShell DSC resource MSFT_ScriptResource failed to execute Set-TargetResource functionality with error message: Cannot bind parameter 'SafeModeAdministratorPassword' to the target. Exception setting "SafeModeAdministratorPassword": "SafeModeAdministratorPassword cannot be null."

スクリプトコード自体は、それがある、取り組んでいます

正しく通過していないのでNULLですか?変数の値を出力すると、安全な文字列が存在することがわかりますが、実際のDSC構成自体ではそうではないようです。私は-SafeModeAdministratorPassword変更した場合は

:私は行くことができる場所を私はよく分からない

PowerShell DSC resource MSFT_ScriptResource failed to execute Set-TargetResource functionality with error message: Exception calling "Deserialize" with "1" argument(s): "The system cannot find the path specified.

:私は他の変数のいくつかを持っているとしてを使用して$を含めるように$ safemodepasswordを私はエラーを取得しますここから。どんな助けもありがとう。ありがとう。

+0

最も簡単な回避策は、その場合には、単に確認するために、通常の文字列(のうちのDSC構成内securestring構築することだろう作品)。また、DSCのデバッグはps 5+のほうがはるかに簡単です。おそらくそれを使用するべきです。 https://blogs.technet.microsoft.com/ashleymcglone/2016/10/26/gnarly-innards-how-to-live-debug-powershell-dsc-configurations-without-using-enable-dscdebug/ – 4c74356b41

答えて

0

Scriptブロック内でSecureStringを渡すことはできないと思います。

ローカルPC上に存在するキーで暗号化されています。

PS C:\> [System.Management.Automation.PSSerializer]::Deserialize('<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> 
>> <Obj RefId="0"> 
>>  <TN RefId="0"> 
>>  <T>System.Management.Automation.PSCredential</T> 
>>  <T>System.Object</T> 
>>  </TN> 
>>  <ToString>System.Management.Automation.PSCredential</ToString> 
>>  <Props> 
>>  <S N="UserName">Hey</S> 
>>  <SS N="Password">01000000d08c9ddf0115d1118c7a00c04fc297eb0100000034646a6e6b53d244b223386a302a6fe700000000020000000000106600000001000020000000db75ebc7ae7b02d84ef6cb1161559006bdd81a84ccd5d152f3a6fdfdcf102165000000000e8000000002000020000000f0c4f2676ae5a65d2823ec8d73c352c79a97d7fd3971fd64c084d90c6c94ff7c20000000476fd1bd7f1842fdfb2e2f2fc4fd17ee0d7b41fefb39cda407bd2a6176e7b40e40000000575dac900276dcc550f09fe48b341885431dd8d287a6073ccbbfbc89e2ff8ee9e3158a8d75a52332ab2a60126cbc69232c6d9109d1db17e28535726b5e1ec2b3</SS> 
>>  </Props> 
>> </Obj> 
>> </Objs>') 

UserName      Password 
--------      -------- 
Hey  System.Security.SecureString 

[WIN-U42BH7N5O4B]: PS C:\> [System.Management.Automation.PSSerializer]::Deserialize('<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> 
>> <Obj RefId="0"> 
>>  <TN RefId="0"> 
>>  <T>System.Management.Automation.PSCredential</T> 
>>  <T>System.Object</T> 
>>  </TN> 
>>  <ToString>System.Management.Automation.PSCredential</ToString> 
>>  <Props> 
>>  <S N="UserName">Hey</S> 
>>  <SS N="Password">01000000d08c9ddf0115d1118c7a00c04fc297eb0100000034646a6e6b53d244b223386a302a6fe700000000020000000000106600000001000020000000db75ebc7ae7b02d84ef6cb1161559006bdd81a84ccd5d152f3a6fdfdcf102165000000000e8000000002000020000000f0c4f2676ae5a65d2823ec8d73c352c79a97d7fd3971fd64c084d90c6c94ff7c20000000476fd1bd7f1842fdfb2e2f2fc4fd17ee0d7b41fefb39cda407bd2a6176e7b40e40000000575dac900276dcc550f09fe48b341885431dd8d287a6073ccbbfbc89e2ff8ee9e3158a8d75a52332ab2a60126cbc69232c6d9109d1db17e28535726b5e1ec2b3</SS> 
>>  </Props> 
>> </Obj> 
>> </Objs>') 
Exception calling "Deserialize" with "1" argument(s): "Key not valid for use in specified state. 
" 
At line:1 char:1 
+ [System.Management.Automation.PSSerializer]::Deserialize('<Objs Versi ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : CryptographicException 

使用Cryptographic Message Syntax暗号化された文字列。

Configuration WebSitePublishConfig 
{ 
    param 
    (
     [Parameter(Mandatory=$true)] 
     [PSCredential] $Credential, 
     [Parameter(Mandatory=$true)] 
     [string] $CertificateFile 
    ) 

    Import-DscResource -ModuleName PSDesiredStateConfiguration 

    $UserName = $Credential.UserName 
    $EncryptedPassword = $Credential.GetNetworkCredential().Password | Protect-CmsMessage -To $CertificateFile 

    Script MyScript 
    { 
     SetScript = ` 
      { 
       # $using:UserName 
       $password = Unprotect-CmsMessage -Content $using:EncryptedPassword 
      } 
    } 
} 

あなたはプレーンテキストでパスワードを渡し、セキュリティを気にしない場合:

$UserName = $Credential.UserName 
$PasswordPlain = $Credential.GetNetworkCredential().Password 

Script MyScript 
{ 
    SetScript = ` 
     { 
      # $using.UserName 
      # $using:PasswordPlain 
     } 
} 
関連する問題