Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Problem with Exchange connection on linux

Open gaborenok opened this issue 1 year ago • 14 comments

Hello Everyone!

I’m trying to run M365 DSC in a Linux Docker container and, surprisingly, I’ve managed to get most of it working so far. However, I’m running into an issue with the Exchange Online connection.

Does anyone have any suggestions on how to fix or work around this?

I can’t connect using the certificate thumbprint, because it looks for the certificate in the Windows Cert store, which isn’t available on Linux. Everything works fine when using CertificatePath and Password, except for ExchangeOnline — even though according to the documentation, it should be supported through DSC as well.


Export-M365DSCConfiguration -Components @("O365OrgSettings") -ApplicationId $ApplicationId -CertificatePath $CertPath -CertificatePassword $Cred -ApplicationSecret $ApplicationSecret -TenantId $TenantId -Path $outputPath


This is the error that I am getting:


Exporting Microsoft 365 configuration for Components: O365OrgSettings

Authentication methods specified:

  • Service Principal with Certificate Path
  • Service Principal with Application Secret

Connecting to {ExchangeOnline}...❌ Exception: /ConfigCobraAssessment/Modules/MSCloudLoginAssistant/1.1.52/Workloads/ExchangeOnline.ps1:290 Line | 290 | throw 'No valid authentication type found' | ~~~~~~~~~


I can connect to Exchange manually without any issues using this direct command:

Connect-ExchangeOnline -AppId $ApplicationId -CertificateFilePath $CertPath -CertificatePassword $CertSecurePassword -Organization "example.onmicrosoft.com"

Does anyone have any ideas or suggestions on how to make this work?

Thank you!

gaborenok avatar Nov 11 '25 11:11 gaborenok

@gaborenok A quick clarifier: Microsoft365DSC is not properly supported on non-Windows platforms, so things might break. Still glad you tried and it seems to work.

Your issue comes from the fact that in the current implementation of MSCloudLoginAssistant, the ExchangeOnline workload does not work with either CertificatePath nor Application Secret. The current implemented ways are the following:

  • Certificate Thumbprint
  • Credentials
  • (Managed) Identity
  • Access Token

I'm not sure why Certificate Path as an authentication method wasn't yet implemented, but I guess because no other workload can use it. On the other side, Application Secret is not supported with ExchangeOnline. Hence, since both of these versions are not working, you receive the error No valid authentication type found.

What might work is to continue using the Client Secret, but also use the combination with an AccessToken. However, I have to admit that I did not test this and it might not work. But since Client Secret is supported by Graph and comes earlier than the AccessToken variant, it should be selected first, and since Client Secret is not supported for ExchangeOnline, it should select the AccessToken for it.

Connect-AzAccount # For application, use with --> -ApplicationId <clientId> -CertificatePath <path> -CertificatePassword <password>
$accessToken = (ConvertFrom-SecureString -SecureString (Get-AzAccessToken -ResourceUrl "https://outlook.office365.com/.default").Token -AsPlainText)
Export-M365DSCConfiguration -Components @("O365OrgSettings") -ApplicationId $ApplicationId -ApplicationSecret $ApplicationSecret -TenantId $TenantId -AccessToken $accessToken -Path $outputPath

For further information about what's going on, use -Verbose at the end. Hope that helps! Let us know how it goes, we're very curious. Thanks and good luck 👍


Edit: Just tested the thing. Unfortunately it's not that easy as I imagined. The current logic is to not try multiple different authentication mechanisms. If one is discovered (Client Secret is first), then this will be used. No retry mechanism with another mechanism is present. I'll try and implement something for ExchangeOnline, but no promises here. And I'll check if we can make the certificate store lookup independent from the operating system.

FabienTschanz avatar Nov 11 '25 21:11 FabienTschanz

After further testing it's unfortunately (currently) not possible. The issue is as mentioned that Microsoft365DSC does not support providing multiple authentication methods at once and that on Linux, Certificate Thumbprint is not available for the ExchangeOnlineManagement module. This is a limitation of the module itself and not something we can fix.

If possible, try using a Managed Identity. Can be user assigned, doesn't have to be a system assigned Managed Identity. I don't know how you set up your container infrastructure, but it would be required to be set up in Azure and not on e.g. your local computer or on-premises infrastructure. That's another restriction.

It's very unfortunate that support is still lacking from the modules. I'll see if there's a possibility to use CertificatePath and load the certificate into memory for Connect-MgGraph to work. If yes, then the Client Secret is no longer necessary.

