MS Entra ID managed identity for client credentials
Prerequisites
This article provides the minimum technical detail required to implement the solution. Detailed step-by-step guidance can be generated by an AI client from this content when needed.
Managed identity for Azure workloads
Fopr Azure workloads, Microsoft Entra User-Assigned Managed Identity (UAMI) can replace a long-lived Keycloak client secret or certificate.
Credential stored by workload
Yes
Private key
No
Rotation required
Yes
Yes
No application credential
Expiration management
Yes
Yes
No
Azure workload overhead
Medium
Medium
Low
Where managed identity is suitable, remove the application-managed credential and therefore remove its rotation process.
The steps below cover only the additional integration configuration.
Implement managed identity for client credentials
It is recommended to use two separate browser tabs for the Azure (A) and Keycloak (K) portals to make it easier to apply the settings.
Configure the Entra appliance audience.
(A) In the first tab, sign in to the Azure Portal.
(A) Search for Microsoft Entra ID. Expand Manage in the left pane and click App registrations.
(A) Navigate to the application created in MS Entra ID (OIDC).
(A) Configure Application ID URI to
api://{ENTRA-APPLICATION-CLIENT-ID}.(A) Configure the application manifest. This defines the audience requested by the managed identity and uses the Entra v2 token issuer expected by the Keycloak trust.
Create and assign application role.
(A) Navigate to the application created in MS Entra ID (OIDC).
(A) Select Create app role.
(A) Provide the following values then select Apply.
KeyValueDisplay name
Keycloak AuthenticateAllowed member types
ApplicationsValue
Keycloak.AuthenticateEnabled
Yes(A) Assign this role to the UAMI with this PowerShell script. This explicitly authorizes the managed identify for the Keycloak authentication integration. The Entra token should contain
roles = ["Keycloak.Authenticate"]. Managed Identity tokens are cached, so a new role assignment may not appear immediately.
Enable Signed JWT - Federated in Keycloak. This makes the federated JWT authenticator available to Keycloak clients.
(K) Open a new tab in your browser and login to the target Spark tenant. Access the Keycloak console from the User menu.
(K) Navigate to Authentication and the Clients authentication flow.
(K) Enable Signed JWT - Federated.
Update the existing Entra OIDC identity provider.
(A) Navigate to the application created in MS Entra ID (OIDC).
(A) Update the following settings.
KeyValueSupports client assertions
ONAllows client assertions to be re-used
ONAllows Client ID as audience for assertions
ON(A) Signature validation and the Entra JWKS URL must also be configured so Keycloak can validate Entra-signed assertions.
Configure the Keycloak client.
(K) Navigate to the client created in MS Entra ID (OIDC).
(K) Under credentials configure:
KeyValueClient Authenticator
Signed JWT - FederatedIdentity provider
{ENTRA-IDP-ALIAS}Allows Client ID as audience for assertions
{UAMI-OBJECT-ID}The federated subject maps the Entra managed identity to the Keycloak client.
UAMI Client ID used by
Azure.Identity(ManagedIdentityClientId)UAMI Object ID used for role assignment and Keycloak Federated subject.
Obtain the Entra token.
Use this C# code snippet to retrieve the Entra token.
Verify the token contains the expected issuer (
iss), audience (aud), managed identity subject (sub), andKeycloak.Authenticaterole.
Exchange the Entra token for a Keycloak token.
Keycloak validates the Entra JWT as the client assertion and returns the normal Keycloak access token.
Last updated
