Skip to content

Use tdbr claim to route telemetry traffic to EU region, Fixes AB#3200872 #2679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vNext
----------
- [MINOR] Use tdbr claim to route telemetry traffic to EU region (#2679)
- [MINOR] Updating handling of ssl error received in Android WebView's onReceivedSslError callback (#2691)
- [MINOR] Fixing the sign in screens when edge to edge is enabled (#2665)
- [MINOR] Showing webcp flow in webview (#2673)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public enum CommonFlight implements IFlightConfig {
*/
ENABLE_WEB_CP_IN_WEBVIEW("EnableWebCpInWebView", false),

/**
* Flight to enable using the new EU TDBR Claim sent through ClientInfo
*/
ENABLE_USING_TDBR_CLAIM_FOR_EU_ROUTING("EnableUsingTdbrClaimForEuRouting", true),

/**
* Flight to enable the Playstore URL launch for broker apps.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* NOTE : Any changes to this enum should also be made in the corresponding enum in Broker.
*/
public enum AttributeName {
/**
* The tenant id for the home tenant of the account for which PRT is required.
*/
tenant_id,
/**
* The length of the response body returned from network request.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.common.java.opentelemetry

import com.microsoft.identity.common.java.flighting.CommonFlight
import com.microsoft.identity.common.java.flighting.CommonFlightsManager.getFlightsProvider
import com.microsoft.identity.common.java.interfaces.IStorageSupplier
import com.microsoft.identity.common.java.logging.Logger
import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.ClientInfo
import com.microsoft.identity.common.java.util.StringUtil

/**
* Utility class for storing telemetry region TDBR claims by tenant.
*/
class EUClaimStorageUtil {
companion object {
private val TAG = EUClaimStorageUtil::class.java.simpleName

/**
* Store telemetry region by tenant.
*
* @param clientInfo the client info containing tenant information and tdbr claim
*/
fun storeTelemetryRegionByTenant(
supplier: IStorageSupplier,
clientInfo: ClientInfo
) {
val methodTag = "$TAG:storeTelemetryRegionByTenant"

if (!getFlightsProvider().isFlightEnabled(CommonFlight.ENABLE_USING_TDBR_CLAIM_FOR_EU_ROUTING)) {
// If flight is not enabled, just return, don't store anything
return;
}

val tenantId = clientInfo.utid
val tdbrClaim = clientInfo.tdbrClaim

if (StringUtil.isNullOrEmpty(tenantId)) {
Logger.warn(
methodTag,
"tenantId is null or empty. Not storing telemetry region by tenant."
)
return
}

if (StringUtil.isNullOrEmpty(tdbrClaim)) {
Logger.warn(
methodTag,
"Received no tdbr claim, not storing anything in shared preferences.."
)
return
}

// Store the tdbr claim for a specific tenant ID
Logger.info(
methodTag,
"Storing telemetry region by tenant: $tenantId, TDBR Claim: $tdbrClaim"
)
val tdbrValueStore = supplier.getUnencryptedNameValueStore(
ClientInfo.TDBR_CLAIM,
String::class.java
)
tdbrValueStore.put(tenantId, tdbrClaim)

// Attach tenant id to the current span
SpanExtension.current().setAttribute(AttributeName.tenant_id.name, tenantId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ClientInfo implements Serializable {

private static final String UNIQUE_IDENTIFIER = "uid";
private static final String UNIQUE_TENANT_IDENTIFIER = "utid";
public static final String TDBR_CLAIM = "xms_tdbr";
private static final long serialVersionUID = 3326461566190095403L;

/**
Expand All @@ -56,6 +57,11 @@ public class ClientInfo implements Serializable {
*/
private String mUtid;

/**
* TDBR Claim, denotes what region the user belongs to.
*/
private String mTdbrClaim;

private String mRawClientInfo;

/**
Expand All @@ -80,6 +86,7 @@ public ClientInfo(@NonNull String rawClientInfo) throws ServiceException {

mUid = clientInfoItems.get(ClientInfo.UNIQUE_IDENTIFIER);
mUtid = clientInfoItems.get(ClientInfo.UNIQUE_TENANT_IDENTIFIER);
mTdbrClaim = clientInfoItems.get(ClientInfo.TDBR_CLAIM);
mRawClientInfo = rawClientInfo;
}

Expand All @@ -101,6 +108,15 @@ public String getUtid() {
return mUtid;
}

/**
* Gets the TDBR claim.
*
* @return The TDBR claim to get.
*/
public String getTdbrClaim() {
return mTdbrClaim;
}

/**
* Returns the raw String underlying this object.
*
Expand Down