Skip to content

Support Entra ID sign-in in sovereign clouds and explain sign-in failures - #1050

Merged
Tomasz Naumowicz (tnaum-ms) merged 72 commits into
mainfrom
dev/tnaum/gov-clouds
Nov 4, 2026
Merged

Tomasz Naumowicz (tnaum-ms) merged 72 commits into
mainfrom
dev/tnaum/gov-clouds

Conversation

@tnaum-ms

@tnaum-ms Tomasz Naumowicz (tnaum-ms) commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Microsoft Entra ID connections to Azure DocumentDB now work with the Azure cloud VS Code is signed in to (Azure US Government, Azure China, custom clouds), and sign-in failures get actionable explanations.

  • Cloud-aware token audience. The extension used to always request the public-cloud resource https://ossrdbms-aad.database.windows.net. It now requests the open-source database resource of the cloud selected in microsoft-sovereign-cloud.environment: …usgovcloudapi.net for US Government and …chinacloudapi.cn for China. Public-cloud behaviour is unchanged; tests pin the scope string.
  • Custom clouds. The resource comes from the new documentDB.customEnvironment.ossrdbmsEndpoint setting, from the custom cloud's sign-in host, or from its ARM metadata (/metadata/endpoints?api-version=2022-09-01). If none of these works, the connection fails with a clear message. Custom clouds never fall back to the public audience.
  • Cloud mismatch check. If the cluster's domain (azure.com, azure.us, azure.cn) belongs to a different cloud than the one VS Code is signed in to, the extension stops before sign-in and names the setting to change. Host names outside these domains, such as private DNS names or IP addresses, are ignored, so they no longer hide the cloud of the recognized hosts. Hosts in more than one Azure cloud stop sign-in with a message to check the connection string.
  • Managed identity. The cloud comes from the override, then the cluster host, then the VM's instance metadata. The VS Code sign-in setting is not used. The Settings descriptions now state this order, and that the override applies to every managed-identity connection on the machine.
  • Shell and playground.
    • The main thread resolves the token audience once per worker and reuses it for later token refreshes.
    • Refreshes no longer depend on the credential cache. Updating credentials or a failed tree connection therefore can't break an open session.
    • Copy Connection String writes the matching TOKEN_RESOURCE.
  • Update Credentials.
  • Entra error classifier. One rule table (src/documentdb/auth/entraErrors/entraErrorRules.ts) maps AADSTS codes and the opaque Windows broker error to messages that say who can fix the problem.
    • It plugs into ConnectionDiagnosticsService, so every surface that already explains connection errors gets it.
    • Managed identity gets its own AADSTS500011 guidance.
    • A broker error that carries an unknown AADSTS code keeps the code.
    • Failure context is matched to a cluster without regard to letter case.
  • Support tracing. Every Entra connection logs entraCloud.resolved: the cloud, the sign-in provider, the broker mode, the host's cloud, and the chosen token resource with the reason for it. No tenant, account, host or connection-string values are logged.
  • Docs. New user-manual page docs/user-manual/sovereign-clouds.md. It now says the msal-no-broker token-cache caveat applies to all sovereign clouds.

Why

A user reported that in Azure US Government, listing resources works but connecting with Entra ID fails with AADSTS65002. There are two causes:

  1. VS Code's client is not yet preauthorized for the OSS RDBMS resource in that cloud. That is a service-side configuration change outside this repository, and it is in progress. Precedents: [Bug]: Sovereign Cloud Universal with MFA Support auth error vscode-mssql#22296, VS Code Could not login to Azure vscode#244689.
  2. The extension always requested the public-cloud audience. This PR fixes that, and makes the first cause diagnosable.

decisions.md records the rejected alternatives and the reasoning. They include using our own client ID, falling back to the public audience, buttons on diagnostics, and restarting sessions when credentials change (D12).

Scope

Not in this PR:

Reviews

  • AI pre-review: iteration 01 review.
  • Copilot feedback and edge cases: iteration 02 review. It records each finding, the operator's decision, and a done note with the fixing commit. All five Copilot threads have replies with commits.

Validation

Case 2 ran in full on 1d388086, the code head; de93377b after it is docs-only:

  • prettier-fix: its one formatting change is committed;

  • l10n:check: up to date;

  • lint, build, typecheck:tests: pass;

  • npx vitest run: 323 files, 5633 passed, 1 skipped;

  • npm run package: VSIX built.

  • Not verified end to end: nobody on the team has sovereign-cloud access. US Government sign-in cannot succeed until the service-side configuration rolls out.

  • Before shipping (D11): check telemetry for successful Entra connections to *.azure.cn hosts, so the switch to the China audience cannot break existing users.

Links

