You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/operations/external-authenticators/tokens.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,30 +8,30 @@ import SelfManaged from '@site/docs/en/_snippets/_self_managed_only_no_roadmap.m
8
8
9
9
ClickHouse users can be authenticated using tokens. This works in two ways:
10
10
11
-
-Existing users (defined in `users.xml` or in local access control paths) can be authenticated with a token if this user can be `IDENTIFIED WITH jwt`.
11
+
-An existing user (defined in `users.xml` or in local access control paths) can be authenticated with a token if this user can be `IDENTIFIED WITH jwt`.
12
12
- Use the information from the token or from an external Identity Provider (IdP) as a source of user definitions and allow locally undefined users to be authenticated with a valid token.
13
13
14
14
Although not all tokens are JWTs, under the hood both ways are treated as the same authentication method to maintain better compatibility.
15
15
16
16
# Token Processors
17
17
18
18
## Configuration
19
-
To use token-based authentication, add `token_processors` section to `config.xml` and define at least one token processor in it.
19
+
To use token-based authentication, add `token_processors` section to `config.xml` and define at least one token processor in it.
20
20
Its contents are different for different token processor types.
21
21
22
22
**Common parameters**
23
23
-`type` -- type of token processor. Supported values: "JWT", "Azure", "OpenID". Mandatory. Case-insensitive.
24
24
-`token_cache_lifetime` -- maximum lifetime of cached token (in seconds). Optional, default: 3600.
25
25
-`username_claim` -- name of claim (field) that will be treated as ClickHouse username. Optional, default: "sub".
26
-
-`groups_claim` -- Name of claim (field) that contains list of groups user belongs to. This claim will be looked up in the token itself (in case token is a valid JWT, e.g. in Keycloak) or in response from `/userinfo`. Optional, default: "groups".
26
+
-`groups_claim` -- name of claim (field) that contains list of groups user belongs to. This claim will be looked up in the token itself (in case token is a valid JWT, e.g. in Keycloak) or in response from `/userinfo`. Optional, default: "groups".
27
27
28
-
For each type, there are additional specific parameters.
28
+
For each type, there are additional specific parameters.
29
29
If some parameters that are not required for current processor type are specified, they are ignored.
30
30
If there are conflicting parameters (e.g `algo` is specified together with `jwks_uri`), an exception will be thrown.
31
31
32
32
## JWT (JSON Web Token)
33
33
34
-
JWT itself is a source of information about user.
34
+
JWT itself is a source of information about user.
35
35
It is decoded locally and its integrity is verified using either static key or JWKS (JSON Web Key Set), either local or remote.
36
36
37
37
`algo`, `static_jwks`/`static_jwks_file` and `jwks_uri` are defining different JWT processing workflows, and they cannot be specified together.
@@ -48,7 +48,7 @@ It is decoded locally and its integrity is verified using either static key or J
48
48
</clickhouse>
49
49
```
50
50
**Parameters:**
51
-
-`algo` - Algorithm for validate signature. Mandatory. Supported values:
51
+
-`algo` - Algorithm for signature validation. Mandatory. Supported values:
52
52
53
53
| HMAC | RSA | ECDSA | PSS | EdDSA |
54
54
|-------| ----- | ------ | ----- | ------- |
@@ -168,7 +168,7 @@ Either `configuration_endpoint` or both `userinfo_endpoint` and `token_introspec
168
168
Sometimes a token is a valid JWT. In that case token will be decoded and validated locally if configuration endpoint returns JWKS URI (or `jwks_uri` is specified alongside `userinfo_endpoint` and `token_introspection_endpoint`).
169
169
170
170
### Tokens cache
171
-
To reduce number of requests to IdP, tokens are cached internally for no longer then`token_cache_lifetime` seconds.
171
+
To reduce number of requests to IdP, tokens are cached internally for a maximum period of`token_cache_lifetime` seconds.
172
172
If token expires sooner than `token_cache_lifetime`, then cache entry for this token will only be valid while token is valid.
173
173
If token lifetime is longer than `token_cache_lifetime`, cache entry for this token will be valid for `token_cache_lifetime`.
174
174
@@ -190,7 +190,7 @@ Example (goes into `users.xml`):
190
190
</clickhouse>
191
191
```
192
192
193
-
Here, the JWT payload must contain `["view-profile"]` on path `resource_access.account.roles`, otherwise authentication will not succeed even with a valid JWT.
193
+
Here, the JWT payload must contain `["view-profile"]` on path `resource_access.account.roles`, otherwise authentication will not succeed even with a valid JWT.
194
194
195
195
:::note
196
196
If `claims` is defined, this user will not be able to authenticate using opaque tokens, so, only JWT-based authentication will be available.
@@ -209,7 +209,7 @@ If `claims` is defined, this user will not be able to authenticate using opaque
209
209
```
210
210
211
211
:::note
212
-
JWT authentication cannot be used together with any other authentication method. The presence of any other sections like `password` alongside `jwt` will force ClickHouse to shut down.
212
+
A user cannot have JWT authentication together with any other authentication method. The presence of any other sections like `password` alongside `jwt` will force ClickHouse to shut down.
213
213
:::
214
214
215
215
## Enabling token authentication using SQL {#enabling-jwt-auth-using-sql}
@@ -219,10 +219,10 @@ Users with "JWT" authentication type cannot be created using SQL now.
219
219
## Identity Provider as an External User Directory {#idp-external-user-directory}
220
220
221
221
If there is no suitable user pre-defined in ClickHouse, authentication is still possible: Identity Provider can be used as source of user information.
222
-
To allow this, add `token` section to the `users_directories` section of the `config.xml` file.
222
+
To allow this, add `token` section to the `users_directories` section of the `config.xml` file.
223
223
224
224
At each login attempt, ClickHouse tries to find the user definition locally and authenticate it as usual.
225
-
If the user is not defined, ClickHouse will treat the user as externally defined and will try to validate the token and get user information from the specified processor.
225
+
If a token is provided but the user is not defined, ClickHouse will treat the user as externally defined and will try to validate the token and get user information from the specified processor.
226
226
If validated successfully, the user will be considered existing and authenticated. The user will be assigned roles from the list specified in the `roles` section.
227
227
All this implies that the SQL-driven [Access Control and Account Management](/docs/en/guides/sre/user-management/index.md#access-control) is enabled and roles are created using the [CREATE ROLE](/docs/en/sql-reference/statements/create/role.md#create-role-statement) statement.
228
228
@@ -232,7 +232,7 @@ All this implies that the SQL-driven [Access Control and Account Management](/do
if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_OK || !response_stream)
54
54
throwException(ErrorCodes::AUTHENTICATION_FAILED, "Failed to get user info by access token, code: {}, reason: {}", response.getStatus(), response.getReason());
LOG_TRACE(getLogger("AccessTokenAuthentication"), "Attempt to authenticate user {} with expired access token by {}", credentials.getUserName(), processor.getProcessorName());
Copy file name to clipboardExpand all lines: src/Access/TokenAccessStorage.h
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,7 @@ class TokenAccessStorage : public IAccessStorage
40
40
boolisReadOnly() constoverride { returntrue; }
41
41
boolexists(const UUID & id) constoverride;
42
42
43
-
private:// IAccessStorage implementations.
44
-
43
+
private:
45
44
mutable std::recursive_mutex mutex; // Note: Reentrance possible by internal role lookup via access_control
46
45
AccessControl & access_control;
47
46
const Poco::Util::AbstractConfiguration & config;
@@ -56,10 +55,9 @@ class TokenAccessStorage : public IAccessStorage
56
55
mutable std::map<String, std::set<String>> roles_per_users; // user name -> role names (...that should be granted to it; may but don't have to include common roles)
57
56
mutable std::map<UUID, String> granted_role_names; // (currently granted) role id -> its name
58
57
mutable std::map<String, UUID> granted_role_ids; // (currently granted) role name -> its id
0 commit comments