Skip to content

Completely isolating Microsoft.Graph.Authentication solving dependency issues - #3789

Merged
Ramses Sanchez-Hernandez (ramsessanchez) merged 1 commit into
microsoftgraph:mainfrom
svrooij:feature/complete-isolation
Sep 23, 2026
Merged

Ramses Sanchez-Hernandez (ramsessanchez) merged 1 commit into
microsoftgraph:mainfrom
svrooij:feature/complete-isolation

Conversation

@svrooij

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request

  • Isolating Microsoft.Graph.Authentication dll to not have any external dependencies, moved to core
  • Create AssemblyLoadContext for PS7+ and load .Core with all dependencies there
  • Zero dependencies are leaked into the Default AssemblyLoadContext as verified by a test loading a conflicting Microsoft.Identity.Client version there.

Other links

@ramsessanchez

Copy link
Copy Markdown
Contributor

Thank you Stephan van Rooij (@svrooij) , this is amazing restructuring to achieve full isolation.

approving, passed on test build #3791

@Mike-Crowley

Mike Crowley (Mike-Crowley) commented Sep 25, 2026 •

Copy link
Copy Markdown

A consideration for the release notes, since the PR description doesn't mention it: once the auth engine and its dependencies load into the private context, PowerShell scripts on PS7 can no longer reference the module's internal .NET types by name. Two common patterns break:

  • [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance (how scripts pull the raw access token out of the session, since Get-MgContext doesn't expose it)
  • catch [Microsoft.Graph.PowerShell.AuthenticationException] (this PR had to rewrite that same catch in its own Permissions.ps1)

The Loader README documents this, but a breaking-change note would head off a wave of "type not found" issues.

@michaelmsonne

On time - so nice to see Stephan van Rooij (@svrooij) ! 🙏

@svrooij

Copy link
Copy Markdown
Contributor Author

A consideration for the release notes, since the PR description doesn't mention it: once the auth engine and its dependencies load into the private context, PowerShell scripts on PS7 can no longer reference the module's internal .NET types by name. Two common patterns break:

  • [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance (how scripts pull the raw access token out of the session, since Get-MgContext doesn't expose it)
  • catch [Microsoft.Graph.PowerShell.AuthenticationException] (this PR had to rewrite that same catch in its own Permissions.ps1)

The Loader README documents this, but a breaking-change note would head off a wave of "type not found" issues.

Ramses Sanchez-Hernandez (@ramsessanchez) it seems people were using undocumented features that were possible because of the dlls leaking to the default assembly context. The exception might need a decent sample, shall I create a separate issue for the pull raw access token from session use-case?

#securityhat -> Should the get raw access token command be protected somehow? I would say an opt-in that has to be set together with Connect-MgGraph something like -AllowAccessToAccessToken together with the login.

And then a Get-MgAccessToken [-Scopes ....] to get an access token as a secure string that checks wehter or not you've set the -AllowAccessToAccessToken upon connecting.

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs: Attention 👋 status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 28, 2026
@Mike-Crowley

Copy link
Copy Markdown

Stephan van Rooij (@svrooij) thanks! I'd skip the connect-time opt-in though. It doesn't really protect anything, since code in the same session can already grab the token without touching any internal types: Invoke-MgGraphRequest -OutputType HttpResponseMessage, then .RequestMessage.Headers.Authorization.Parameter. That should keep working after this PR, because the loader hands every shared-framework assembly (System.Net.Http included) back to the default context. Not tested against a build yet, since none has shipped. On top of that, the Loader README already points at reflection for the private types, and anything running in the session can just call Graph itself.

The realistic risk is a token landing in a log or a transcript, and a Get-MgAccessToken that returns a SecureString covers that on its own. That's what Az.Accounts 5.0 did with Get-AzAccessToken. Ideally it ships in the same release as this PR, so the notes can say "use this instead" and not just "this broke."

Two more things that might be worth a line in the notes:

  • Tools that inject a token by building AuthContext / GraphSession themselves (AADInternals does this) can switch to Connect-MgGraph -AccessToken.
  • For the exception, the same type-name match this PR uses in Permissions.ps1 makes a decent sample: catch { if ($_.Exception.GetType().FullName -eq 'Microsoft.Graph.PowerShell.AuthenticationException') { ... } }

🤖 Drafted and posted by Claude (Claude Code) on behalf of Mike Crowley (@Mike-Crowley).

Pierre Thoor (pthoor) added a commit to pthoor/MET that referenced this pull request Oct 6, 2026
…update MSAL conflict research (#39)

* Fix ACL errors leaking to console instead of a friendly warning

Get-Acl/Set-Acl raise non-terminating errors by default (e.g. a missing
SeSecurityPrivilege on some drives/mounts without an elevated process).
Without -ErrorAction Stop, New-METRestrictedFile's catch block never fired,
so the raw ACL error leaked to the console instead of the intended
"Could not restrict permissions" warning.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Codify known cmdlet/property/value identifiers in HTML report text

Add Get-METReportGlossaryTerms, which walks every check script's own AST to
collect the cmdlet names, parameter names, and PascalCase multi-segment
string constants (RejectDirectSend, Get-EXOMailbox, AdminOnlyAccessPolicy,
...) they actually reference. Get-METReport feeds that list into the HTML
report's client-side inline-code regex as KNOWN_TOKENS, so those
identifiers render as inline code wherever they appear in Finding/
Recommendation text, not only after a literal "Run:" prefix.

Generated from the checks' own code rather than a hand-maintained list, so
a new check's identifiers are picked up automatically - the same approach
already used for CONTROLS_META.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Ignore graphify knowledge-graph output and stray local zip bundles

graphify-out/ is a local dev aid regenerated by the graphify skill, not
project source, and *-combined.zip bundles are stray local exports.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* docs: Microsoft.Graph.Authentication 2.41.0 fixes the Graph/EXO half of the MSAL conflict

Confirmed by direct testing in this environment: Microsoft.Graph.Authentication
2.41.1 + ExchangeOnlineManagement 3.10.1 now coexist with zero assembly-load
exceptions, thanks to microsoftgraph/msgraph-sdk-powershell#3789 (merged
2026-09-23, shipped in 2.41.0) isolating Graph's MSAL/dependencies into a
private AssemblyLoadContext on PS7+.

MicrosoftTeams was not part of that fix and still loads its own unisolated
MSAL copy - confirmed MicrosoftTeams 8.0.0 + ExchangeOnlineManagement 3.10.1
alone (no Graph) still throws FileLoadException 0x80131040 in ~4 seconds.
So the 3-way EXO+Graph+Teams combination Connect-METSession needs still has
no safe version triple; the blocker has narrowed from "Graph and Teams both
conflict with EXO" to "only Teams conflicts with EXO now." Subprocess
isolation remains the proposed fix for that remaining half.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Add browser coverage for unquoted-identifier inline-code rendering

The KNOWN_TOKENS, $true and CIDR alternatives in codifyQuotes were only
asserted as generated script text, so a grouping or indexing regression in
the client-side matching could ship with every test passing (Copilot
review on PR #39). A new KnownTokens fixture renders a Finding carrying
bare RejectDirectSend/EnableSafeList, $true and 10.0.0.0/8, and a
Playwright test asserts each is an .inline-code element while the
surrounding prose is not. Verified to fail with the KNOWN_TOKENS
alternative disabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Reconcile Teams/EXO coexistence guidance; isolate Teams, not Graph

CLAUDE.md still said MicrosoftTeams and EXO are proven to coexist while
the MSAL paragraph below it says they conflict, and named
Expand-METGroupMembership as the only Graph call site although
MET-Teams014 calls Graph cmdlets directly. Both corrected.

The ROADMAP subprocess-isolation item still isolated only Graph, which
cannot resolve the remaining Teams<->EXO conflict (it reproduces with no
Graph loaded). Redesigned it around running the native Get-Cs* checks in
a Teams-only child process. (Copilot review on PR #39.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix ACL-warning test reading -WarningVariable from the wrong scope

The Windows-only test ran Get-METReport inside a `{ } | Should -Not
-Throw` scriptblock, which executes in a child scope - -WarningVariable
populated that scope's $warnings, so the assertion always saw an empty
value and failed on the Windows CI leg. Call Get-METReport directly
instead; an unexpected throw still fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* CI: allow release-assets.githubusercontent.com for the HTML report job

actions/setup-node now has to download Node 22.23.2 from the
actions/node-versions GitHub release, which GitHub serves from
release-assets.githubusercontent.com. harden-runner's block policy denied
that host (and setup-node's nodejs.org fallback), so the job failed with
ECONNREFUSED before any test ran, deterministically across re-runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ROADMAP: include Teams016 in the Teams subprocess-isolation scope

MET-Teams016 (merged in #40) calls Get-CsTeamsMessagingConfiguration, so
it belongs with the other native-Teams checks the child process would run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@Mike-Crowley

Mike Crowley (Mike-Crowley) commented Oct 14, 2026 •

Copy link
Copy Markdown

Thanks for this work. One follow-up on the type-name point from earlier, since this case isn't an undocumented internal: ContextScope is the type of the documented Connect-MgGraph -ContextScope parameter. Entra PowerShell's Connect-Entra is a proxy for Connect-MgGraph that declares that parameter as [Microsoft.Graph.PowerShell.Authentication.ContextScope], so on PS7 with 2.41.0 through 2.41.2, every Connect-Entra call now fails with "Unable to find type" (microsoftgraph/entra-powershell#1614). Other modules that wrap Connect-MgGraph with a typed -ContextScope would hit the same thing.

This reaches production docs as well: step 2 of Get started with the Microsoft MCP Server for Enterprise has admins run Connect-Entra, so the documented provisioning flow fails as written.

I may be missing design context, but one option: registering a type accelerator makes Connect-Entra bind again on 2.41.1 and 2.41.2 (I verified the binding, not a full sign-in):

$accelerators = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
$contextScope = (Get-Command Connect-MgGraph).Parameters['ContextScope'].ParameterType
$accelerators::Add($contextScope.FullName, $contextScope)

Doing that on import for types that appear on public cmdlet parameters might keep wrappers like this working without giving up the isolation. Happy to open a separate issue if that's easier to track. The Entra-side change is up as microsoftgraph/entra-powershell#1615.

🤖 Drafted and posted by Claude (Claude Code) on behalf of Mike Crowley (@Mike-Crowley).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Attention 👋 status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants