Skip to content

Allow attaching a cosmos db account with tenantId.#2895

Merged
sevoku merged 3 commits intomainfrom
dev/mkrueger/issue2620
Mar 5, 2026
Merged

Allow attaching a cosmos db account with tenantId.#2895
sevoku merged 3 commits intomainfrom
dev/mkrueger/issue2620

Conversation

@mkrueger
Copy link
Copy Markdown
Member

@mkrueger mkrueger commented Jan 16, 2026

This pull request adds support for handling Azure Cosmos DB connection strings that use either an AccountKey or a TenantId for authentication, instead of requiring only an AccountKey. The changes update validation, parsing, and storage logic throughout the codebase to recognize and propagate TenantId values, and they add tests to ensure correct parsing. Additionally, the URI handler and workspace model are updated to support the new field.

Cosmos DB connection string handling:

  • Updated validation and user prompts to accept connection strings that include AccountEndpoint and either AccountKey or TenantId, and clarified error messages and placeholders accordingly. [1] [2] [3]
  • Extended the parseCosmosDBConnectionString function and ParsedCosmosDBConnectionString class to extract and store the TenantId property if present. [1] [2] [3]
  • Added tests to ensure correct parsing of connection strings with TenantId and with only AccountEndpoint. [1] [2]

Workspace and storage model updates:

  • Modified the CosmosDBAttachedAccountModel and related logic to include an optional tenantId field, and ensured the field is persisted and propagated where appropriate (e.g., in storage items and account info). [1] [2] [3] [4] [5]

URI handler and parameter propagation:

  • Updated the URI handler to extract, mask, and propagate the tenantId parameter from URIs, and to store it in attached account storage items if present. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Fixes #2620

@mkrueger mkrueger requested a review from sevoku January 16, 2026 13:31
@mkrueger mkrueger requested a review from a team as a code owner January 16, 2026 13:31
sevoku
sevoku previously approved these changes Jan 22, 2026
Copy link
Copy Markdown
Member

@sevoku sevoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tried with using a connection string with a specific tenant Id that is not my default and it works like a charm.

bk201-
bk201- previously approved these changes Feb 2, 2026
@mkrueger mkrueger force-pushed the dev/mkrueger/issue2620 branch from fa712c8 to f761783 Compare March 3, 2026 11:27
Copy link
Copy Markdown
Member

@sevoku sevoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkrueger the build is broken, please don't forget to run npm run l10n

See my other comment, let's don't enforce TenantId in the connection string?

Comment thread src/commands/newConnection/CosmosDBConnectionStringStep.ts Outdated
@mkrueger mkrueger force-pushed the dev/mkrueger/issue2620 branch from 83d0009 to 4018945 Compare March 5, 2026 13:11
@mkrueger mkrueger requested a review from sevoku March 5, 2026 13:29
sevoku
sevoku previously approved these changes Mar 5, 2026
Copy link
Copy Markdown
Member

@sevoku sevoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, now I see a prompt and can select the tenant, works like a charm! This is also relevant for #2686.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for attaching Cosmos DB accounts using Entra ID by accepting/storing a TenantId (in addition to AccountKey) across connection-string parsing, URI handling, and workspace persistence.

Changes:

  • Extend Cosmos DB connection string parsing/model to extract and propagate TenantId, and update masking accordingly.
  • Persist optional tenantId in attached account workspace storage and use it when building account credentials.
  • Add a new “select tenant” wizard step for connection strings that don’t include AccountKey or TenantId, plus parsing tests.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vscodeUriHandler.ts Accept tenantId via URI params / parsed connection string and persist it into workspace storage items.
src/tree/workspace-view/cosmosdb/CosmosDBWorkspaceItem.ts Read tenantId from stored workspace item properties into the attached account model.
src/tree/workspace-view/cosmosdb/CosmosDBAttachedAccountModel.ts Add optional tenantId to the attached account model type.
src/tree/cosmosdb/AccountInfo.ts Flow tenantId into credential creation for connection-string and attached-account paths.
src/cosmosdb/cosmosDBConnectionStrings.ts Parse TenantId from connection strings and store it on ParsedCosmosDBConnectionString.
src/cosmosdb/cosmosDBConnectionStrings.test.ts Add tests for parsing connection strings with TenantId and with AccountEndpoint only.
src/commands/newConnection/newConnection.ts Add the new tenant prompt step to the “New Connection” wizard flow.
src/commands/newConnection/NewConnectionWizardContext.ts Add tenantId to wizard context for cross-step propagation.
src/commands/newConnection/CosmosDBTenantStep.ts New step: prompt tenant selection when neither AccountKey nor TenantId is present.
src/commands/newConnection/CosmosDBExecuteStep.ts Persist tenantId into storage item properties when available.
src/commands/newConnection/CosmosDBConnectionStringStep.ts Extract tenantId from the entered connection string into wizard context.
l10n/bundle.l10n.json Add localized strings for updated validation text and tenant selection UI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/vscodeUriHandler.ts
Comment thread src/commands/newConnection/CosmosDBConnectionStringStep.ts
…TenantId

When a user attaches a Cosmos DB account with a connection string that
contains only AccountEndpoint (no AccountKey or TenantId), prompt them
to select an Azure tenant via VSCodeAzureSubscriptionProvider for Entra
ID authentication.

- Add CosmosDBTenantStep using VSCodeAzureSubscriptionProvider.getTenants()
- Auto-select tenant when only one is available
- Add tenantId to NewConnectionWizardContext
- Extract tenantId from connection string in CosmosDBConnectionStringStep
- Use context.tenantId in CosmosDBExecuteStep (from prompt or connection string)
- Relax validation: only AccountEndpoint is required
@sevoku sevoku merged commit 3c026b3 into main Mar 5, 2026
5 checks passed
@sevoku sevoku deleted the dev/mkrueger/issue2620 branch March 5, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow attaching a Cosmos DB Account with tenantId (without AccountKey)

4 participants