FabienTschanz avatar Nov 12 '25 00:11 FabienTschanz

@FabienTschanz thanks a lot for your comments. Yes, I totally understand that this is not supported on Linux yet.

I tried each way that you mentioned as well today.

Unfortunately, I cannot give good news on the progress; the connection to Exchange Online is still not successful with either of the options.

With managed identity, I am getting the following error message:


VERBOSE: Module 'MSCloudLoginAssistant' with version '1.1.52' has been imported. VERBOSE: All dependencies for module 'MSFT_O365OrgSettings' have been validated. VERBOSE: Importing function 'Export-TargetResource'. VERBOSE: Importing function 'Get-TargetResource'. VERBOSE: Importing function 'Set-TargetResource'. VERBOSE: Importing function 'Test-TargetResource'. Connecting to {ExchangeOnline}...❌ OperationStopped: Value cannot be null. (Parameter 'Organization cannot be null for Managed Identity based connections.')


I do not really understand the issue because I cannot give Organization parameter at all. And I understand that this is the error from the Exchange module.

Export-M365DSCConfiguration -Components @("O365OrgSettings") -ManagedIdentity -TenantId $TenantId ` -Path $outputPath

Any ideas?

gaborenok avatar Nov 12 '25 15:11 gaborenok

We have a release prepared (1.25.1112.1) which will be available soon. Please try again with this version and the updated dependencies, we fixed a couple of things in the MSCloudLoginAssistant. Maybe it works afterwards. But I'll try and trace where the issue comes from and add that to the list of things to fix that I have already prepared.

FabienTschanz avatar Nov 12 '25 15:11 FabienTschanz

Thank you! I managed to do it with an access token, and for now, I will use separate DSC exports and then join them. I will let you know how it went.

$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertPath, $CertSecurePassword) Write-Output "Certificate loaded successfully"

try { $ExchangeToken = Get-MsalToken -ClientId $ApplicationId -TenantId $TenantId -ClientCertificate $Cert -Scopes "https://outlook.office365.com/.default" } catch { Write-Warning "Could not get access token: $_" } $ExchangeAccessToken = $ExchangeToken.AccessToken

Export-M365DSCConfiguration -Components @("O365OrgSettings") -AccessToken $ExchangeAccessToken -TenantId $TenantId ` -Path $outputPath

If you have any other suggestions, I am happy to hear them.

gaborenok avatar Nov 12 '25 16:11 gaborenok

Nicely done, looking forward to it. I'll keep you posted with my experiments.

FabienTschanz avatar Nov 12 '25 17:11 FabienTschanz

The changes from https://github.com/microsoft/MSCloudLoginAssistant/pull/231/commits/cb99afe68e9976b7244100213003ab036ae254fb breaks cert auth on windows machines running PS 5.1. specifically if ($PSVersionTable.Platform -ne 'Win32NT') as platform doesn't exist.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-5.1#psversiontable
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.5#psversiontable

Connecting to {ExchangeOnline}...❌
Partial Export file was saved at: C:\Users\VSSADM~1\AppData\Local\Temp\eaebfd66-e645-4816-be6a-a1dd2c5efe1d.partial.ps1
Certificate Thumbprint authentication is only supported on the Windows platform.
At C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.55\Workloads\ExchangeOnline.ps1:113 char:17
+ ...             throw 'Certificate Thumbprint authentication is only supp ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Certificate Thu...ndows platform.:String) [], RuntimeException
    + FullyQualifiedErrorId : Certificate Thumbprint authentication is only supported on the Windows platform.

ssoabx avatar Dec 04 '25 08:12 ssoabx

@ssoabx Working on it.

FabienTschanz avatar Dec 04 '25 08:12 FabienTschanz

Hey @gaborenok gaborenok. We were trying to do the exact thing. Running DSC in a Linux Docker container and we didnt get so far as you seem to have gotten. We got lost in the "initialization" phase where we prepared the environment: image with powershell and the installation of the necessary modules.

Our plan was to use the container to be able to initialize a pipeline that would help automating reading the setting config for the available resource categories in our tenant... Manual triggering it can be time consuming and an automation is always better.

We'd be grateful for some insights how you got to the stage where you were! Maybe what image you used and how you used the certificate path for the authentication. Or maybe some tips how we could automate the process described before.

Thanks a bunch and a happy new year (kinda late but hey!)

Greetings

noddcrack avatar Jan 15 '26 18:01 noddcrack

MSCloudLoginAssistant fails Exchange Online auth on Linux: The missing code path

