Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

AADOrganizationCertificateBasedAuthConfiguration: export & test fails

Open ssoabx opened this issue 6 months ago • 1 comments

Description of the issue

With the new update the AADOrganizationCertificateBasedAuthConfiguration resource doesnt export anymore and fails the test:

[21/83] Extracting [AADOrganizationCertificateBasedAuthConfiguration] using {CertificateThumbprint}...
    |---[1/1] CertificateBasedAuthConfigurations for XXXTenant❌
    An error occurred while exporting resource {AADOrganizationCertificateBasedAuthConfiguration}: Cannot convert argument "inArray", with value: "[...] long string [...]" to type "System.Byte". Error: "Input string was not in a correct format."""

Still worked two versions ago:

[21/95] Extracting [AADOrganizationCertificateBasedAuthConfiguration] using {CertificateThumbprint}...
    |---[1/1] CertificateBasedAuthConfigurations for XXXTenant✅

Build test:

VERBOSE: [runnervm9mj8d]: LCM:  [ Start  Resource ]  
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration]
VERBOSE: [runnervm9mj8d]: LCM:  [ Start  Test     ]  
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration]
VERBOSE: [runnervm9mj8d]:                            
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Testing 
configuration of the AADOrganizationCertificateBasedAuthConfiguration with OrganizationId 
{283e4ff2-6900-48ab-9c7c-1da51ec2b164}
VERBOSE: [runnervm9mj8d]:                            
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Getting 
configuration for the Azure AD Organization Certificate Based Auth Configuration for OrganizationId 
{283e4ff2-6900-48ab-9c7c-1da51ec2b164}
VERBOSE: [runnervm9mj8d]:                            
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] An Azure AD 
Organization Certificate Based Auth Configuration with Id {29728ade-6ae4-4ee9-9103-412912537da5} was found
VERBOSE: [runnervm9mj8d]:                            
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Error Log created 
at {file://C:/Windows/TEMP/7008-M365DSC-ErrorLog.log}
VERBOSE: [runnervm9mj8d]: LCM:  [ End    Test     ]  
[[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] False in 9.1650 
seconds.
VERBOSE: [runnervm9mj8d]: LCM:  [ *FAILED*Compare  ]     Completed processing compare operation. The operation returned
 False.
An internal error occurred. 
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : HRESULT 0x8007054f
    + PSComputerName        : localhost

Deploy:

2026-06-03T05:27:15.9946417Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration]

2026-06-03T05:27:15.9968917Z VERBOSE: [runnervm9mj8d]: LCM:  [ Start  Test     ] 

2026-06-03T05:27:15.9971574Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration]

2026-06-03T05:27:16.0310620Z VERBOSE: [runnervm9mj8d]:                           

2026-06-03T05:27:16.0315251Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Testing

2026-06-03T05:27:16.0319318Z configuration of the AADOrganizationCertificateBasedAuthConfiguration with OrganizationId

2026-06-03T05:27:16.0326078Z {283e4ff2-6900-48ab-9c7c-1da51ec2b164}

2026-06-03T05:27:16.0336854Z VERBOSE: [runnervm9mj8d]:                           

2026-06-03T05:27:16.0340444Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Getting

2026-06-03T05:27:16.0342280Z configuration for the Azure AD Organization Certificate Based Auth Configuration for OrganizationId

2026-06-03T05:27:16.0344769Z {283e4ff2-6900-48ab-9c7c-1da51ec2b164}

2026-06-03T05:27:16.1394644Z VERBOSE: [runnervm9mj8d]:                           

2026-06-03T05:27:16.1403275Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] An Azure AD

2026-06-03T05:27:16.1466288Z Organization Certificate Based Auth Configuration with Id {29728ade-6ae4-4ee9-9103-412912537da5} was found

2026-06-03T05:27:16.1763998Z VERBOSE: [runnervm9mj8d]:                           

2026-06-03T05:27:16.2062684Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration] Error Log created

