microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.64k stars 503 forks source link

M365Automation pipeline fails when rewriting SecurityCompliance.schema.psm1 using M365DSC exported settings #4035

Open kochi-shunsuke opened 11 months ago

kochi-shunsuke commented 11 months ago

Description of the issue

I built my environment according to the devops whitepaper I also rewritten SecurityCompliance.schema.psm1 with the tenant settings exported by M365DSC. This causes the following error in the build pipeline:

[error]The module 'SecurityCompliance' could not be loaded. For more information, run 'Import-Module SecurityCompliance'.

Commenting out some LocaleSettings prevents errors. How do I need to modify LocaleSettings?

Microsoft 365 DSC Version

V1.23.1101.1

Which workloads are affected

Security & Compliance Center

The DSC configuration

#The following is one of several examples.
#The comment out part causes the error.
#ーーー
 SCSensitivityLabel "SCSensitivityLabel-Public"
        {
            AdvancedSettings     = @(
                MSFT_SCLabelSetting
                {
                    Key   = 'isparent'
                    Value = 'False'
                }
            );
            Comment              = "";
            ContentType          = @("File, Email");
            Credential           = $Credential;
            DisplayName          = "Public";
            Ensure               = "Present";
    <#        LocaleSettings       = @(
                MSFT_SCLabelLocaleSettings
                {
                    LocaleKey = 'displayName'
                    LabelSettings  = @(
                        MSFT_SCLabelSetting
                        {
                            Key   = 'default'
                            Value = 'Public'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'en-US'
                            Value = 'Public'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'de-DE'
                            Value = 'Öffentlich'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'es-ES'
                            Value = 'Público'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'fr-FR'
                            Value = 'Public'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'it-IT'
                            Value = 'Pubblico'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ja-JP'
                            Value = '公共'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ko-KR'
                            Value = '공개'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'pt-BR'
                            Value = 'Público'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ru-RU'
                            Value = 'Открытый доступ'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-CN'
                            Value = '公用'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-TW'
                            Value = '公用'
                        }
                    )
                }
                MSFT_SCLabelLocaleSettings
                {
                    LocaleKey = 'tooltip'
                    LabelSettings  = @(
                        MSFT_SCLabelSetting
                        {
                            Key   = 'default'
                            Value = 'Business data that is specifically prepared and approved for public consumption.'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'en-US'
                            Value = 'Public'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'de-DE'
                            Value = 'Öffentlich'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'es-ES'
                            Value = 'Público'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'fr-FR'
                            Value = 'Public'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'it-IT'
                            Value = 'Pubblico'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ja-JP'
                            Value = '公共'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ko-KR'
                            Value = '공개'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'pt-BR'
                            Value = 'Público'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ru-RU'
                            Value = 'Открытый доступ'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-CN'
                            Value = '公用'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-TW'
                            Value = '公用'
                        }
                    )
                }
            );
    #>        Name                 = "defa4170-0d19-0005-0001-bc88714345d2";
            Priority             = 4;
            Tooltip              = "Business data that is specifically prepared and approved for public consumption.";
        }
#ーーー

#I don't know why, but I don't get the error if I don't comment out the following:
#ーーー
SCSensitivityLabel "SCSensitivityLabel-General"
        {
            AdvancedSettings     = @(
                MSFT_SCLabelSetting
                {
                    Key   = 'isparent'
                    Value = 'False'
                }
            );
            Comment              = "";
            ContentType          = @("File, Email");
            Credential           = $Credential;
            DisplayName          = "General";
            Ensure               = "Present";
            LocaleSettings       = @(
                MSFT_SCLabelLocaleSettings
                {
                    LocaleKey = 'displayName'
                    LabelSettings  = @(
                        MSFT_SCLabelSetting
                        {
                            Key   = 'default'
                            Value = 'General'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'en-US'
                            Value = 'General'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'de-DE'
                            Value = 'Allgemein'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'es-ES'
                            Value = 'General'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'fr-FR'
                            Value = 'Général'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'it-IT'
                            Value = 'Generale'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ja-JP'
                            Value = '一般'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ko-KR'
                            Value = '일반'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'pt-BR'
                            Value = 'Geral'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ru-RU'
                            Value = 'Общее'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-CN'
                            Value = '常规'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-TW'
                            Value = '一般'
                        }
                    )
                }
                MSFT_SCLabelLocaleSettings
                {
                    LocaleKey = 'tooltip'
                    LabelSettings  = @(
                        MSFT_SCLabelSetting
                        {
                            Key   = 'default'
                            Value = 'Business data that is not intended for public consumption. However, this can be shared with external partners, as required. Examples include a company internal telephone directory, organizational charts, internal standards, and most internal communication.'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'en-US'
                            Value = 'General'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'de-DE'
                            Value = 'Allgemein'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'es-ES'
                            Value = 'General'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'fr-FR'
                            Value = 'Général'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'it-IT'
                            Value = 'Generale'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ja-JP'
                            Value = '一般'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ko-KR'
                            Value = '일반'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'pt-BR'
                            Value = 'Geral'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'ru-RU'
                            Value = 'Общее'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-CN'
                            Value = '常规'
                        }
                        MSFT_SCLabelSetting
                        {
                            Key   = 'zh-TW'
                            Value = '一般'
                        }
                    )
                }
            );
            Name                 = "defa4170-0d19-0005-0002-bc88714345d2";
            Priority             = 5;
            Tooltip              = "Business data that is not intended for public consumption. However, this can be shared with external partners, as required. Examples include a company internal telephone directory, organizational charts, internal standards, and most internal communication.";
        }
#ーーー

Verbose logs showing the problem

No response

Environment Information + PowerShell Version

No response

andikrueger commented 10 months ago

Could you try to compile your configuration manually to gather additional information about the issue?

kochi-shunsuke commented 10 months ago

Compiling the configuration manually did not show any errors. The command executed and the result are:

PS C:\test> .\M365DSC-Test-Config-SC-20240122.ps1 -Credential $Credential

    Directory: C:\test\M365DSC-Test-Config-SC-20240122

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        1/22/2024  12:30 AM         516262 localhost.mof

However, the error in the build pipeline continue when running from AzureDevOps.

What should I do next?

andikrueger commented 10 months ago

This looks strange. Any chance to run Import-Module .... -Verbose on the psd1 file for the security compliance configuration?

kochi-shunsuke commented 10 months ago

OK, I tried it. And I attached the result as a file. result_import-module_verbose.txt

andikrueger commented 10 months ago

This looks like an encoding issue. Could you please get the file encoding of this file?

kochi-shunsuke commented 10 months ago

I get the encoding of the psd1 and psm1 files for the security compliance configuration. They are UTF-8.

Are there any other files that I should get the encoding?

kochi-shunsuke commented 10 months ago

@andikrueger Is there a recommended encoding? Also, are there any languages not available in M365 DSC?

ykuijs commented 1 month ago

The new version of the whitepaper has been published this morning! It took a little bit longer due to some other improvements and bugs we encountered during testing. My apologies for that!

You can find the announcement here and the new version of the whitepaper here.

Please try again with the new scripts and let us know the results. Many improvements have been made, including an encoding check.