Before you begin
You’ll need:- An organization on the Enterprise plan and a service running ClickHouse version 26.4 or later.
-
A ClickHouse Cloud role with the
control-plane:service:managepermission on the service (for example, Admin or Service admin) to add the JWT provider. - Access to the Microsoft Entra admin center with at least the Cloud Application Administrator role.
- Microsoft Entra ID P1 or P2 if you want to assign groups, rather than individual users, to app roles.
-
The Azure CLI (
az) andclickhouse-clientto test the setup. -
A list of the ClickHouse roles you want to grant through Entra ID. Each one becomes an Entra ID app role with the same name. This guide uses two:
How it works
- You register an application in Entra ID that represents your ClickHouse Cloud service, and define one app role for each ClickHouse role.
- You assign Entra ID users, groups, and applications to those app roles.
- A user signs in with Azure CLI or
clickhouse-client --login, or an application uses the client credentials grant. Entra ID issues a v2.0 access token whoseaudclaim is the application (client) ID and whoserolesclaim lists the app roles assigned to the caller. - ClickHouse Cloud verifies the token signature against the Entra ID public keys, checks the
issandaudclaims, and creates an ephemeral user with the privileges of the ClickHouse roles named in therolesclaim, capped by the privileges of thedefaultuser.
Register ClickHouse in Entra ID
1
Create the app registration
In the Microsoft Entra admin center, open App registrations and select New registration:
- Name: a display name, for example
clickhouse-cloud-production. - Supported account types: single tenant. Depending on the portal version, this option is labeled Single tenant only or Accounts in this organizational directory only.
- Redirect URI: leave empty. Users sign in with the device code flow, which doesn’t use a redirect URI.
- Application (client) ID, referred to below as
<CLIENT_ID>. It becomes theaudclaim of the tokens. - Directory (tenant) ID, referred to below as
<TENANT_ID>. It’s part of the issuer and the JWKS URL.
2
Request v2.0 access tokens
By default, Entra ID issues v1.0 access tokens, whose issuer is
https://sts.windows.net/<TENANT_ID>/. Configure the application to receive v2.0 tokens instead, whose issuer is https://login.microsoftonline.com/<TENANT_ID>/v2.0 and whose aud claim is always the client ID.In your app registration, open Manifest, set the access token version to 2, and select Save. The property name depends on the manifest format the editor shows:- Microsoft Graph format:
requestedAccessTokenVersionin theapisection. - Azure AD Graph format: the top-level
accessTokenAcceptedVersion, as in the screenshot below.
3
Expose an API
Open Expose an API:
-
Next to Application ID URI, select Add, accept the default value
api://<CLIENT_ID>, and save. Clients use this URI to request tokens for ClickHouse. It doesn’t change theaudclaim of v2.0 tokens, which stays the client ID. -
Select Add a scope and fill in the form. Users request this scope when they sign in. Applications that authenticate as themselves don’t use it.
5
Create app roles
Each app role corresponds to one ClickHouse role. The app role’s Value is what appears in the
roles claim of the token, and it must match the name of the ClickHouse role exactly, including case.Open App roles and select Create app role for each ClickHouse role:The following example defines three app roles whose values are ClickHouse role names:
6
Require assignment
By default, any user in your tenant can get a token for the application. To limit tokens to the users, groups, and applications you assign to an app role, open Enterprise applications, select the application with the same name as your app registration, open Properties, set Assignment required? to Yes, and select Save.
7
Assign users and groups to app roles
In the same enterprise application, open Users and groups and select Add user/group. Select a user or group, select an app role, and select Assign. Repeat for each user or group.A user who is assigned several app roles, directly or through groups, gets all of them in the
roles claim.Assigning groups to app roles requires Microsoft Entra ID P1 or P2. Nested groups aren’t supported: only direct members of an assigned group receive its app role.
Create matching roles in ClickHouse
Connect to your service as thedefault user, for example from the SQL console, and create a role for each app role value:
- Role names are case-sensitive and must match the app role values.
- ClickHouse ignores names in the
rolesclaim that don’t match an existing role on the service. - The permission limit for JWT providers in ClickHouse Cloud is the
defaultuser. ClickHouse drops any privileges of a role that thedefaultuser doesn’t have.
Add Entra ID as a JWT provider
Follow the steps in Add a JWT provider and enter these values:Connect as a user
Set the values from your app registration and your service hostname as shell variables:Pass an Azure CLI token
Sign in with Azure CLI, request an access token for the ClickHouse application, and pass it toclickhouse-client with --jwt:
--login for long sessions.
Sign in with clickhouse-client
clickhouse-client can run the OAuth 2.0 device code flow itself and renew the token during the session:
offline_access in the scope: it makes Entra ID return a refresh token, which the client uses to renew the access token. Without it, you have to sign in again when the access token expires.
Connect as an application
Applications such as ETL jobs and backend services authenticate as themselves with the OAuth 2.0 client credentials grant. The app roles you grant to an application must allow the Applications member type.- In App registrations, register a separate application for the workload. Under Certificates & secrets, create a client secret or upload a certificate. The commands below refer to the workload’s client ID and secret as
<WORKLOAD_CLIENT_ID>and<WORKLOAD_CLIENT_SECRET>. - In the workload’s app registration, open API permissions and select Add a permission. Under APIs my organization uses, find the ClickHouse application, select Application permissions, select the app roles the workload needs, and select Add permissions.
- Select Grant admin consent to assign the app roles to the workload.
Verify
After connecting, check the identity and privileges of the session:
ClickHouse doesn’t grant the roles themselves to the ephemeral user. It collects the privileges of the roles named in the token, intersects them with the privileges of the
default user, and grants the result to the user directly. That’s why SHOW CURRENT ROLES returns no rows.
For user tokens, Entra ID sets sub to an opaque identifier that is unique to the combination of user and application. It isn’t the user’s email address or object ID.
Best practices
Assign groups, not individual users
Assign one Entra ID group to each app role, then grant or revoke access by changing group membership. Nobody has to edit the application when people join or leave a team.Use a separate app registration for each environment
Tokens carry the client ID of their app registration in theaud claim. With separate app registrations for production and staging, a token issued for one environment can’t authenticate to the other.
Expect role changes to apply on the next token
Entra ID writes theroles claim when it issues a token. After you change the app role assignments of a user, the change takes effect when the user gets a new token. Tokens that are already issued keep their roles until they expire. With Azure CLI, run az logout and az login to get a new token immediately.
Troubleshooting
The token is rejected and its issuer starts with https://sts.windows.net
The token is rejected and its issuer starts with https://sts.windows.net
Entra ID issued a v1.0 token. Set
requestedAccessTokenVersion to 2 in the application manifest, as described in Request v2.0 access tokens, and request a new token.The token is rejected because of its audience
The token is rejected because of its audience
- The Audience of the provider in ClickHouse Cloud must be the client ID, not
api://<CLIENT_ID>. - Check that you requested a token for the ClickHouse application. Without
--resource,az account get-access-tokenreturns a token for Azure Resource Manager instead.
Entra ID returns AADSTS65001 or asks for consent
Entra ID returns AADSTS65001 or asks for consent
The client application isn’t pre-authorized for the
access_as_application scope. Add its client ID under Expose an API → Authorized client applications, as described in Authorize a client application for user sign-in.Entra ID returns AADSTS50105 or AADSTS501051
Entra ID returns AADSTS50105 or AADSTS501051
The user or application isn’t assigned to the ClickHouse application, and Assignment required? is set to Yes. Assign the user, one of their groups, or the application to an app role. If you assigned a group, make sure the user is a direct member of it.
Authentication succeeds but queries fail with ACCESS_DENIED
Authentication succeeds but queries fail with ACCESS_DENIED
The ephemeral user doesn’t have the privileges the query needs. Check that:
- The Roles claim of the provider is set to
roles. - The token contains a
rolesclaim. It’s missing when the caller is assigned to the application without an app role. - Each value in the
rolesclaim matches an existing ClickHouse role on the service, including case. - The
defaultuser has the privileges you granted to the role.
The token is rejected after configuring a claims-mapping policy
The token is rejected after configuring a claims-mapping policy
If you configured a claims-mapping policy or a custom signing key for the application, Entra ID signs its tokens with a key that isn’t in the tenant’s JWKS. Set the JWKS URL of the provider to
https://login.microsoftonline.com/<TENANT_ID>/discovery/v2.0/keys?appid=<CLIENT_ID>.Related
- JWT authentication setup: add, update, and remove JWT providers in the Cloud console.
- JWT Authentication: token claims, ephemeral users, and client usage.