Skip to content

Correct IMDS resource ID query parameter #954

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

Merged
merged 1 commit into from
May 15, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class Constants {

public static final String MANAGED_IDENTITY_CLIENT_ID = "client_id";
public static final String MANAGED_IDENTITY_RESOURCE_ID = "mi_res_id";
public static final String MANAGED_IDENTITY_RESOURCE_ID_IMDS = "msi_res_id";
public static final String MANAGED_IDENTITY_OBJECT_ID = "object_id";
public static final String MANAGED_IDENTITY_DEFAULT_TENTANT = "managed_identity";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ void addUserAssignedIdToQuery(ManagedIdentityIdType idType, String userAssignedI
break;
case RESOURCE_ID:
LOG.info("[Managed Identity] Adding user assigned resource id to the request.");
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID, Collections.singletonList(userAssignedId));
if (ManagedIdentityClient.getManagedIdentitySource() == ManagedIdentitySourceType.IMDS) {
// IMDS seems to accept both mi_res_id and msi_res_id but their API only documents msi_res_id,
// and using mi_res_id leads to issues in some scenarios that use the IMDS code path.
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID_IMDS, Collections.singletonList(userAssignedId));
} else {
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID, Collections.singletonList(userAssignedId));
}
break;
case OBJECT_ID:
LOG.info("[Managed Identity] Adding user assigned object id to the request.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
queryParameters.put("client_id", Collections.singletonList(id.getUserAssignedId()));
break;
case RESOURCE_ID:
queryParameters.put("mi_res_id", Collections.singletonList(id.getUserAssignedId()));
if (ManagedIdentityClient.getManagedIdentitySource() == ManagedIdentitySourceType.IMDS) {
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID_IMDS, Collections.singletonList(id.getUserAssignedId()));
} else {
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID, Collections.singletonList(id.getUserAssignedId()));
}
break;
case OBJECT_ID:
queryParameters.put("object_id", singletonList(id.getUserAssignedId()));
Expand Down