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 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public void onReceive(@NonNull PropertyBag propertyBag) {

verifyBrokerVersionIsSupported(resultBundle, parameters.getRequiredBrokerProtocolVersion());
result = mResultAdapter.getAcquireTokenResultFromResultBundle(resultBundle);
trackTelemetryRegionFromResultBundle(resultBundle);
} catch (final BaseException | ExecutionException e) {
Telemetry.emit(
new ApiEndEvent()
Expand Down Expand Up @@ -616,6 +617,7 @@ public AcquireTokenResult extractResultBundle(final @Nullable Bundle resultBundl
"Attempting to sleep thread during Device Code Flow token polling...");
return acquireDeviceCodeFlowToken(authorizationResult, parameters);
} else {
trackTelemetryRegionFromResultBundle(resultBundle);
return acquireTokenResult;
}
}
Expand Down Expand Up @@ -1322,6 +1324,9 @@ private void saveMsaAccountToCache(final @NonNull Bundle resultBundle,

try {
final ClientInfo clientInfo = new ClientInfo(brokerResult.getClientInfo());
// Store the telemetry region info in shared preferences
mComponents.getPlatformUtil().storeTelemetryRegionByTenant(mComponents.getStorageSupplier(), clientInfo);

final MicrosoftStsAccount microsoftStsAccount = new MicrosoftStsAccount(
new IDToken(brokerResult.getIdToken()),
clientInfo
Expand Down Expand Up @@ -1421,4 +1426,23 @@ private void verifyBrokerVersionIsSupported(@Nullable final Bundle resultBundle,
"So, this is not likely a broker version supported issue. Continuing.");
}
}

private void trackTelemetryRegionFromResultBundle(@NonNull final Bundle resultBundle) throws BaseException {
final String methodTag = TAG + ":trackTelemetryRegionFromResultBundle";
final BrokerResult brokerResult = new MsalBrokerResultAdapter().brokerResultFromBundle(resultBundle);
if (resultBundle.getBoolean(AuthenticationConstants.Broker.BROKER_REQUEST_V2_SUCCESS)) {
if (StringUtil.isNullOrEmpty(brokerResult.getClientInfo())) {
return;
}

try {
final ClientInfo clientInfo = new ClientInfo(brokerResult.getClientInfo());

// Store the telemetry region info in shared preferences
mComponents.getPlatformUtil().storeTelemetryRegionByTenant(mComponents.getStorageSupplier(), clientInfo);
} catch (Exception e) {
Logger.error(methodTag, "Exception while trying to store telemetry region from client info in broker result.", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@
import com.microsoft.identity.common.java.exception.ErrorStrings;
import com.microsoft.identity.common.java.flighting.CommonFlight;
import com.microsoft.identity.common.java.flighting.CommonFlightsManager;
import com.microsoft.identity.common.java.interfaces.INameValueStorage;
import com.microsoft.identity.common.java.interfaces.IStorageSupplier;
import com.microsoft.identity.common.java.logging.Logger;
import com.microsoft.identity.common.java.opentelemetry.AttributeName;
import com.microsoft.identity.common.java.opentelemetry.SpanExtension;
import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.ClientInfo;
import com.microsoft.identity.common.java.util.IPlatformUtil;
import com.microsoft.identity.common.java.util.StringUtil;

Expand Down Expand Up @@ -204,6 +209,31 @@ public List<Map.Entry<String, String>> updateWithAndGetPlatformSpecificExtraQuer
return originalList;
}

@Override
public void storeTelemetryRegionByTenant(@NonNull IStorageSupplier supplier, @NonNull ClientInfo clientInfo) {
final String methodTag = TAG + ":storeTelemetryRegionByTenant";
final String tenantId = clientInfo.getUtid();
final String tdbrClaim = clientInfo.getTdbrClaim();

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);
final INameValueStorage<String> tdbrValueStore = supplier.getUnencryptedNameValueStore(ClientInfo.TDBR_CLAIM, String.class);
tdbrValueStore.put(tenantId, tdbrClaim);

// Attach tenant id to the current span
SpanExtension.current().setAttribute(AttributeName.tenant_id.name(), tenantId);
}

/**
* Updates the query string parameters with the WebAuthn capability parameter (or removes the parameter) if applicable.
*
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.microsoft.identity.common.java.commands.ICommand;
import com.microsoft.identity.common.java.exception.ClientException;
import com.microsoft.identity.common.java.exception.ErrorStrings;
import com.microsoft.identity.common.java.interfaces.IStorageSupplier;
import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.ClientInfo;

import java.security.NoSuchAlgorithmException;
import java.util.List;
Expand Down Expand Up @@ -129,4 +131,11 @@ public interface IPlatformUtil {
*/
@Nullable
List<Map.Entry<String, String>> updateWithAndGetPlatformSpecificExtraQueryParameters(@Nullable List<Map.Entry<String, String>> originalList);

/**
* Store telemetry region by tenant.
*
* @param clientInfo the client info containing tenant information and tdbr claim
*/
void storeTelemetryRegionByTenant(@NonNull IStorageSupplier supplier, @NonNull ClientInfo clientInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import com.microsoft.identity.common.java.crypto.IDevicePopManager;
import com.microsoft.identity.common.java.exception.ClientException;
import com.microsoft.identity.common.java.interfaces.IPopManagerSupplier;
import com.microsoft.identity.common.java.interfaces.IStorageSupplier;
import com.microsoft.identity.common.java.interfaces.PlatformComponents;
import com.microsoft.identity.common.java.net.DefaultHttpClientWrapper;
import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.ClientInfo;
import com.microsoft.identity.common.java.providers.oauth2.IStateGenerator;
import com.microsoft.identity.common.java.strategies.IAuthorizationStrategyFactory;
import com.microsoft.identity.common.java.util.IBroadcaster;
Expand Down Expand Up @@ -188,6 +190,11 @@ public String getPackageNameFromUid(int uid) {
public List<Map.Entry<String, String>> updateWithAndGetPlatformSpecificExtraQueryParameters(@Nullable List<Map.Entry<String, String>> originalList) {
return originalList;
}

@Override
public void storeTelemetryRegionByTenant(@edu.umd.cs.findbugs.annotations.NonNull IStorageSupplier supplier, @edu.umd.cs.findbugs.annotations.NonNull ClientInfo clientInfo) {
// Do nothing
}
};

public static final IBrowserSelector NON_FUNCTIONAL_BROWSER_SELECTOR = new NoopBrowserSelector();
Expand Down
Loading