MSCloudLoginAssistant version 1.1.52 throws "No valid authentication type found" on Linux because its ExchangeOnline.ps1 module lacks a handler for ServicePrincipalWithPath authentication—the only certificate method that works on non-Windows platforms. The direct Connect-ExchangeOnline command succeeds because it accepts -CertificateFilePath directly, while MSCloudLoginAssistant's routing logic only recognizes ServicePrincipalWithThumbprint, which requires the Windows Certificate Store that doesn't exist on Linux. This is a known gap in the module's cross-platform support.

Why MSCloudLoginAssistant cannot route CertificatePath authentication

The authentication failure occurs at line ~290 in ExchangeOnline.ps1 where the module evaluates which connection method to use. Based on GitHub source analysis, the module checks for these authentication types:

  • ServicePrincipalWithThumbprint → Uses -CertificateThumbprint parameter
  • ManagedIdentity → Uses Azure Managed Identity
  • Credentials → Uses username/password
  • AccessTokens → Uses OAuth tokens

The critical missing handler is ServicePrincipalWithPath, which should route to -CertificateFilePath + -CertificatePassword. When users configure M365DSC with CertificatePath instead of CertificateThumbprint, MSCloudLoginAssistant sets the authentication type to ServicePrincipalWithPath, but no corresponding code block exists to handle this case. The execution falls through to the default throw 'No valid authentication type found' error.

Microsoft's documentation explicitly states: "The CertificateThumbprint parameter is supported only in Microsoft Windows." This creates an impossible situation—Linux users cannot use CertificateThumbprint (requires Windows Certificate Store), yet MSCloudLoginAssistant doesn't properly route the Linux-compatible CertificatePath option.

Relevant GitHub issues confirm the gap

GitHub Issue #5687 on Microsoft365DSC documents this exact error at ExchangeOnline.ps1:289 with MSCloudLoginAssistant 1.1.34, where a user attempting certificate authentication received "No valid authentication type found." Issue #5601 reports macOS/Darwin failures with module path errors in ExchangeOnline.ps1:75, demonstrating broader non-Windows platform issues. Issue #6098 reveals module version incompatibilities where MSCloudLoginAssistant 1.1.43 uses the deprecated -DisableWAM parameter removed in ExchangeOnlineManagement 3.7.2.

The MSCloudLoginAssistant repository shows 21 open issues with no published releases or detailed changelogs on GitHub. Updates are tracked only through PowerShell Gallery versions and Microsoft365DSC dependencies.

Direct connection works because it bypasses the routing logic

When running Connect-ExchangeOnline directly with -CertificateFilePath and -CertificatePassword, the Exchange Online PowerShell module handles the authentication natively without MSCloudLoginAssistant's intermediary routing:

# This works directly on Linux
Connect-ExchangeOnline `
    -CertificateFilePath "/path/to/certificate.pfx" `
    -CertificatePassword (ConvertTo-SecureString -String "password" -AsPlainText -Force) `
    -AppID "your-app-id" `
    -Organization "tenant.onmicrosoft.com"

The ExchangeOnlineManagement module (v2.0.4+) has native Linux support for file-based certificate authentication. The failure occurs only when MSCloudLoginAssistant interposes its authentication routing, which was designed primarily for Windows environments where certificate store access is standard.

Practical workarounds for Linux Docker deployments

Option 1: Bypass MSCloudLoginAssistant for Exchange Online workloads. Connect to Exchange Online directly before running M365DSC operations, though this may not integrate seamlessly with DSC configuration management:

$certPassword = ConvertTo-SecureString -String $env:CERT_PASSWORD -AsPlainText -Force
Connect-ExchangeOnline `
    -CertificateFilePath "/certs/m365dsc.pfx" `
    -CertificatePassword $certPassword `
    -AppID $env:APP_ID `
    -Organization "tenant.onmicrosoft.com"

Option 2: Use Access Token authentication (available in ExchangeOnlineManagement 3.1.0+ and MSCloudLoginAssistant 1.0.119+). Generate tokens externally via Azure CLI or managed identity, then pass to M365DSC:

$accessToken = (Get-AzAccessToken -ResourceTypeName "https://outlook.office365.com").Token
Connect-ExchangeOnline `
    -AccessToken (ConvertTo-SecureString $accessToken -AsPlainText -Force) `
    -Organization "tenant.onmicrosoft.com"

Option 3: Patch ExchangeOnline.ps1 locally by adding a ServicePrincipalWithPath handler around line 290:

