Background
PR #6070 routed the IMDSv2 mTLS-PoP token leg through MSAL's internal TokenClient. As a side effect, ImdsV2ManagedIdentitySource still inherits AbstractManagedIdentity but no longer uses its token template:
- It calls none of the inherited template methods.
- It is forced to stub the abstract
CreateRequestAsync with a throw — a classic "refused bequest" code smell.
ManagedIdentityClient selects the source through the shared AbstractManagedIdentity-typed path and then downcasts back to ImdsV2ManagedIdentitySource.
This was raised during review of #6070 (review thread). We agreed to address it as a scoped follow-up rather than carry the tech debt.
Proposed fix
- Introduce an internal interface
IImdsV2MtlsBindingSource exposing AcquireMtlsBindingForDelegationAsync.
- Have
ImdsV2ManagedIdentitySource implement the interface instead of inheriting AbstractManagedIdentity; delete the throwing CreateRequestAsync override.
- Split source selection in
ManagedIdentityClient into a decision helper (SelectManagedIdentitySourceType) and instantiation, replacing the downcast with a clean interface-typed path.
- Remove the obsolete
ValidateServerCertificate_NotSetForImdsV2 test (asserts a base-class validation-callback behavior IMDSv2 no longer has).
Constraints
References
Background
PR #6070 routed the IMDSv2 mTLS-PoP token leg through MSAL's internal
TokenClient. As a side effect,ImdsV2ManagedIdentitySourcestill inheritsAbstractManagedIdentitybut no longer uses its token template:CreateRequestAsyncwith athrow— a classic "refused bequest" code smell.ManagedIdentityClientselects the source through the sharedAbstractManagedIdentity-typed path and then downcasts back toImdsV2ManagedIdentitySource.This was raised during review of #6070 (review thread). We agreed to address it as a scoped follow-up rather than carry the tech debt.
Proposed fix
IImdsV2MtlsBindingSourceexposingAcquireMtlsBindingForDelegationAsync.ImdsV2ManagedIdentitySourceimplement the interface instead of inheritingAbstractManagedIdentity; delete the throwingCreateRequestAsyncoverride.ManagedIdentityClientinto a decision helper (SelectManagedIdentitySourceType) and instantiation, replacing the downcast with a clean interface-typed path.ValidateServerCertificate_NotSetForImdsV2test (asserts a base-class validation-callback behavior IMDSv2 no longer has).Constraints
internal).References