Skip to content

Cosmos: Update key-based live tests to fixed self-owned accounts. - #5049

Open
Arooshi Avasthy (aavasthy) wants to merge 14 commits into
Azure:mainfrom
aavasthy:users/aavasthy/updatekeybasedtest
Open

Cosmos: Update key-based live tests to fixed self-owned accounts.#5049
Arooshi Avasthy (aavasthy) wants to merge 14 commits into
Azure:mainfrom
aavasthy:users/aavasthy/updatekeybasedtest

Conversation

@aavasthy

@aavasthy Arooshi Avasthy (aavasthy) commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

PR Description

Our key-based Cosmos live tests currently deploy a brand-new Cosmos account into an ephemeral Microsoft test tenant on every CI run. That tenant is rotated frequently, and each rotation requires a new ADO service connection (which we can't create ourselves - it needs engineering systems). This makes the tests fragile and painful to keep alive.

Run the key-based live tests against fixed, self-owned Cosmos accounts in the subscription (sdk-ci resource group), with the endpoints and keys stored in a single Key Vault secret.

Test path Behavior after this PR
Cosmos_live_test (6 key-based legs) Uses 6 fixed accounts in sdk-ci via new rust-ci KV secret. Changed.
Cosmos_live_thinclient (GatewayV2, 2 legs) Still ARM-deployed per run - moved to its own matrix file to keep it on the legacy path. Unchanged behavior.
Cosmos_live_test_aad Untouched. Still ARM-deployed per run against the ephemeral tenant.
Emulator, benchmark, perf, release paths Untouched.
Any Rust SDK source (.rs) Not modified.

How it works

  1. 6 permanent Cosmos accounts live in the sdk-ci resource group. They
    were created once (idempotent script under sdk/cosmos/pipeline/ account-provisioning/) and match the 6 previous per-run configurations
    (Eventual/Session/Strong SingleWrite, Session MultiWrite, Session Split,
    Session MR Failover).
  2. Their endpoints and primary/secondary keys live in one Key Vault
    secret
    (rust-ci, JSON blob keyed by logical account name), linked
    into the existing Test Secrets for Cosmos Live Tests - user administered variable group.
  3. Each Cosmos_live_test matrix leg carries an AccountSelector (e.g.
    session-multiwrite). The new resolve-test-account-steps.yml pre-test
    step runs resolve-cosmos-test-account.ps1, which picks the right slice
    of the secret and exports the same env vars the ARM template used to
    produce (AZURE_COSMOS_CONNECTION_STRING, ACCOUNT_HOST,
    DATABASE_NAME, AZURE_COSMOS_DEFAULT_CONSISTENCY, COSMOS_RUSTFLAGS).
  4. Because there is no ARM deploy, the leg also skips federated auth
    entirely - it needs no tenant login.

@Pilchie

Copy link
Copy Markdown
Member

Just reading the description, but isn't this the opposite of what we want? We need all key based auth to be in the ephemeral tenant, but can use MSI based EntraID auth in the normal tenant?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Moves key-based Cosmos live tests to permanent accounts while preserving ARM deployment for thin-client and AAD tests.

Changes:

  • Adds fixed-account provisioning, configuration, and secret resolution.
  • Splits test matrices by resource strategy.
  • Extends pipeline templates to support tests without ARM deployment.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
sdk/cosmos/pipeline/resolve-test-account-steps.yml Invokes account resolution.
sdk/cosmos/pipeline/resolve-cosmos-test-account.tests.ps1 Tests resolver validation.
sdk/cosmos/pipeline/resolve-cosmos-test-account.ps1 Exports selected account settings.
sdk/cosmos/pipeline/README.md Documents fixed-account workflow.
sdk/cosmos/pipeline/live-test-accounts.schema.json Defines secret schema.
sdk/cosmos/pipeline/live-test-accounts.sample.json Provides sample account data.
sdk/cosmos/pipeline/account-provisioning/README.md Documents provisioning and rotation.
sdk/cosmos/pipeline/account-provisioning/New-CosmosLiveTestAccounts.ps1 Provisions permanent accounts.
sdk/cosmos/pipeline/account-provisioning/cosmos-live-test-accounts.definition.json Defines account topology.
sdk/cosmos/live-thinclient-matrix.json Isolates ARM-backed thin-client tests.
sdk/cosmos/live-platform-matrix.json Maps key-based legs to fixed accounts.
sdk/cosmos/ci.yml Wires the new test paths.
eng/pipelines/templates/stages/archetype-sdk-client.yml Generates fixed-account jobs.
eng/pipelines/templates/jobs/live.tests.yml Supports skipping resource deployment.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

DefaultConsistencyLevel = $acct.defaultConsistencyLevel
EnableAutomaticFailover = $autoFailover
EnableMultipleWriteLocations = $multiWrite
ApiKind = 'GlobalDocumentDB'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — added both capabilities to the script to match the bicep. No live tests currently use vector or full-text search, so the already-provisioned accounts aren't blocking anything

}
}
else {
Write-Info "Cosmos account '$accountName' already exists (selector=$selector); leaving configuration as-is"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intentional — reruns shouldn't silently mutate live accounts. Config changes go through a manual delete + rerun, per the runbook.

Comment thread sdk/cosmos/ci.yml
Comment on lines +86 to 90
FixedAccountMatrixConfigs:
- Name: Cosmos_live_test
Path: sdk/cosmos/live-platform-matrix.json
Selection: sparse
GenerateVMJobs: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The scope of this PR is the move to fixed accounts; adding a sweeper is a separate concern with its own design questions (schedule, age threshold, safety against a concurrent run, which identity runs it).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is not completely orthogonal - for example one step to take now might be to not just use UUID based names - but prefix them with some tiemstamp - so, that any async sweeper could delete let's say db/collections that were created >12 hours ago? Not necessarily blocking for this PR - but worth thinking about this because it will become a hot topic as soon as this PR is merged.

Comment on lines +34 to +40
The script does **not** write to any ADO variable group itself - copy the
JSON it prints (or the contents of `-OutputPath`) into the
`rust-ci` secret variable in the
`Test Secrets for Cosmos Live Tests - user administered` variable group (or
whichever group `sdk/cosmos/pipeline/resolve-test-account-steps.yml` is
pointed at). Treat the JSON as a secret at every step - it contains account
keys.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — updated the runbook in  sdk/cosmos/pipeline/account-provisioning/README.md  to point rotation at the  rust-ci  Key Vault secret

Comment thread sdk/cosmos/pipeline/README.md Outdated
Comment on lines +43 to +47
accounts in the `sdk-ci` resource group and prints the JSON to store in
the ADO secret. See its README for the full runbook.
4. That JSON is stored as the `rust-ci` secret
variable in the `Test Secrets for Cosmos Live Tests - user administered`
ADO variable group (already wired into `sdk/cosmos/ci.yml`).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — updated  sdk/cosmos/pipeline/README.md  to describe  rust-ci  as a Key Vault secret linked (read-through) into the variable group, and clarified that rotation happens on the KV secret itself since the variable-group value is not writable.

@@ -0,0 +1,252 @@
<#

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — added the standard copyright/license header at the top of  New-CosmosLiveTestAccounts.ps1 . Verified  Get-Help  still returns the synopsis, so the comment-based help block still parses correctly.

Comment on lines +63 to +68
$endpoint = [string]$account.endpoint
$key = [string]$account.key
$secondaryKey = if ($account.PSObject.Properties.Name -contains 'secondaryKey') { [string]$account.secondaryKey } else { '' }
$database = if ($account.PSObject.Properties.Name -contains 'database' -and $account.database) { [string]$account.database } else { 'shared-test-db' }
$consistency = [string]$account.consistency
$testCategory = [string]$account.testCategory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed. Added a  Get-OptionalString  helper and now read  endpoint ,  key ,  secondaryKey ,  database ,  consistency ,  testCategory  conditionally, so the targeted  missing required ''  messages surface instead of a StrictMode throw. Verified against payloads missing  endpoint  and  consistency  — both output the intended error.

Comment on lines +49 to +51
if (-not ($config.PSObject.Properties.Name -contains 'version') -or $config.version -ne 1) {
Fail "Unsupported or missing schema version '$($config.version)' (parser supports: 1)."
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed. Now reading  version  into a sentinel first, so the message formats cleanly instead of throwing under StrictMode. Verified with a payload missing  version  — outputs  Unsupported or missing schema version ''  as intended.

@aavasthy

Copy link
Copy Markdown
Contributor Author

Just reading the description, but isn't this the opposite of what we want? We need all key based auth to be in the ephemeral tenant, but can use MSI based EntraID auth in the normal tenant?

Tests are still part of ephemeral tenant. In the existing process we would spin up a new account every time and run tests on it. With this new process, we have fixed accounts. We store the account + key in a secret vault and systems engineering team helped us create a new service connection for it just once. Now every time a tenant comes through we will just need to create new account and replace the account+key in vault but do not have to create a new service connection.

@Pilchie

Kevin Pilch (Pilchie) commented Aug 11, 2026

Copy link
Copy Markdown
Member

Ok, so the part of the description where it says:

No more ephemeral tenant,

is just wrong, and should be updated?
Yes removed it, we are using ephemeral tenant just removing the dependency of every time reaching out to eng sys for creating new service connection

@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread .vscode/cspell.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't modify this file. Modify sdk/cosmos/.cspell.json. That's what it's there fore and doesn't require maintainer sign-off.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted the changes in sdk/cosmos/.cspell.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Daniel Jurek (@danieljurek) or Ben Broderick Phillips (@benbp) can you review this please? I think you helped them originally so I don't have as much context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM except few NITs and Heath's blocking comment

@aavasthy
Arooshi Avasthy (aavasthy) force-pushed the users/aavasthy/updatekeybasedtest branch from a5aea65 to 13df811 Compare August 12, 2026 22:12
@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

The build.rs comment referencing the emulator command-line switch `/enableaadauthentication` triggered a cspell 'Unknown word' failure on the Build Analyze step. Adding an inline `cspell:ignore` directive keeps the comment intact without touching the shared root cspell config, matching the existing pattern used in tests/emulator_tests/cosmos_aad.rs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@aavasthy
Arooshi Avasthy (aavasthy) force-pushed the users/aavasthy/updatekeybasedtest branch from 1e1ba4a to f1de010 Compare August 13, 2026 07:27
@aavasthy

Copy link
Copy Markdown
Contributor Author

/azp run rust - cosmos - weekly

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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

Labels

Cosmos The azure_cosmos crate Do Not Merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants