Added per user connection pooling for OBO.#3153
Added per user connection pooling for OBO.#3153anushakolan wants to merge 1 commit intodev/anushakolan/obo-delegated-identityfrom
Conversation
|
/azp run |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
| return baseConnectionString; | ||
| } | ||
|
|
||
| // Extract user pool key from current HTTP context using iss:sub |
There was a problem hiding this comment.
update the comment to match the real behavior so the next reader doesn’t get confused. the comment says “iss:sub”, but GetUserPoolKeyHash actually prefers oid then falls back to sub.
| ClaimsPrincipal user = HttpContextAccessor.HttpContext.User; | ||
|
|
||
| // Extract issuer claim - required for tenant isolation | ||
| string? iss = user.FindFirst("iss")?.Value; |
There was a problem hiding this comment.
Some identity setups may not emit a literal "iss" claim in the principal (even if the token had an issuer). You already do good fallbacks for oid/sub; you could do similar for issuer if there’s an established claim type you use elsewhere in the repo. add a fallback source for issuer (if you can), or at least mention in a comment that "iss" must be present for pooling to activate.
| if (string.IsNullOrEmpty(iss) || string.IsNullOrEmpty(userKey)) | ||
| { | ||
| // Cannot create a pool key without both claims | ||
| QueryExecutorLogger.LogDebug("Cannot create per-user pool key: missing iss or user identifier claim."); |
There was a problem hiding this comment.
maybe include datasource name (still safe) to help debugging. Remember to use structured logs
Why make this change?
What is this change?
user-delegated-authis enabled, the connection pool is automatically partitioned by user identity. No additional configuration is required.Application Nameconnection string property to include a user-specific hash:{baseAppName}|obo:{hash}iss+oidorsub) using SHA256, then encoded as URL-safe Base64.Key implementation details:
_dataSourceBaseAppNamedictionary stores the base Application Name for OBO-enabled data sourcesGetUserPoolKeyHash()extracts user claims and generates deterministic hashGetConnectionStringForCurrentUser()appends user hash to create pool-isolated connection stringsHow was this tested?
TestOboWithUserClaims_ConnectionStringHasUserSpecificAppName- Verifies connection string contains|obo:with hash when user claims presentTestObo_DifferentUsersGetDifferentPoolHashes- Verifies different users get different Application NamesTestOboNoUserContext_UsesBaseConnectionString- Verifies startup scenario uses base connection string without OBO suffixManual E2E Testing
Environment Setup:
Test Scenario 1: Single User Connection Pool Isolation
sys.dm_exec_sessionsthat all connections had the same Application Name with user-specific hashTest Scenario 2: Multi-User Pool Isolation
DAB,dab_oss_2.0.0|obo:W8L-UzlymZJcRbqAoTRBBcDDvHBjKoEP1lo94PGpcp0DAB,dab_oss_2.0.0|obo:Xk9mPqRsT2vWxYz1AbCdEfGhIjKlMnOpQrStUvWxTest Scenario 3: Startup Without User Context
DAB,dab_oss_2.0.0(no|obo:suffix)Verification Query (run on Azure SQL):