An Azure service that provides hardware security module management.
Hello @Radnai Miklós
Your observation about the service principal is significant. Based on the current Managed HSM authentication and authorization documentation, I don't see a supported delegated permission such as user_impersonation exposed for third-party applications targeting the Managed HSM data plane.
Managed HSM uses Microsoft Entra ID for authentication, but its authorization model differs from standard Key Vault in an important way. The Managed HSM data plane uses Managed HSM local RBAC, independently from Azure RBAC on the control plane. Users, groups, service principals, and managed identities are security principals that can be granted data-plane access.
Therefore, the error you're seeing: "AADSTS650053 The application asked for scope 'user_impersonation' that doesn't exist on the resource" is consistent with what you're seeing in the Managed HSM enterprise application: if the resource doesn't publish that delegated permission, requesting https://managedhsm.azure.net/user_impersonation isn't a valid way to obtain a delegated Managed HSM token.
Also, don't substitute the regular Azure Key Vault user_impersonation scope. Managed HSM has its own data-plane endpoint https://<hsm-name>.managedhsm.azure.net/. Managed HSM and Key Vault vaults are different resource types with different access-control behavior.
For an application/service calling Managed HSM, the documented pattern is instead to give the application's service principal or managed identity the required Managed HSM local RBAC role. For example, Microsoft documents assigning Managed HSM Crypto User to a service principal or managed identity at /keys or at an individual /keys/<key-name> scope.
For example:
az keyvault role assignment create \
--hsm-name <hsm-name> \
--role "Managed HSM Crypto User" \
--assignee <application-or-managed-identity-object-id> \
--scope /keys/<key-name>
The important architectural consequence is that the HSM then authorizes the application identity, not the interactive user's Managed HSM local RBAC assignment. So this does not reproduce the delegated “act as this user and evaluate this user's HSM permissions” model you're looking for.
If each user's authorization must remain distinct, I would avoid giving the middle-tier application a broad HSM-wide role and then treating the user's Entra authorization as though Managed HSM enforced it. Instead, authenticate and authorize the user in your application and give the application's HSM identity only the minimum key-level permissions required for the operations the application is allowed to perform. Managed HSM supports role assignments down to /keys/<key-name>, which can help reduce the application's HSM privileges.
If the requirement specifically mandates cryptographic enforcement by Managed HSM of the interactive user's own local-RBAC identity, rather than application-side authorization followed by an app/managed-identity HSM call, I would raise that requirement with Azure Key Vault/Managed HSM Support. I could not find a currently documented delegated/OBO permission for the Managed HSM resource that would make the authorization-code pattern in the question work.
Be careful not to interpret the lack of oauth2PermissionScopes as meaning Managed HSM doesn't use OAuth/Entra tokens at all. It does. The distinction here is between Entra authentication to Managed HSM and a resource exposing a delegated OAuth permission to third-party client applications.
References:
Managed HSM data-plane role management
Managed HSM local RBAC built-in roles
Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution. Thank you.