elseif ($Global:MSCloudLoginConnectionProfile.ExchangeOnline.AuthenticationType -eq 'ServicePrincipalWithPath')
{
    Connect-ExchangeOnline `
        -CertificateFilePath $Global:MSCloudLoginConnectionProfile.ExchangeOnline.CertificatePath `
        -CertificatePassword $Global:MSCloudLoginConnectionProfile.ExchangeOnline.CertificatePassword `
        -AppId $Global:MSCloudLoginConnectionProfile.ExchangeOnline.ApplicationId `
        -Organization $Global:MSCloudLoginConnectionProfile.ExchangeOnline.TenantId
}

Option 4: Use Managed Identity if running in Azure (VMs, Functions, Container Apps). This authentication type is already handled by MSCloudLoginAssistant.

Docker-specific requirements that compound the problem

Linux containers require PSWSMan module installation before Exchange Online connections work. Without it, SSL errors occur (undefined symbol: SSL_library_init). The correct container setup:

FROM mcr.microsoft.com/azure-powershell:latest
RUN pwsh -Command "Install-Module -Name PSWSMan -Force -Scope AllUsers"
RUN pwsh -Command "Install-WSMan"
RUN pwsh -Command "Install-Module -Name ExchangeOnlineManagement -Force -Scope AllUsers"

M365DSC itself has deeper Linux limitations beyond authentication—the Local Configuration Manager (LCM) that enforces DSC configurations is a Windows-only component. M365DSC on Linux can perform exports and generate configurations, but cannot enforce configuration drift without Windows LCM infrastructure.

Version updates have not addressed this specific issue

MSCloudLoginAssistant version 1.0.119 fixed SecureString conversion errors for Graph SDK 2.0 compatibility, and 1.1.43 addressed some parameter issues, but no version through 1.1.52 has added the ServicePrincipalWithPath handler for Exchange Online. The module continues to assume Windows Certificate Store availability for certificate-based authentication scenarios.

ExchangeOnlineManagement 3.5.0 is recommended to avoid the -DisableWAM parameter incompatibility with newer MSCloudLoginAssistant versions. Version 3.7.2+ removed this parameter entirely.

Conclusion

The "No valid authentication type found" error stems from a straightforward code gap in MSCloudLoginAssistant—no handler exists for ServicePrincipalWithPath authentication in the Exchange Online workload module. Microsoft's explicit Windows-only limitation on CertificateThumbprint combined with this missing code path creates a complete barrier for certificate-based M365DSC Exchange Online operations on Linux.

Immediate solutions include bypassing MSCloudLoginAssistant with direct Connect-ExchangeOnline calls using -CertificateFilePath, switching to access token authentication, or patching the module locally. Long-term, the M365DSC team should add OS detection and ServicePrincipalWithPath routing to ExchangeOnline.ps1—a relatively simple fix that would enable cross-platform certificate authentication. Consider filing a GitHub issue on the MSCloudLoginAssistant repository requesting this specific enhancement, referencing the existing issue #5687 as context.

es-ist-leon avatar Jan 20 '26 06:01 es-ist-leon

Hi everyone, the reply from es-ist-leon is quite good and goes into the same details and directions that I explored.

I’ve pushed my code to a public repository so you can take a look and copy anything useful. I didn’t take this any further because, for my use case, it wasn’t sufficient. There are also many exports that don’t work with an access token. I haven’t tried managed identity yet—only access tokens.

I also wasn’t able to install DSC properly inside the container, so I had to import the modules manually. That step might not actually be necessary, but I couldn’t get it working otherwise.

Repository

https://github.com/gaborenok/m365_dsc_linux

If you plan to run these containers in GitHub Actions or another pipeline environment, you may also want to consider Windows containers. In my experience, they had no practical limitations, and I was able to do everything I needed.

I hope this helps.
Good luck, and please keep me posted on your progress—I’m curious to see how it turns out!

gaborenok avatar Jan 20 '26 09:01 gaborenok

I'll add some of the missing authentication options to the MSCloudLoginAssistant module, but that will take some time to complete. Got some other things that require a bit more of my attention first. Will add this to the list of todos.

FabienTschanz avatar Jan 20 '26 19:01 FabienTschanz

already did it

es-ist-leon avatar Jan 20 '26 19:01 es-ist-leon

Support for Exchange Online connection on Linux is now available within MSCloudLoginAssistant.

FabienTschanz avatar Apr 10 '26 08:04 FabienTschanz