Set up Maester in GitLab
This guide will walk you through setting up Maester in GitLab and automate the running of tests using GitLab Pipelines (jobs).
Set up your Maester tests project (group) in GitLab
Section titled “Set up your Maester tests project (group) in GitLab”Pre-requisites
Section titled “Pre-requisites”- If you are new to GitLab, create an account at gitlab.com for organizations
- If you use GitLab.com, you can run your CI/CD jobs on GitLab-hosted runners.
Create a blank new project to always use the latest available public Maester Tests
Section titled “Create a blank new project to always use the latest available public Maester Tests”- On the left sidebar, at the top, select ‘Create new ()’ and ‘New project/repository’.
- Select Create a blank project
- Repository name: E.g.
maester-tests - Private: Select this option to keep your tests private
- Repository name: E.g.
There are many ways to authenticate with Microsoft Entra from GitHub Actions. We recommend using workload identity federation as it is more secure, requires less maintenance and is the easiest to set up.
If you’re unable to use more advanced options like certificates stored in Azure Key Vault, which need an Azure subscription, there’s also guidance available for using client secrets.
- Workload identity federation (recommended) uses OpenID Connect (OIDC) to authenticate with Microsoft Entra protected resources without using secrets.
- Client secret uses a secret to authenticate with Microsoft Entra protected resources.
Create an Entra Application
Section titled “Create an Entra Application”- Open Entra admin center > Identity > Applications > App registrations
- Tip: enappreg.cmd.ms is a shortcut to the App registrations page.
- Select New registration
- Enter a name for the application (e.g.
Maester DevOps Account) - Select Register
Grant permissions to Microsoft Graph
Section titled “Grant permissions to Microsoft Graph”- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select Microsoft Graph > Application permissions
- Search for each of the permissions and check the box next to each permission:
- AuditLog.Read.All
- DeviceManagementConfiguration.Read.All
- DeviceManagementManagedDevices.Read.All
- DeviceManagementRBAC.Read.All
- DeviceManagementServiceConfig.Read.All
- Directory.Read.All
- DirectoryRecommendations.Read.All
- EntitlementManagement.Read.All
- IdentityRiskEvent.Read.All
- NetworkAccess.Read.All
- OnPremDirectorySynchronization.Read.All
- OrgSettings-AppsAndServices.Read.All
- OrgSettings-Forms.Read.All
- Policy.Read.All
- Policy.Read.ConditionalAccess
- Reports.Read.All
- ReportSettings.Read.All
- RoleEligibilitySchedule.Read.Directory
- RoleManagement.Read.All
- RoleManagementAlert.Read.Directory
- SecurityIdentitiesSensors.Read.All
- SecurityIdentitiesHealth.Read.All
- SharePointTenantSettings.Read.All
- ThreatHunting.Read.All
- UserAuthenticationMethod.Read.All
To run preview Agent ID tests, also grant these application permissions:
- AgentIdentity.Read.All
- AgentIdentityBlueprint.Read.All
- AgentIdentityBlueprintPrincipal.Read.All
- Application.Read.All
- Optionally, search for each of the permissions if you want to allow privileged permissions:
- ReportSettings.ReadWrite.All
- Required to disable report obfuscation
- ReportSettings.ReadWrite.All
- Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
(Optional) Grant permissions to Exchange Online
(Optional) Grant permissions to Exchange Online
Section titled “(Optional) Grant permissions to Exchange Online”The Exchange Online role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Exchange Online permissions are necessary to support tests that validate Exchange Online configurations, such as the CISA tests.
- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select APIs that my organization uses > search for Office 365 Exchange Online > Application permissions
- Search for
Exchange.ManageAsApp - Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
- Connect to the Exchange Online Management tools and use the following to set the appropriate permissions:
New-ServicePrincipal -AppId <Application ID> -ObjectId <Object ID> -DisplayName <Name>New-ManagementRoleAssignment -Role "View-Only Configuration" -App <DisplayName from previous command>(Optional) Grant permissions to Teams
(Optional) Grant permissions to Teams
Section titled “(Optional) Grant permissions to Teams”The Teams role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Teams permissions are necessary to support tests that validate Teams configurations.
- Open Roles and administrators
- Search and select Teams Reader
- Select Add assigment
- Select No member selected
- Search for the name of previously created application
- Select previously created application and select Select to confirm
- Select Next to confirm
- Ensure that Active and Permanently assigned are ticked
- Enter Justification
- Select Assign to confirm
(Optional) Grant permissions to Azure
(Optional) Grant permissions to Azure
Section titled “(Optional) Grant permissions to Azure”The Azure Role-Based Access Control (RBAC) implementation uses Uniform Resource Names (URNs) with a ”/” separator for hierarchical scoping. Some resources exist within the root (e.g., ”/”) scope, and Microsoft retains strict control over them by limiting supported interactions. As a Global Administrator, you can elevate access to become authorized for these limited interactions.
The Azure RBAC permissions are necessary to support tests that validate Azure configurations, such as the CISA tests.
The following PowerShell script will enable you, with a Global Administrator role assignment, to:
- Identify the Service Principal Object ID that will be authorized as a Reader (Enterprise app Object ID)
- Install the necessary Az module and prompt for connection
- Elevate your account access to the root scope
- Create a role assignment for Reader access over the Root Scope
- Create a role assignment for Reader access over the Entra ID (i.e., aadiam provider)
- Identify the role assignment authorizing your account access to the root scope
- Delete the root scope role assignment for your account
$servicePrincipal = "<Object ID of the Entra App>"$subscription = "<Subscription ID>"Install-Module Az.Accounts -ForceInstall-Module Az.Resources -ForceConnect-AzAccount#Elevate to root scope access$elevateAccess = Invoke-AzRestMethod -Path "/providers/Microsoft.Authorization/elevateAccess?api-version=2015-07-01" -Method POST
#Assign permissions to Enterprise AppNew-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"New-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/providers/Microsoft.aadiam" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"
#Remove root scope access$assignment = Get-AzRoleAssignment -RoleDefinitionId 18d7d88d-d35e-4fb5-a5c3-7773c20a72d9|?{$_.Scope -eq "/" -and $_.SignInName -eq (Get-AzContext).Account.Id}$deleteAssignment = Invoke-AzRestMethod -Path "$($assignment.RoleAssignmentId)?api-version=2018-07-01" -Method DELETE(Optional) Grant permissions to SharePoint Online
(Optional) Grant permissions to SharePoint Online
Section titled “(Optional) Grant permissions to SharePoint Online”SharePoint Online tests require the PnP.PowerShell module and an Entra ID app registration configured for interactive login with SharePoint delegated permissions.
The SharePoint Online permissions are necessary to support tests that validate SharePoint Online configurations, such as the CISA SharePoint baseline controls.
Install PnP.PowerShell
Section titled “Install PnP.PowerShell”Install-Module PnP.PowerShell -Scope CurrentUserThe easiest way to create the required app registration is to follow the official PnP PowerShell guide:
Option A — Automatically create a new PnP app registration
Section titled “Option A — Automatically create a new PnP app registration”PnP provides a built-in cmdlet to create a dedicated app registration for interactive login. This is the quickest option and the one recommended in the PnP docs:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "Maester PnP" -Tenant [yourtenant].onmicrosoft.com -SharePointDelegatePermissions "AllSites.FullControl"This will:
- Create an Entra ID app registration with the required delegated permissions
- Configure
http://localhostas the redirect URI automatically - Prompt you to authenticate and provide consent
- Output the Client ID you will need for
Connect-Maester
If you prefer to start from the exact example in the PnP docs, run Register-PnPEntraIDAppForInteractiveLogin with their default parameters and add -SharePointDelegatePermissions "AllSites.FullControl" for Maester’s SharePoint tests.
Note: Maester’s SharePoint tests are read-only.
AllSites.FullControl(delegated) is sufficient.Important: After registering the app, open a new PowerShell session before running
Connect-Maester, as the registration process loads PnP assemblies that can conflict with Microsoft Graph.
Option B — Reuse the existing Maester app registration
Section titled “Option B — Reuse the existing Maester app registration”If you prefer not to create a separate app, you can update the Maester app registration you created earlier to also support PnP PowerShell interactive login.
1. Add the localhost redirect URI
- Open your Maester app registration in the Entra admin center
- Select Authentication > Add a platform > Mobile and desktop applications
- In the Custom redirect URIs field, enter
http://localhost(note:http, nothttps) - Select Configure
2. Add SharePoint delegated permissions
- Select API permissions > Add a permission
- Select SharePoint > Delegated permissions
- Search for and check
AllSites.FullControl - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
3. Connect using the existing Client ID
You can retrieve the Client ID of your Maester app from Graph without looking it up manually. First connect to Graph, then query for the app by its display name:
# Connect to Graph firstConnect-Maester -Service Graph
# Retrieve the Client ID of the Maester app registration$clientId = (Get-MgApplication -Filter "displayName eq 'Maester DevOps Account'").AppIdThen connect to SharePoint Online in a new session using the retrieved Client ID. The SharePoint admin URL is auto-discovered from your tenant — no need to specify it manually:
# Open a new PowerShell session, then:Connect-Maester -Service Graph,SharePointOnline -SharePointClientId $clientIdImportant: After registering the app, open a new PowerShell session before running
Connect-Maester, as PnP assemblies loaded during the session can conflict with Microsoft Graph.
Option C — App-only access (automation / non-interactive)
Section titled “Option C — App-only access (automation / non-interactive)”For unattended runs (CI pipelines, scheduled tasks) where interactive login is not possible, use application permissions with certificate-based authentication.
1. Add SharePoint application permission
- Open your app registration in the Entra admin center
- Select API permissions > Add a permission
- Select SharePoint > Application permissions
- Search for and check
Sites.FullControl.All - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
2. Upload a certificate
- Select Certificates & secrets > Certificates > Upload certificate
- Upload the public key (
.cer) of your certificate
3. Connect using Connect-Maester
Pass the certificate thumbprint directly to Connect-Maester using -SharePointCertificateThumbprint. -TenantId is required for thumbprint-based auth:
$params = @{ Service = @('Graph', 'SharePointOnline') SharePointClientId = "<App Client ID>" SharePointCertificateThumbprint = "<Certificate Thumbprint>" TenantId = "<Tenant ID or domain>"}Connect-Maester @paramsThe certificate must be present in the current user’s Windows certificate store. The SharePoint admin URL is auto-discovered — supply -SharePointAdminUrl to override it if needed.
Use the Client ID from Option A or Option B when connecting:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>"The SharePoint admin URL is auto-discovered from your tenant’s initial domain. If auto-discovery does not work (e.g. government or custom-domain tenants), supply it explicitly:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -SharePointAdminUrl "https://contoso-admin.sharepoint.com"For device code flow (e.g. non-interactive sessions):
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -UseDeviceCode(Optional) Grant Dataverse permissions for Copilot Studio tests
(Optional) Grant Dataverse permissions for Copilot Studio
Section titled “(Optional) Grant Dataverse permissions for Copilot Studio”Dataverse access is required for the Copilot Studio security tests (MT.1113–MT.1122) that evaluate Copilot Studio agent configurations.
Create an Application User in Power Platform
Section titled “Create an Application User in Power Platform”- Go to the Power Platform Admin Center → select your environment → Settings → Users + permissions → Application users
- Click New app user → Add an app → select the app registration created above
- Select the correct Business unit
- Assign a security role with read access:
- Basic User for simplicity, or
- A custom role (e.g.
Maester Security Reader) with Organization-level Read on: Agent (bot), Agent component (botcomponent), User (systemuser), and Connection Reference (connectionreference)
- Click Create
Configure Maester
Section titled “Configure Maester”Add the environment URL to maester-config.json:
{ "GlobalSettings": { "DataverseEnvironmentUrl": "https://org12345.crm.dynamics.com" }}Add federated credentials
Section titled “Add federated credentials”- Select Certificates & secrets
- Select Federated credentials, select Add credential
- For Federated credential scenario, select Other issuer
- Fill in the following fields
- Issuer: Your GitLab organization url or standard gitlab url
https://gitlab.com - Type: Select Explicit subject identifier
- Value:
project_path:<mygroup>/<myproject>:ref_type:branch:ref:<branch>E.g.project_path:maester/maester-tests:ref_type:branch:ref:main - Name: Credential name E.g.
gitlab-federated-identity - Description: Credential name E.g.
GitLab service account federated identity - Audience: Your GitLab organization url or standard gitlab url
https://gitlab.com
- Issuer: Your GitLab organization url or standard gitlab url
- Select Add
📖 For detailed Azure integration guidance: GitLab provides comprehensive documentation on integrating with Azure services. See the GitLab Azure integration guide for advanced authentication patterns, best practices, and troubleshooting tips.
Create GitLab variables
Section titled “Create GitLab variables”- Open your
maester-testsGitLab project and go to Settings - Select CI/CD > Variables > CI/CD Variables
- Add the three secrets listed below by selecting Add variable
- To look up these values you will need to use the Entra portal, open the application you created earlier and copy the following values from the Overview page:
- Visibility: Visible, Key:
AZURE_TENANT_ID, Value: The Directory (tenant) ID of the Entra tenant - Visibility: Visible, Key:
AZURE_CLIENT_ID, Value: The Application (client) ID of the Entra application you created
- Visibility: Visible, Key:
- Define which services should be connected using the other variables in order to run the corresponding tests.
- Visibility: Visible, Key:
CONNECTION_EXCHANGE, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not - Visibility: Visible, Key:
CONNECTION_PURVIEW, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not - Visibility: Visible, Key:
CONNECTION_TEAMS, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not
- Visibility: Visible, Key:
- Save each secret by selecting Add variable at the bottom.
Create .gitlab-ci.yml file (or use pipeline editor)
Section titled “Create .gitlab-ci.yml file (or use pipeline editor)”stages: - test
run_maester_tests_inline: stage: test image: mcr.microsoft.com/microsoftgraph/powershell:latest id_tokens: AZURE_FEDERATED_TOKEN: aud: https://gitlab.com variables: TENANTID: $AZURE_TENANT_ID CLIENTID: $AZURE_CLIENT_ID CONNECTION_EXCHANGE: $CONNECTION_EXCHANGE CONNECTION_PURVIEW: $CONNECTION_PURVIEW CONNECTION_TEAMS: $CONNECTION_TEAMS
before_script: - mkdir test-results - mkdir public-tests - pwsh -c 'Write-host "Running in project $env:CI_PROJECT_NAME with results at $env:CI_JOB_URL ($env:CI_JOB_URL)."' script: - | pwsh -Command ' #region prepare execution # Install Maester #Install-Module Maester -AllowPrerelease -Force Install-Module Maester -Force Install-Module Az.Accounts -Force
# Latest public tests Set-Location public-tests Install-MaesterTests Set-Location ..
# Declare functions function Get-AccessToken { param([string]$Scope)
$TokenBody = @{ grant_type = "client_credentials" client_id = $env:AZURE_CLIENT_ID client_assertion_type = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" client_assertion = $env:AZURE_FEDERATED_TOKEN.Trim() scope = $Scope }
$Response = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$env:AZURE_TENANT_ID/oauth2/v2.0/token" -Method POST -Body $TokenBody -ContentType "application/x-www-form-urlencoded" return $Response.access_token }
# Configure test results $PesterConfiguration = New-PesterConfiguration $PesterConfiguration.Output.Verbosity = "None" Write-Host "Pester verbosity level set to: $($PesterConfiguration.Output.Verbosity.Value)"
$MaesterParameters = @{ Path = "public-tests" PesterConfiguration = $PesterConfiguration OutputFolder = "test-results" OutputFolderFileName = "test-results" PassThru = $true }
$MaesterParameters.Add("DisableTelemetry", $false ) Write-Host "Disable pester telemetry set to: $($MaesterParameters.DisableTelemetry)"
$AdditionalConnections = @{ Exchange = [System.Convert]::ToBoolean($env:CONNECTION_EXCHANGE) Purview = [System.Convert]::ToBoolean($env:CONNECTION_PURVIEW) Teams = [System.Convert]::ToBoolean($env:CONNECTION_TEAMS) }
Write-Host "Additional connections configuration:" $AdditionalConnections.GetEnumerator() | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
#endregion prepare execution #region connect to services
# Connect as service principal Write-Host "Connect service principal" Connect-AzAccount -ServicePrincipal -Tenant $env:AZURE_TENANT_ID -ApplicationId $env:AZURE_CLIENT_ID -FederatedToken $env:AZURE_FEDERATED_TOKEN | Out-Null
# Get Graph token and connect to Microsoft Graph Write-Host "Connect Graph" $graphToken = (Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com").Token Connect-MgGraph -AccessToken $graphToken -NoWelcome
# Connect to Exchange Online and Purview if ($AdditionalConnections.Exchange -eq $true -or $AdditionalConnections.Purview -eq $true) { Install-Module -Name ExchangeOnlineManagement -Force
# Get Exchange Online token using Az authentication $exchangeToken = Get-AccessToken -Scope "https://outlook.office365.com/.default"
if ($AdditionalConnections.Exchange -eq $true) { Write-Host "Connect Exchange" Connect-ExchangeOnline -AccessToken $exchangeToken -Organization $env:AZURE_TENANT_ID -ShowBanner:$false }
if ($AdditionalConnections.Purview -eq $true) { $domains = Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/domains?`$select=id,isDefault" $primaryDomain = $domains.value | Where-Object { $_.isDefault -eq $true } | Select-Object -ExpandProperty id
Write-Host "Connect Purview" Connect-IPPSSession -AccessToken $exchangeToken -Organization $primaryDomain -ShowBanner:$false } }
# Connect to Microsoft Teams if ($AdditionalConnections.Teams -eq $true) { Install-Module -Name MicrosoftTeams -Force
Write-Host "Connect Teams"
# Get Graph token using federated credentials $graphToken = Get-AccessToken -Scope "https://graph.microsoft.com/.default"
# Get Teams token using federated credentials $teamsToken = Get-AccessToken -Scope "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default" # Microsoft Teams Application ID
# Connect to Microsoft Teams with both tokens Connect-MicrosoftTeams -AccessTokens @("$graphToken", "$teamsToken") }
#endregion connect to services
#region run tests
# Run Maester tests #$results = Invoke-Maester -Path public-tests -PesterConfiguration $PesterConfiguration -OutputFolder test-results -OutputFolderFileName "test-results" -PassThru $results = Invoke-Maester @MaesterParameters
#endregion run tests #region end script
# View summary report $results | Format-List Result, FailedCount, PassedCount, SkippedCount, TotalCount, TenantId, TenantName, CurrentVersion, LatestVersion
# Flag status to GitLab if ($results.Result -ne "Passed") { Write-Warning "Status = $($results.Result): see Maester Test Report for details." } #endregion end script ' after_script: - pwsh -c 'Write-host "Report can be opened at ($env:CI_JOB_URL/artifacts/external_file/test-results/test-results.html)."' artifacts: when: on_success paths: - test-results/ expire_in: 1 week
rules: - if: '$CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web"'Create an Entra Application
Section titled “Create an Entra Application”- Open Entra admin center > Identity > Applications > App registrations
- Tip: enappreg.cmd.ms is a shortcut to the App registrations page.
- Select New registration
- Enter a name for the application (e.g.
Maester DevOps Account) - Select Register
Grant permissions to Microsoft Graph
Section titled “Grant permissions to Microsoft Graph”- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select Microsoft Graph > Application permissions
- Search for each of the permissions and check the box next to each permission:
- AuditLog.Read.All
- DeviceManagementConfiguration.Read.All
- DeviceManagementManagedDevices.Read.All
- DeviceManagementRBAC.Read.All
- DeviceManagementServiceConfig.Read.All
- Directory.Read.All
- DirectoryRecommendations.Read.All
- EntitlementManagement.Read.All
- IdentityRiskEvent.Read.All
- NetworkAccess.Read.All
- OnPremDirectorySynchronization.Read.All
- OrgSettings-AppsAndServices.Read.All
- OrgSettings-Forms.Read.All
- Policy.Read.All
- Policy.Read.ConditionalAccess
- Reports.Read.All
- ReportSettings.Read.All
- RoleEligibilitySchedule.Read.Directory
- RoleManagement.Read.All
- RoleManagementAlert.Read.Directory
- SecurityIdentitiesSensors.Read.All
- SecurityIdentitiesHealth.Read.All
- SharePointTenantSettings.Read.All
- ThreatHunting.Read.All
- UserAuthenticationMethod.Read.All
To run preview Agent ID tests, also grant these application permissions:
- AgentIdentity.Read.All
- AgentIdentityBlueprint.Read.All
- AgentIdentityBlueprintPrincipal.Read.All
- Application.Read.All
- Optionally, search for each of the permissions if you want to allow privileged permissions:
- ReportSettings.ReadWrite.All
- Required to disable report obfuscation
- ReportSettings.ReadWrite.All
- Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
(Optional) Grant permissions to Exchange Online
(Optional) Grant permissions to Exchange Online
Section titled “(Optional) Grant permissions to Exchange Online”The Exchange Online role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Exchange Online permissions are necessary to support tests that validate Exchange Online configurations, such as the CISA tests.
- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select APIs that my organization uses > search for Office 365 Exchange Online > Application permissions
- Search for
Exchange.ManageAsApp - Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
- Connect to the Exchange Online Management tools and use the following to set the appropriate permissions:
New-ServicePrincipal -AppId <Application ID> -ObjectId <Object ID> -DisplayName <Name>New-ManagementRoleAssignment -Role "View-Only Configuration" -App <DisplayName from previous command>(Optional) Grant permissions to Teams
(Optional) Grant permissions to Teams
Section titled “(Optional) Grant permissions to Teams”The Teams role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Teams permissions are necessary to support tests that validate Teams configurations.
- Open Roles and administrators
- Search and select Teams Reader
- Select Add assigment
- Select No member selected
- Search for the name of previously created application
- Select previously created application and select Select to confirm
- Select Next to confirm
- Ensure that Active and Permanently assigned are ticked
- Enter Justification
- Select Assign to confirm
(Optional) Grant permissions to Azure
(Optional) Grant permissions to Azure
Section titled “(Optional) Grant permissions to Azure”The Azure Role-Based Access Control (RBAC) implementation uses Uniform Resource Names (URNs) with a ”/” separator for hierarchical scoping. Some resources exist within the root (e.g., ”/”) scope, and Microsoft retains strict control over them by limiting supported interactions. As a Global Administrator, you can elevate access to become authorized for these limited interactions.
The Azure RBAC permissions are necessary to support tests that validate Azure configurations, such as the CISA tests.
The following PowerShell script will enable you, with a Global Administrator role assignment, to:
- Identify the Service Principal Object ID that will be authorized as a Reader (Enterprise app Object ID)
- Install the necessary Az module and prompt for connection
- Elevate your account access to the root scope
- Create a role assignment for Reader access over the Root Scope
- Create a role assignment for Reader access over the Entra ID (i.e., aadiam provider)
- Identify the role assignment authorizing your account access to the root scope
- Delete the root scope role assignment for your account
$servicePrincipal = "<Object ID of the Entra App>"$subscription = "<Subscription ID>"Install-Module Az.Accounts -ForceInstall-Module Az.Resources -ForceConnect-AzAccount#Elevate to root scope access$elevateAccess = Invoke-AzRestMethod -Path "/providers/Microsoft.Authorization/elevateAccess?api-version=2015-07-01" -Method POST
#Assign permissions to Enterprise AppNew-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"New-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/providers/Microsoft.aadiam" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"
#Remove root scope access$assignment = Get-AzRoleAssignment -RoleDefinitionId 18d7d88d-d35e-4fb5-a5c3-7773c20a72d9|?{$_.Scope -eq "/" -and $_.SignInName -eq (Get-AzContext).Account.Id}$deleteAssignment = Invoke-AzRestMethod -Path "$($assignment.RoleAssignmentId)?api-version=2018-07-01" -Method DELETE(Optional) Grant permissions to SharePoint Online
(Optional) Grant permissions to SharePoint Online
Section titled “(Optional) Grant permissions to SharePoint Online”SharePoint Online tests require the PnP.PowerShell module and an Entra ID app registration configured for interactive login with SharePoint delegated permissions.
The SharePoint Online permissions are necessary to support tests that validate SharePoint Online configurations, such as the CISA SharePoint baseline controls.
Install PnP.PowerShell
Section titled “Install PnP.PowerShell”Install-Module PnP.PowerShell -Scope CurrentUserThe easiest way to create the required app registration is to follow the official PnP PowerShell guide:
Option A — Automatically create a new PnP app registration
Section titled “Option A — Automatically create a new PnP app registration”PnP provides a built-in cmdlet to create a dedicated app registration for interactive login. This is the quickest option and the one recommended in the PnP docs:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "Maester PnP" -Tenant [yourtenant].onmicrosoft.com -SharePointDelegatePermissions "AllSites.FullControl"This will:
- Create an Entra ID app registration with the required delegated permissions
- Configure
http://localhostas the redirect URI automatically - Prompt you to authenticate and provide consent
- Output the Client ID you will need for
Connect-Maester
If you prefer to start from the exact example in the PnP docs, run Register-PnPEntraIDAppForInteractiveLogin with their default parameters and add -SharePointDelegatePermissions "AllSites.FullControl" for Maester’s SharePoint tests.
Note: Maester’s SharePoint tests are read-only.
AllSites.FullControl(delegated) is sufficient.Important: After registering the app, open a new PowerShell session before running
Connect-Maester, as the registration process loads PnP assemblies that can conflict with Microsoft Graph.
Option B — Reuse the existing Maester app registration
Section titled “Option B — Reuse the existing Maester app registration”If you prefer not to create a separate app, you can update the Maester app registration you created earlier to also support PnP PowerShell interactive login.
1. Add the localhost redirect URI
- Open your Maester app registration in the Entra admin center
- Select Authentication > Add a platform > Mobile and desktop applications
- In the Custom redirect URIs field, enter
http://localhost(note:http, nothttps) - Select Configure
2. Add SharePoint delegated permissions
- Select API permissions > Add a permission
- Select SharePoint > Delegated permissions
- Search for and check
AllSites.FullControl - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
3. Connect using the existing Client ID
You can retrieve the Client ID of your Maester app from Graph without looking it up manually. First connect to Graph, then query for the app by its display name:
# Connect to Graph firstConnect-Maester -Service Graph
# Retrieve the Client ID of the Maester app registration$clientId = (Get-MgApplication -Filter "displayName eq 'Maester DevOps Account'").AppIdThen connect to SharePoint Online in a new session using the retrieved Client ID. The SharePoint admin URL is auto-discovered from your tenant — no need to specify it manually:
# Open a new PowerShell session, then:Connect-Maester -Service Graph,SharePointOnline -SharePointClientId $clientIdImportant: After registering the app, open a new PowerShell session before running
Connect-Maester, as PnP assemblies loaded during the session can conflict with Microsoft Graph.
Option C — App-only access (automation / non-interactive)
Section titled “Option C — App-only access (automation / non-interactive)”For unattended runs (CI pipelines, scheduled tasks) where interactive login is not possible, use application permissions with certificate-based authentication.
1. Add SharePoint application permission
- Open your app registration in the Entra admin center
- Select API permissions > Add a permission
- Select SharePoint > Application permissions
- Search for and check
Sites.FullControl.All - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
2. Upload a certificate
- Select Certificates & secrets > Certificates > Upload certificate
- Upload the public key (
.cer) of your certificate
3. Connect using Connect-Maester
Pass the certificate thumbprint directly to Connect-Maester using -SharePointCertificateThumbprint. -TenantId is required for thumbprint-based auth:
$params = @{ Service = @('Graph', 'SharePointOnline') SharePointClientId = "<App Client ID>" SharePointCertificateThumbprint = "<Certificate Thumbprint>" TenantId = "<Tenant ID or domain>"}Connect-Maester @paramsThe certificate must be present in the current user’s Windows certificate store. The SharePoint admin URL is auto-discovered — supply -SharePointAdminUrl to override it if needed.
Use the Client ID from Option A or Option B when connecting:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>"The SharePoint admin URL is auto-discovered from your tenant’s initial domain. If auto-discovery does not work (e.g. government or custom-domain tenants), supply it explicitly:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -SharePointAdminUrl "https://contoso-admin.sharepoint.com"For device code flow (e.g. non-interactive sessions):
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -UseDeviceCode(Optional) Grant Dataverse permissions for Copilot Studio tests
(Optional) Grant Dataverse permissions for Copilot Studio
Section titled “(Optional) Grant Dataverse permissions for Copilot Studio”Dataverse access is required for the Copilot Studio security tests (MT.1113–MT.1122) that evaluate Copilot Studio agent configurations.
Create an Application User in Power Platform
Section titled “Create an Application User in Power Platform”- Go to the Power Platform Admin Center → select your environment → Settings → Users + permissions → Application users
- Click New app user → Add an app → select the app registration created above
- Select the correct Business unit
- Assign a security role with read access:
- Basic User for simplicity, or
- A custom role (e.g.
Maester Security Reader) with Organization-level Read on: Agent (bot), Agent component (botcomponent), User (systemuser), and Connection Reference (connectionreference)
- Click Create
Configure Maester
Section titled “Configure Maester”Add the environment URL to maester-config.json:
{ "GlobalSettings": { "DataverseEnvironmentUrl": "https://org12345.crm.dynamics.com" }}Create a client secret
Section titled “Create a client secret”- Select Certificates & secrets > Client secrets > New client secret
- Enter a description for the secret (e.g.
Maester DevOps Secret) - Select Add
- Copy the value of the secret, we will use this value in the Azure Pipeline
Create GitLab variables
Section titled “Create GitLab variables”- Open your
maester-testsGitLab project and go to Settings - Select CI/CD > Variables > CI/CD Variables
- Add the three secrets listed below by selecting Add variable
- To look up these values you will need to use the Entra portal, open the application you created earlier and copy the following values from the Overview page:
- Visibility: Visible, Key:
AZURE_TENANT_ID, Value: The Directory (tenant) ID of the Entra tenant - Visibility: Visible, Key:
AZURE_CLIENT_ID, Value: The Application (client) ID of the Entra application you created - Visibility: Masked and hidden, Key:
AZURE_CLIENT_SECRET, Value: The client secret you copied in the previous step
- Visibility: Visible, Key:
- Define which services should be connected using the other variables in order to run the corresponding tests.
- Visibility: Visible, Key:
CONNECTION_EXCHANGE, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not - Visibility: Visible, Key:
CONNECTION_PURVIEW, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not - Visibility: Visible, Key:
CONNECTION_TEAMS, Value: “true” if you want to connect to the service and execute tests for this service too, “false” if not
- Visibility: Visible, Key:
- Save each secret by selecting Add variable at the bottom.
Create .gitlab-ci.yml file (or use pipeline editor)
Section titled “Create .gitlab-ci.yml file (or use pipeline editor)”stages: - test
run_maester_tests_inline: stage: test image: mcr.microsoft.com/microsoftgraph/powershell:latest variables: TENANTID: $AZURE_TENANT_ID CLIENTID: $AZURE_CLIENT_ID CLIENTSECRET: $AZURE_CLIENT_SECRET CONNECTION_EXCHANGE: $CONNECTION_EXCHANGE CONNECTION_PURVIEW: $CONNECTION_PURVIEW CONNECTION_TEAMS: $CONNECTION_TEAMS
before_script: - mkdir test-results - mkdir public-tests - pwsh -c 'Write-host "Running in project $env:CI_PROJECT_NAME with results at $env:CI_JOB_URL ($env:CI_JOB_URL)."' script: - | pwsh -Command ' #region prepare execution # Install Maester #Install-Module Maester -AllowPrerelease -Force Install-Module Maester -Force
# Latest public tests Set-Location public-tests Install-MaesterTests Set-Location ..
# Declare functions function Get-AccessToken { param([string]$Scope)
$TokenBody = @{ Grant_Type = "client_credentials" Scope = $Scope Client_Id = $env:AZURE_CLIENT_ID Client_Secret = $env:AZURE_CLIENT_SECRET } $Response = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$env:AZURE_TENANT_ID/oauth2/v2.0/token" -Method POST -Body $TokenBody -ContentType "application/x-www-form-urlencoded" return $Response.access_token }
# Configure test results $PesterConfiguration = New-PesterConfiguration $PesterConfiguration.Output.Verbosity = "None" Write-Host "Pester verbosity level set to: $($PesterConfiguration.Output.Verbosity.Value)"
$MaesterParameters = @{ Path = "public-tests" PesterConfiguration = $PesterConfiguration OutputFolder = "test-results" OutputFolderFileName = "test-results" PassThru = $true }
$MaesterParameters.Add("DisableTelemetry", $false ) Write-Host "Disable pester telemetry set to: $($MaesterParameters.DisableTelemetry)"
$AdditionalConnections = @{ Exchange = [System.Convert]::ToBoolean($env:CONNECTION_EXCHANGE) Purview = [System.Convert]::ToBoolean($env:CONNECTION_PURVIEW) Teams = [System.Convert]::ToBoolean($env:CONNECTION_TEAMS) }
Write-Host "Additional connections configuration:" $AdditionalConnections.GetEnumerator() | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
# Connect to Microsoft Graph Write-Host "Connect Graph" $clientSecret = ConvertTo-SecureString -AsPlainText $env:AZURE_CLIENT_SECRET -Force [pscredential] $clientSecretCredential = New-Object System.Management.Automation.PSCredential($env:AZURE_CLIENT_ID, $clientSecret) Connect-MgGraph -TenantId $env:AZURE_TENANT_ID -ClientSecretCredential $clientSecretCredential -NoWelcome
# Connect to Exchange Online and Purview if ($AdditionalConnections.Exchange -eq $true -or $AdditionalConnections.Purview -eq $true) { Install-Module -Name ExchangeOnlineManagement -Force
# Get Exchange Online token using $exchangeToken = Get-AccessToken -Scope "https://outlook.office365.com/.default"
if ($AdditionalConnections.Exchange -eq $true) { Write-Host "Connect Exchange" Connect-ExchangeOnline -AccessToken $exchangeToken -Organization $env:AZURE_TENANT_ID -ShowBanner:$false }
if ($AdditionalConnections.Purview -eq $true) { $domains = Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/domains?`$select=id,isDefault" $primaryDomain = $domains.value | Where-Object { $_.isDefault -eq $true } | Select-Object -ExpandProperty id
Write-Host "Connect Purview" Connect-IPPSSession -AccessToken $exchangeToken -Organization $primaryDomain -ShowBanner:$false }
}
# Connect to Microsoft Teams if ($AdditionalConnections.Teams -eq $true) { Install-Module -Name MicrosoftTeams -Force
Write-Host "Connect Teams"
# Get Graph token using federated credentials $graphToken = Get-AccessToken -Scope "https://graph.microsoft.com/.default"
# Get Teams token using federated credentials $teamsToken = Get-AccessToken -Scope "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default" # Microsoft Teams Application ID
Connect-MicrosoftTeams -AccessTokens @("$graphToken", "$teamsToken") }
#endregion connect to services #region run tests
# Run Maester tests #$results = Invoke-Maester -Path public-tests -PesterConfiguration $PesterConfiguration -OutputFolder test-results -OutputFolderFileName "test-results" -PassThru $results = Invoke-Maester @MaesterParameters
#endregion run tests #region end script
# View summary report $results | Format-List Result, FailedCount, PassedCount, SkippedCount, TotalCount, TenantId, TenantName, CurrentVersion, LatestVersion
# Flag status to GitLab if ($results.Result -ne "Passed") { Write-Warning "Status = $($results.Result): see Maester Test Report for details." } #endregion end script ' after_script: - pwsh -c 'Write-host "Report can be opened at ($env:CI_JOB_URL/artifacts/external_file/test-results/test-results.html)."' artifacts: when: on_success paths: - test-results/ expire_in: 1 week
rules: - if: '$CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web"'Manually running the Maester tests
Section titled “Manually running the Maester tests”To manually run the Maester tests workflow
- Open your
maester-testsGitLab project and go to Build - Select Piplines from the left pane
- Select New pipline on the right top button
- And again New pipline to run new pipeline
Viewing the test results
Section titled “Viewing the test results”- Open your
maester-testsGitLab project and go to Build - Select Artifacts from the left pane
- Search a artifact to view the results e.g.
run_maester_tests_* - Select browse on the right to open the folder
test-results
Summary view A summary view is not available with GitLab in comparison to GitHub.