Esri / arcgis-powershell-dsc

This repository contains scripts, code and samples for automating the install and configuration of ArcGIS (Enterprise and Desktop) using Microsoft Windows PowerShell DSC (Desired State Configuration).
Apache License 2.0
110 stars 61 forks source link

gMSA failures when used in PsDscRunAsCredential #364

Open PleaseStopAsking opened 2 years ago

PleaseStopAsking commented 2 years ago

Community Note

Module Version

Affected Resource(s)

Configuration Files

Expected Behavior

Portal: The PersistStorageCredentials and CreatePortalContentFolder Script resources should execute successfully and add the Azure storage account key to Windows Credential Manager for the gMSA account and create the root folder for portal content. Server: The PersistConfigStoreCloudStorageCredentials and PersistServerDirectoriesCloudStorageCredentials should execute successfully and add the Azure storage account key to Windows Credential Manager for the gMSA account.

Actual Behavior

The resources fails with the error The user name or password is incorrect on Test.

Steps to Reproduce

I created a test configuration to illustrate the issue.

To execute, copy/paste the config into powershell and then copy/paste the below commands which will fail with the error The user name or password is incorrect.

$Params = @{
    'ServiceCredential'                  = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ( 'emcsworld\gmsa1$', (ConvertTo-SecureString 'PlaceHolder' -AsPlainText -Force) ))
    'ConfigStoreCloudStorageCredentials' = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ( 'examplefileaccount1.file.core.windows.net', (ConvertTo-SecureString 'PlaceHolder' -AsPlainText -Force) ))
    'ConfigurationData'                  = (@{AllNodes = @(@{NodeName = 'localhost'; PSDscAllowPlainTextPassword = $true }) })
}
Test @Params
Start-DscConfiguration -Path .\Test\ -Wait -Force -Verbose
Configuration Test {
    param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $ServiceCredential,

        [Parameter(Mandatory = $False)]
        [System.Management.Automation.PSCredential]
        $ConfigStoreCloudStorageCredentials
    )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $AllNodes.NodeName
    {
        $ConfigStoreAzureFilesEndpoint = $ConfigStoreCloudStorageCredentials.UserName
        $ConfigStoreFilesStorageAccountName = $ConfigStoreAzureFilesEndpoint.Substring(0, $ConfigStoreAzureFilesEndpoint.IndexOf('.'))
        $ConfigStoreStorageAccountKey = $ConfigStoreCloudStorageCredentials.GetNetworkCredential().Password

        Script PersistConfigStoreCloudStorageCredentials
        {
            TestScript = {
                $result = cmdkey "/list:$using:ConfigStoreAzureFilesEndpoint"
                $result | ForEach-Object { Write-Verbose -Message "cmdkey: $_" -Verbose }
                if ($result -like '*none*') {
                    return $false
                }
                return $true
            }
            SetScript = {
                $result = cmdkey "/add:$using:ConfigStoreAzureFilesEndpoint" "/user:$using:ConfigStoreFilesStorageAccountName" "/pass:$using:ConfigStoreStorageAccountKey"
                $result | ForEach-Object { Write-Verbose -Message "cmdkey: $_" -Verbose }
            }
            GetScript            = { return @{} }
            DependsOn            = $Depends
            PsDscRunAsCredential = $ServiceCredential # This is critical, cmdkey must run as the service account to persist property
        }
    }
}

Important Factoids

This affects both the Server and Portal configurations when they attempt to store Azure storage account keys as the gMSA.

References

https://github.com/Esri/arcgis-powershell-dsc/blob/6a8456bedc0993b8ad4cf6fbaee56d4949b049b4/Modules/ArcGIS/Configurations-OnPrem/ArcGISServer.ps1#L336

https://github.com/Esri/arcgis-powershell-dsc/blob/6a8456bedc0993b8ad4cf6fbaee56d4949b049b4/Modules/ArcGIS/Configurations-OnPrem/ArcGISServer.ps1#L362

https://github.com/Esri/arcgis-powershell-dsc/blob/6a8456bedc0993b8ad4cf6fbaee56d4949b049b4/Modules/ArcGIS/Configurations-OnPrem/ArcGISPortal.ps1#L271

https://github.com/Esri/arcgis-powershell-dsc/blob/6a8456bedc0993b8ad4cf6fbaee56d4949b049b4/Modules/ArcGIS/Configurations-OnPrem/ArcGISPortal.ps1#L293

shailesh91 commented 2 years ago

@PleaseStopAsking unfortunately DSC doesn't support GMSA accounts. No way to get around this error for now.