Setting it up
Microsoft 365 setup
The app registration, the permissions, and the mailbox boundary that keeps them narrow.
ContactMesh authenticates as an application, with a certificate. It never asks a recipient to sign in and never holds anybody’s password.
What it is granted, and what it is not
Section titled “What it is granted, and what it is not”| Grant | Where | For | Without it |
|---|---|---|---|
Contacts.Read | Exchange RBAC, scoped to the source mailbox | Reading the folder being published | Nothing is read from the source, so there is nothing to publish |
Contacts.ReadWrite | Exchange RBAC, scoped to the destination mailboxes | Creating and updating the managed folders | Every write is refused: no folder is created and no card is written |
User.Read.All | Graph application permission | Resolving members to mailboxes, and reading display name, principal name, user type, account state and profile photo; a directory source reads its people with it | No member resolves to a mailbox, the people picker is empty, and a directory source reads nobody |
GroupMember.Read.All | Graph application permission | Listing groups, and reading their direct members — members of a nested group do not count | Every group-driven audience resolves to nobody, and the group picker lists nothing |
Member.Read.Hidden | Graph application permission, only if an audience uses a group with hidden membership | Reading that group’s members | That one group resolves to nobody. Do not grant it otherwise |
OrgContact.Read.All | Graph application permission, only if a directory source reads organisational contacts | Listing the tenant’s organisational contacts, the address list’s entries for people outside it | That source’s rounds are refused (SourceDirectoryContactsNotPermitted) and remove nobody. Do not grant it otherwise |
Exchange.ManageAsApp | Office 365 Exchange Online application permission, only if ContactMesh keeps the scope group | Changing the scope group’s members, with a role for that group alone | Group upkeep stops with The app registration has no Exchange.ManageAsApp. Do not grant it otherwise |
Sites.Selected | Graph application permission, only if a SharePoint source reads a list, plus read granted on each of its sites | Reading the list, its columns and items, and its image column’s pictures, on the sites an administrator granted and on no other | That source’s rounds are refused (SourceSharePointNotPermitted) and remove nobody. Without the grant on the site, the permission reads nothing |
Group membership is resolved from the directory on every refresh rather than copied once, which is
why GroupMember.Read.All is not optional for anything but an audience made entirely of named
individuals.
The refusal does not name the permission
Section titled “The refusal does not name the permission”Graph refuses with a status code and nothing else, and ContactMesh records the refusal as it arrived. A
group whose members cannot be read leaves Graph user discovery request failed with HTTP 403. on its
row in the publication’s audience. “User discovery” is the client’s own label for any read that
returns users; the grant actually missing is GroupMember.Read.All.
Test sign-in does not catch it. It reads one user, so it passes on User.Read.All alone and
says nothing about groups. scripts/Test-M365Integration.ps1 reads users, groups and — when given a
group — that group’s transitive members, and names the permission behind each check.
The mailbox boundary
Section titled “The mailbox boundary”The contact permissions are granted through Exchange Online RBAC for Applications, scoped to a resource group of mailboxes, rather than as a tenant-wide Entra grant. That scoping is the boundary: the registration can reach the mailboxes in scope and is refused everywhere else, by Exchange, regardless of what the software asks for.
The older Application Access Policy mechanism uses a mail-enabled security group and still works. Microsoft labels it legacy and recommends RBAC for new deployments.
Keeping the group in step
Section titled “Keeping the group in step”A scope built on a group counts that group’s direct members only. People who sit in nested groups, or in several groups, have to be copied into it one by one, and kept there as people come and go. Group upkeep does that: the users of the groups you pick, nested groups resolved, become the scope group’s direct members, and with Remove others the users who are in none of them leave it.
Set it on the tenant’s page, Exchange tab, under Group upkeep, once Exchange scope names the group. Kept by chooses who writes:
- ContactMesh changes the group itself, every fifteen minutes. Microsoft Graph cannot change a mail-enabled
security group, so ContactMesh uses Exchange, the way Microsoft’s Exchange Online PowerShell module does, and
the registration needs more than the sync does: the
Exchange.ManageAsAppapplication permission (Office 365 Exchange Online, with admin consent) and an Exchange role that may change this one group. - Script leaves the writing to a scheduled task of your own. Download script hands out
Sync-ContactMeshScopeGroup.ps1with this tenant’s groups filled in, and ContactMesh only reads and says whether the group is in step.
A group synced from Active Directory can only be changed there, so only the script keeps one: it writes the Active Directory group, and Entra Connect carries the change up.
The role, for ContactMesh to write
Section titled “The role, for ContactMesh to write”The role group below may change the scope group and nothing else. Run it once, in Exchange Online PowerShell, with the service principal the RBAC setup created:
$group = Get-DistributionGroup -Identity 'contactmesh-mailboxes@contoso.com'New-ManagementScope -Name 'ContactMesh scope group' -RecipientRestrictionFilter "Guid -eq '$($group.Guid)'"New-RoleGroup -Name 'ContactMesh group upkeep' -Roles 'Security Group Creation and Membership' ` -CustomRecipientWriteScope 'ContactMesh scope group'Add-RoleGroupMember -Identity 'ContactMesh group upkeep' -Member '<service principal object ID>'What holds a change back
Section titled “What holds a change back”- Plan mode holds every change, as it holds every write: the round compares and says what it would do.
- A picked group that cannot be read in full changes nothing, so a failed read never empties the scope.
- More removals than Removal limit, or picked groups with nobody in them, take nobody out. The page names the people, and Remove lets that many through once.
- Adds come before removals, and a round makes at most 500 changes; the next one goes on.
- Guests, disabled accounts, users without a mailbox and the mailboxes a source reads are left out.
Each round that changes the group writes one audit entry, in counts. Exchange’s own audit log names who was added or taken out. Changes can take up to two hours to reach the mailboxes’ permissions.
The script
Section titled “The script”The script reads Entra groups through Microsoft Graph, or Active Directory groups, and writes the group in
Exchange Online or in Active Directory. Unattended, it signs in as an application with a certificate: use a
registration of its own with GroupMember.Read.All, User.Read.All and Exchange.ManageAsApp, and the role
above, so ContactMesh’s certificate stays on its host. Fill in AppId and Organization (the tenant’s
.onmicrosoft.com domain) at the top of the file.
.\Sync-ContactMeshScopeGroup.ps1 -CertificateThumbprint 'A1B2…' -WhatIfpwsh -NoProfile -File .\Sync-ContactMeshScopeGroup.ps1 -CertificateThumbprint 'A1B2…' -LogPath C:\Logs\ContactMeshIt exits with 0 when done, 2 when it held removals over -MaxRemovals, and 1 on a failure. Run it once
by hand with -Force to make held removals. On Linux, give -CertificatePath to a .pfx and its password in
CONTACTMESH_CERTIFICATE_PASSWORD.
Order of work
Section titled “Order of work”-
Create the app registration. One registration, certificate credential, no redirect URIs — it is a daemon and never signs a person in. Note its Application (client) ID and the enterprise application’s Object ID. Exchange wants the Object ID, and it is a different value from the client ID: in the Entra admin centre, Enterprise applications → the app → Object ID. Not the Object ID under App registrations, which Microsoft warns is a different value too. Store it in the tenant’s Exchange scope, or let a setup check offer it, and the commands on the tenant’s Setup tab carry it.
-
Grant the Graph permissions.
User.Read.AllandGroupMember.Read.Allas application permissions, plusMember.Read.Hiddenonly in the hidden-membership case,OrgContact.Read.Allonly for a directory source that reads organisational contacts andSites.Selectedonly for a SharePoint source, then have an administrator consent to them. An added grant that nobody consented to behaves exactly like one that was never added.Sites.Selectedreads nothing until read on each site is granted too, withNew-MgSitePermissionas A SharePoint list shows; the tenant’s Setup tab gives the command with the site filled in. -
Create the certificate and upload the public half. See Certificates.
-
Create two Exchange resource scopes — one matching the source mailbox by address, one matching the destination mailboxes — and assign
Application Contacts.Readto the first andApplication Contacts.ReadWriteto the second. One scope carrying both roles would make the source writable. The repository shipsscripts/Configure-ContactMeshGroupRbac.ps1, which does the pointer, both scopes and both assignments in one idempotent pass and then checks that the source did not acquire write.scripts/Configure-ExchangeApplicationRbac.ps1does one scope and one role per run, for a deployment that scopes by explicit mailbox list.A destination scope by group membership stores the group’s DistinguishedName in its filter. Recreating the group, converting it to cloud-managed or ending directory sync changes that name, and the scope then matches nobody without reporting an error. Run
scripts/Configure-ContactMeshGroupRbac.ps1again after any of these: it reads the name back and corrects the filter.Bringing on a tenant that another tool already writes to? Assign only
Application Contacts.Readto the destinations at first, compare what a publication would do, and addApplication Contacts.ReadWriteonce you have read the comparison. It is the one control here that Microsoft enforces rather than ContactMesh. -
Prove it. Allow 30 minutes to 2 hours first. Exchange RBAC assignments and group membership changes reach a running application slowly; a correct command that seems to have done nothing has usually not propagated yet, and re-running it will not help.
scripts/verify-graph-certificate.shauthenticates with the certificate, reads the source folder, and writes and removes a scratch contact in a destination mailbox. SetCONTACTMESH_CONTRACT_SOURCE_MAILBOXandCONTACTMESH_CONTRACT_DENIED_MAILBOXas well: the checks that a read-only source refuses a write and that an out-of-scope mailbox is refused entirely are skipped when those are unset, and a green run then proves the grant and says nothing about the boundary.On a source’s Reading tab, Run probe under Access boundary has the worker make the same checks against one recipient’s mailbox: it reads Waiting for the worker…, then Running safe probe…, and keeps what each check proved, and for which mailbox, with its age, for as long as finished work is kept. Plan mode holds the probe’s two writes as it holds every other: they read Simulated, proving nothing either way, and the probe proves them once plan mode is off.
Test-ServicePrincipalAuthorization, in the Exchange session, asks Exchange directly what the application may do. Run it against a mailbox that should be writable, then against one outside the scope. The second answer is the one to check: a scope that matches everybody looks correct until something outside it is tested.Setup check, on the tenant’s Exchange tab, joins these up: the credential, the Graph permissions, the directory, the group, the scope, each source’s permission probe and the marker round trip, in order, with the remedy for the step that is wrong. See Tenants.
Calendars
Section titled “Calendars”With the Calendars module, calendar publications write a calendar of their own into each recipient’s mailbox. That takes one more Exchange role on the scope the destinations already have, and no Entra permission:
-
Assign
Application Calendars.ReadWriteon the destination scope. Runscripts/Configure-ContactMeshGroupRbac.ps1again with-Calendarsand the arguments you gave it the first time. It adds the role on the same destination scope and leaves the source scope without it, so the application cannot write the source mailbox’s calendar; its check fails if a test destination is outside the scope or the source mailbox is inside it.Terminal window ./scripts/Configure-ContactMeshGroupRbac.ps1 `-AppId '<SYNC-APP-CLIENT-ID>' `-ServicePrincipalObjectId '<SYNC-ENTERPRISE-APP-OBJECT-ID>' `-SourceMailbox 'contacts@contoso.com' `-DestinationGroup 'ContactMesh recipients' `-TestDestinationMailbox 'alex.user@contoso.com' `-Calendars -
Prove it, after the same 30 minutes to 2 hours. A destination mailbox must show
InScopeTrue, and the source mailbox and one outside the scopeFalse:Terminal window Test-ServicePrincipalAuthorization `-Identity '<SYNC-ENTERPRISE-APP-OBJECT-ID>' `-Resource 'alex.user@contoso.com' |Where-Object RoleName -eq 'Application Calendars.ReadWrite' |Format-Table RoleName,AllowedResourceScope,InScope -
Or let the setup check say it. On the tenant’s Exchange tab, Setup check has a Calendars row once the tenant has a calendar publication. It lists one recipient’s calendars — one Exchange refused first — and a mailbox outside the scope’s, and writes nothing in either. Exchange refusing the recipient fails it, with the role assignment for the destination scope to paste; a mailbox outside the scope whose calendars list fails it too. A listing proves a calendar role reaches the mailbox, not which one, so the row also offers the test above for that mailbox:
RoleNameshould readApplication Calendars.ReadWrite.
Do not grant Calendars.Read, Calendars.ReadBasic or Calendars.ReadWrite as Entra application
permissions: either reaches every mailbox in the tenant, and the setup check warns on it. A mailbox outside
the scope reads Outside app scope on the publication’s Delivery tab, and is asked again every 15
minutes.
Calendar sources
Section titled “Calendar sources”A mailbox source reads a shared mailbox’s calendar, and writes nothing to it.
It needs exactly this: the Exchange role Application Calendars.Read on a management scope of its own,
ContactMesh calendar sources, which holds the source mailboxes and nothing else. Never put a source mailbox in the
destination scope: Application Calendars.ReadWrite there would let the application write its calendar.
-
Make the scope with the source mailbox, and assign the read role on it:
Terminal window New-ManagementScope `-Name 'ContactMesh calendar sources' `-RecipientRestrictionFilter "PrimarySmtpAddress -eq 'firmenkalender@contoso.com'"New-ManagementRoleAssignment `-Name 'ContactMesh source Calendars.Read' `-App '<SYNC-ENTERPRISE-APP-OBJECT-ID>' `-Role 'Application Calendars.Read' `-CustomResourceScope 'ContactMesh calendar sources'A second source mailbox widens the same scope rather than making another:
Terminal window Set-ManagementScope `-Identity 'ContactMesh calendar sources' `-RecipientRestrictionFilter "PrimarySmtpAddress -eq 'firmenkalender@contoso.com' -or PrimarySmtpAddress -eq 'anlaesse@contoso.com'" -
Prove it, after the same 30 minutes to 2 hours: the source mailbox must show
Application Calendars.ReadInScopeTrue, andApplication Calendars.ReadWriteFalse:Terminal window Test-ServicePrincipalAuthorization `-Identity '<SYNC-ENTERPRISE-APP-OBJECT-ID>' `-Resource 'firmenkalender@contoso.com' |Where-Object RoleName -like '*Calendars*' |Format-Table RoleName,AllowedResourceScope,InScope -
Or let the setup check say it. Setup check has a Calendar source row for each mailbox source, after Calendars. It reads the mailbox’s calendar as the source does and writes nothing. Exchange refusing it fails the row, with the two commands above to paste, filled in; a source mailbox in the destination group, or one the sync writes to, fails it too, because the destination’s role reaches it. The source’s own page shows the same commands when a read is refused.
Profile photos
Section titled “Profile photos”Recipient photos are read with the same User.Read.All grant and shown in the pickers. They are
served by Microsoft’s People/Image service rather than by the directory, so a registration that can
read a display name is not automatically one that can read a face — if photos do not appear, that is
what to check. People with no photo are shown as initials, which is the ordinary case.