2026-06-03T05:27:16.2087345Z at {file://C:/Windows/TEMP/7008-M365DSC-ErrorLog.log}

2026-06-03T05:27:16.2785701Z VERBOSE: [runnervm9mj8d]: LCM:  [ End    Test     ] 

2026-06-03T05:27:16.3053806Z [[AADOrganizationCertificateBasedAuthConfiguration]AADOrganizationCertificateBasedAuthConfiguration]  in 0.2970

2026-06-03T05:27:16.3120164Z seconds.

2026-06-03T05:27:16.9957881Z PowerShell DSC resource MSFT_AADOrganizationCertificateBasedAuthConfiguration  failed to execute Test-TargetResource

2026-06-03T05:27:16.9959316Z functionality with error message: Cannot convert argument "inArray", with value: "[…] long sting […]" ", for "ToBase64String" to type

2026-06-03T05:27:16.9982294Z "System.Byte[]": "Cannot convert value "[…] long sting […]" " to type "System.Byte[]". Error: "Cannot convert value […] long sting […]" to type

2026-06-03T05:27:17.0025165Z "System.Byte". Error: "Input string was not in a correct format."""

2026-06-03T05:27:17.0026267Z     + CategoryInfo          : InvalidOperation: (:) [], CimException

2026-06-03T05:27:17.0027360Z     + FullyQualifiedErrorId : ProviderOperationExecutionFailure

2026-06-03T05:27:17.0028534Z     + PSComputerName        : localhost

Error log:

System.Management.Automation.MethodException: Cannot convert argument "inArray", with value: "[...] cert1 [...]", for "ToBase64String" to type "System.Byte[]": "Cannot convert value "[...]" to type "System.Byte[]". Error: "Cannot convert value "[...]" to type "System.Byte". Error: "Input string was not in a correct format.""" ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "[...]" to type "System.Byte[]". Error: "Cannot convert value "[...]" to type "System.Byte". Error: "Input string was not in a correct format."" ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "[...]" to type "System.Byte". Error: "Input string was not in a correct format." ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at System.ComponentModel.ByteConverter.FromString(String value, NumberFormatInfo formatInfo)
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.Management.Automation.LanguagePrimitives.ConvertStringToInteger(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)
   at System.Management.Automation.LanguagePrimitives.ConvertScalarToArray(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   --- End of inner exception stack trace ---
   at System.Management.Automation.LanguagePrimitives.ConvertScalarToArray(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at CallSite.Target(Closure , CallSite , Type , Object )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
"Error retrieving data:"
at Get-TargetResource, D:\a\1\s\Modules\Microsoft365DSC\1.26.527.1\DscResources\MSFT_AADOrganizationCertificateBasedAuthConfiguration\MSFT_AADOrganizationCertificateBasedAuthConfiguration.psm1: line 107
at Test-M365DSCTargetResource, D:\a\1\s\Modules\Microsoft365DSC\1.26.527.1\Modules\M365DSCUtil.psm1: line 497
at Test-TargetResource, D:\a\1\s\Modules\Microsoft365DSC\1.26.527.1\DscResources\MSFT_AADOrganizationCertificateBasedAuthConfiguration\MSFT_AADOrganizationCertificateBasedAuthConfiguration.psm1: line 326
TenantId: dev4outsourcing.onmicrosoft.com

Microsoft 365 DSC Version

Version 1.26.527.1

Which workloads are affected

Azure Active Directory (Entra ID)

The DSC configuration

AADOrganizationCertificateBasedAuthConfiguration "AADOrganizationCertificateBasedAuthConfiguration"
        {
			ApplicationId          = $ConfigurationData.NonNodeData.ApplicationId;
            CertificateThumbprint  = $ConfigurationData.NonNodeData.CertificateThumbprint;
            TenantId               = $OrganizationName;
            OrganizationId         = $ConfigurationData.NonNodeData.OrganizationId;
            CertificateAuthorities = @(
                MSFT_MicrosoftGraphcertificateAuthority{
                    IsRootAuthority = $False
                    CertificateRevocationListUrl = "http://XXXX/XXXX.crl"
                    Certificate = "[...] long string [...]"
                }
                MSFT_MicrosoftGraphcertificateAuthority{
                    IsRootAuthority = $True
                    CertificateRevocationListUrl = "http://XXXX/XXXX.crl"
                    Certificate = "[...] long string [...]"
                }
            );
            Ensure                 = "Present";
        }

maybe related to https://github.com/Microsoft365DSC/Microsoft365DSC/commit/0f9b96629fa4969575ef107d87f148925546236f ? the certificate objects still show as System.Byte[] in graph.

ssoabx avatar Jun 03 '26 10:06 ssoabx

Hey, found the exact cause and fixed it. The problem is in Get-TargetResource in MSFT_AADOrganizationCertificateBasedAuthConfiguration.psm1. There's a single line that calls [System.Convert]::ToBase64String() on the certificate property coming back from Graph which worked fine before because Graph used to return it as a raw byte[]. At some point (looks like around 0f9b966) the SDK started returning it already as a Base64 string, so calling ToBase64String() on a string blows up trying to treat each character as a byte. That's exactly the "Input string was not in a correct format" error you're seeing.

The fix is a type check before the conversion:

if ($currentCertificateAuthorities.certificate -is [System.Byte[]]) { $certValue = [System.Convert]::ToBase64String($currentCertificateAuthorities.certificate) } else { $certValue = $currentCertificateAuthorities.certificate } $myCertificateAuthorities.Add('Certificate', $certValue)

No other functions need touching Test-TargetResource and Export-TargetResource both go through Get-TargetResource so they're fixed automatically. Set-TargetResource goes the other direction (FromBase64String) so that was never broken.

saeekailas avatar Jun 03 '26 12:06 saeekailas