Fix national/sovereign cloud exports hitting commercial Graph endpoint (#117) - #122
Open
eduardarbona (earbona23) wants to merge 1 commit into
Open
eduardarbona (earbona23) wants to merge 1 commit into
eduardarbona (earbona23) wants to merge 1 commit into
Conversation
Invoke-GraphBatchRequest hardcoded https://graph.microsoft.com as the base URI for the $batch endpoint (and for stripping the host from paginated nextLink URLs). Because that absolute URI is passed to Invoke-MgRestMethod, the SDK targets it verbatim instead of the connected environment's Graph host. On a national/sovereign cloud (USGov, USGovDoD, China, ...) every batch request therefore goes to the commercial cloud and fails with 401 InvalidCloudInstance, even though Connect-MgGraph -Environment authenticated correctly. Resolve the Graph endpoint from the connected environment via (Get-MgEnvironment -Name (Get-MgContext).Environment).GraphEndpoint, with a fallback to the commercial endpoint when it can't be resolved. This defers the endpoint list to the Graph SDK's own environment table, so new sovereign clouds are supported without further changes. The paginated nextLink host is stripped using the same resolved endpoint. Fixes microsoft#117
Author
|
Sam Erde (@SamErde) Merill Fernando (@merill) — this fixes the endpoint issue filed in #117: The change is small and the companion docs PR is #123, which covers #118. Both are green and merge cleanly. Whenever there's a window for triage, I'm around to adjust anything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a national/sovereign cloud tenant (GCC-High / USGov, USGovDoD, China, ...)
Export-Entrafails with:even though
Connect-EntraExporter/Connect-MgGraph -Environment 'USGov'authenticated correctly. Rolling back to 2.0.7 works. (Fixes #117)Root cause
src/internal/Invoke-GraphBatchRequest.ps1hardcodes the base Graph URI:That absolute URI is handed to
Invoke-MgRestMethod, which targets it verbatim instead of resolving against the connected environment's Graph host. So every batch request (and the whole export, since 3.x batches everything) goes to the commercial cloud regardless of the environment you connected to — the token is valid, but for the wrong cloud instance →InvalidCloudInstance. The paginated@odata.nextLinkhost stripping on line ~332 was hardcoded to the same commercial host.Fix
Resolve the Graph endpoint from the currently connected environment and use it for both the
$batchURI and the nextLink host stripping:This defers the endpoint list to the Graph SDK's own environment table (
Get-MgEnvironment), so USGov →graph.microsoft.us, USGovDoD →dod-graph.microsoft.us, China →microsoftgraph.chinacloudapi.cn, and any future sovereign cloud the SDK adds all work with no further changes. Commercial cloud behavior is unchanged, and an unresolvable environment falls back to the commercial endpoint.Only
Microsoft.Graph.Authenticationcmdlets already required by the module are used (Get-MgContext,Get-MgEnvironment) — no new dependency.Verification
Parser.ParseFile— no syntax errors.PSScriptAnalyzer— no new findings on the changed lines (only pre-existing repo-wide alias/Write-Host warnings remain).Functional test dot-sourcing the function with mocked
Get-MgContext/Get-MgEnvironment/Invoke-MgRestMethod, asserting the resulting$batchURI per environment:$batchURIhttps://graph.microsoft.us/v1.0/$batchhttps://dod-graph.microsoft.us/v1.0/$batchhttps://microsoftgraph.chinacloudapi.cn/v1.0/$batchhttps://graph.microsoft.com/v1.0/$batchhttps://graph.microsoft.com/v1.0/$batch(fallback)Related: #118 (updating
Connect-EntraExporter's sovereign cloud handling) is addressed separately.