Record the investigation of Entra ID sign-in failures (AADSTS65002) in
Azure US Government: the client and resource app IDs, why preauthorization
is fixed outside the extension, the opaque broker error, per-cloud OSSRDBMS
audiences published in ARM metadata, and how other extensions handle
sovereign clouds.

Add decisions and the iteration plan for a cloud-aware DocumentDB token
audience (interactive, managed identity, custom clouds) and a single-table
Entra error classifier routed through ConnectionDiagnosticsService.

Co-authored-by: Copilot <[email protected]>
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ CI passed: standard tier (ready PR)

Commit 76ee272, workflow run.

Layer Result Ran or skipped because
Static checks ✅ passed every push
Unit tests ✅ passed every push
npm packages: verify tarballs ⏭️ skipped no change to packages/**, package-lock.json or the CI workflow
VSIX: inspect contents ✅ passed ready PR
VSIX: self-test of the checks ⏭️ skipped no change to build/verification/**, build/vite/**, the Vite configs, package-lock.json or the CI workflow
VSIX: activate in VS Code ✅ passed ready PR
VSIX: self-test of the activation check ⏭️ skipped no change to build/verification/**, build/vite/**, the Vite configs, package-lock.json or the CI workflow
Webview host in unbundled extensions ⏭️ skipped no change to packages/vscode-ext-webview/**, package-lock.json or the CI workflow
E2E ⏭️ not available yet arrives with the E2E iteration (full tier)

Full run: add the ci:full-requested label to run every layer once on the current commit.
Last full run: ✅ passed on 7f2a288, requested by Tomasz Naumowicz (@tnaum-ms), run.

Code quality

Check Status How to fix
Localization (l10n) ✅ Passed Nothing to fix
ESLint ✅ Passed Nothing to fix
Prettier formatting ✅ Passed Nothing to fix

Build size

No page, activation, VSIX or other bundle size changed by 5% or 50 KiB or more against main. VSIX: 8.5 MiB.

Artifacts: VSIX | Bundle-reports-41834283100 | L1-manifest-report-41834283100

All graphs (exact bytes)
Graph PR bytes Base bytes Delta bytes Delta %
Collection View page (collectionView) 6,036,286 6,036,286 ✅ 0 0.0%
Document View page (documentView) 4,808,762 4,808,762 ✅ 0 0.0%
Local Quick Start page (localQuickStart) 1,551,408 1,551,408 ✅ 0 0.0%
Atlas Credentials page (atlasCredentials) 1,504,612 1,504,612 ✅ 0 0.0%
Cluster Dashboard page (clusterDashboard) 1,550,863 1,550,863 ✅ 0 0.0%
Activation (mainStartup) 3,474,639 3,448,763 ⬆️ +25,876 +0.8%
Extension host (main) 10,001,365 9,975,455 ⬆️ +25,910 +0.3%
Playground worker (playgroundWorker) 5,385,560 5,384,556 ⬆️ +1,004 +0.0%
VSIX (vsix) 8,949,544 8,941,533 ⬆️ +8,011 +0.1%
playgroundTsPlugin 6,175 6,175 ✅ 0 0.0%
viewsEntry 1,456,593 1,456,593 ✅ 0 0.0%
viewsAssets 80,340 80,340 ✅ 0 0.0%
editorWorker 259,528 259,528 ✅ 0 0.0%
jsonWorker 389,389 389,389 ✅ 0 0.0%

Packaged bytes. Shared chunks count in every graph that loads them, so rows do not add up.

Updated in place on every run.

@tnaum-ms Tomasz Naumowicz (tnaum-ms) added the ci:full-requested Requests a full run of CI checks. label Oct 23, 2026
@github-actions github-actions Bot removed the ci:full-requested Requests a full run of CI checks. label Oct 23, 2026
@tnaum-ms

Copy link
Copy Markdown
Collaborator Author

Review follow-up: fixes beyond the Copilot threads

The five Copilot threads each have a reply with the fixing commit. Those were C1–C5 in the review file, iteration 02, which records each finding, the decision and a done note. The same review found further issues; they were fixed as follows.

Fixes

Item What changed Commit
E1 When a Windows broker error contains an unknown AADSTS code, the code is now kept (unknownAadsts, still marked as brokered) and no longer treated as opaque. The code now reaches the explanation and telemetry. Broker errors without any code are unchanged. D9 states the new precedence. 093b7ac
E3 D6 and the resolver's JSDoc no longer claim that the sign-in authority and the token audience can never disagree. They now say "unless an explicit override is set". Documentation only. cb2d769
E4 A token request that finishes after its worker was replaced no longer writes to or clears the Entra failure record. Covered for both surfaces and both token sources. f1d820e
R3 Removed the stale "draft" wording from the feature README. c938efa
Records Committed the review and new decision D12 (open sessions keep what they started with), then updated the localization bundle and ran prettier. 70c663b, 73c30b5, fe267ff, e874e42, 293ec03

Improvements in this PR since the last review

  • No more broken shells or playgrounds after credentials are cleared (C3, D12). Token refresh in open sessions no longer depends on the credential cache. Before this fix, it failed with "No credentials found" for public-cloud users too.
  • Update Credentials: writes the new credentials through instead of deleting them, restarts only the stateless playground worker, and explains that open shells keep their connection.
  • More accurate sign-in diagnostics:
    • managed identity gets its own AADSTS500011 guidance (C1);
    • failure lookups work when cluster IDs differ in casing (C2);
    • unknown codes inside broker errors are kept (E1);
    • late worker results no longer change the failure record (E4).
  • Settings and the user guide now describe the real override precedence (C5) and the msal-no-broker caveat for all sovereign clouds (C4).

Still open

Focused tests for the changed areas pass locally (7 files, 216 tests), and the localization bundle is up to date. CI is running on fe267ff.

Reverts 7f2a288. The 1.0.2-sov-cloud-preview version existed only for a
preview build, which is no longer needed because the branch merges next.

Co-authored-by: Copilot <[email protected]>
@tnaum-ms Tomasz Naumowicz (tnaum-ms) added this to the 1.0.2 milestone Nov 4, 2026
One private DNS name or IP address in the seed list made the host cloud
"unknown", which skipped the interactive cloud-mismatch check and sent
managed identity to IMDS even though an azure.us/azure.cn host already
identified the cloud. Unrecognized hosts are now ignored; hosts in more
than one built-in cloud stop interactive and managed-identity sign-in
with a clear message (copy falls back to the VS Code cloud). The trace
records hostsOutsideAzure for support; no host names are logged.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@tnaum-ms

Copy link
Copy Markdown
Collaborator Author

Update: the remaining review items are done

Item What changed Commit
R1 Reverted the preview version bump; the version is 1.0.2-alpha.0 again. 9dc532e
R2 Rewrote the PR description and set the milestone to 1.0.2. (GitHub only)
E2 The cloud of the hosts the extension recognizes now survives when private DNS names or IP addresses are mixed into the seed list. The cloud-mismatch check works again, and managed identity takes the cloud from the host instead of asking IMDS. Hosts in more than one Azure cloud stop sign-in with a clear message. Copy Connection String falls back to the VS Code cloud instead. The support trace gains hostsOutsideAzure; no host names are recorded. D8 and the user guide are updated. 134c708

Case 2 ran in full on 1d38808 (Vitest: 5633 passed, 1 skipped; package built the VSIX). The review file now has a done note for every finding. The Disconnect action remains a follow-up in #1059.

Rename the unshipped mongoClusterHostnameSuffix property to hostnameSuffix without a compatibility alias. Update readers, diagnostics, localization, tests, and current documentation.

Co-authored-by: Copilot <[email protected]>
- Add a "What to do when" table and a per-setup configuration matrix
- Make the Settings editor the primary way to set each setting, with JSON
  and the Azure Resources command as alternatives
- Explain Remote settings for machine-scoped documentDB.customEnvironment
  and when a change takes effect
- Add error message tables with who can fix each problem
- Document the [Authentication] output lines for diagnostics
- Drop internal implementation details
- Note cloud-aware TOKEN_RESOURCE in managed identity and copy docs
- Link the setting description to the guide

Co-authored-by: Copilot <[email protected]>
@tnaum-ms
Tomasz Naumowicz (tnaum-ms) merged commit 6ec182c into main Nov 4, 2026
14 checks passed
@tnaum-ms
Tomasz Naumowicz (tnaum-ms) deleted the dev/tnaum/gov-clouds branch November 4, 2026 13:49
Tomasz Naumowicz (tnaum-ms) added a commit that referenced this pull request Nov 4, 2026
…(WI-29)

Adds the dns.mixedHostDomains warning to the Server address (DNS) step,
for Microsoft Entra ID and managed identity connections only. It
classifies the hosts the driver contacts (seeds, the SRV name and its
resolved targets) with getAzureHostSuffix and the trusted
documentDB.customEnvironment.hostnameSuffix, and warns when they span
two built-in clouds, or one built-in cloud plus unrecognized names
(IP literals included). Hosts that are all unrecognized do not warn.

The package DNS check is wrapped, and the finding is attached once, to
the first host DNS resolves. It only turns a pass into a warning, so
blocking, the headline and later checks are unchanged. Finding data and
telemetry carry counts and cloud enums only, and the panel shows the
finding without a host.

Reason: #1050 review finding E2. The resolver itself is unchanged.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants