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
+70-47Lines changed: 70 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,26 +13,34 @@ ClickHouse users can be authenticated using tokens. This works in two ways:
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
-
##Token Processors
16
+
# Token Processors
17
17
18
-
To use token-based authentication, add `token_processors` section to `config.xml` and define at least one token processor in it. Its contents are different for different token processing workflows (JWT and opaque (generic) tokens).
18
+
## Configuration
19
+
To use token-based authentication, add `token_processors` section to `config.xml` and define at least one token processor in it.
20
+
Its contents are different for different token processor types.
19
21
20
-
### Common configuration parameters
21
-
In addition to specific parameters (see below), there are also parameters that can be applied to a token processor of any type:
22
-
-`cache_lifetime` -- maximum lifetime of cached token (in seconds). Optional, default: 3600.
22
+
**Common parameters**
23
+
-`type` -- type of token processor. Supported values: "JWT", "Azure", "OpenID". Mandatory. Case-insensitive.
24
+
-`token_cache_lifetime` -- maximum lifetime of cached token (in seconds). Optional, default: 3600.
23
25
-`username_claim` -- name of claim (field) that will be treated as ClickHouse username. Optional, default: "sub".
24
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".
25
27
26
-
### JWT (JSON Web Token)
28
+
For each type, there are additional specific parameters.
29
+
If some parameters that are not required for current processor type are specified, they are ignored.
30
+
If there are conflicting parameters (e.g `algo` is specified together with `jwks_uri`), an exception will be thrown.
27
31
28
-
JWT itself is a source of information about user. It can be decoded locally, and its integrity can be verified using token issuer's (public) key.
32
+
## JWT (JSON Web Token)
29
33
30
-
This key can exist in three ways:
31
-
*##### Static key:
34
+
JWT itself is a source of information about user.
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
+
37
+
`algo`, `static_jwks`/`static_jwks_file` and `jwks_uri` are defining different JWT processing workflows, and they cannot be specified together.
38
+
### JWT with static key:
32
39
```xml
33
40
<clickhouse>
34
41
<token_processors>
35
42
<my_static_key_validator>
43
+
<type>jwt</type>
36
44
<algo>HS256</algo>
37
45
<static_key>my_static_secret</static_key>
38
46
</my_static_key_validator>
@@ -49,25 +57,28 @@ This key can exist in three ways:
49
57
| HS512 | RS512 | ES512 | PS512 ||
50
58
||| ES256K |||
51
59
Also supports None (though not recommended).
60
+
`claims` - A string containing a JSON object that should be contained in the token payload. If this parameter is defined, token without corresponding payload will be considered invalid. Optional.
52
61
-`static_key` - key for symmetric algorithms. Mandatory for `HS*` family algorithms.
53
62
-`static_key_in_base64` - indicates if the `static_key` key is base64-encoded. Optional, default: `False`.
54
63
-`public_key` - public key for asymmetric algorithms. Mandatory except for `HS*` family algorithms and `None`.
55
64
-`private_key` - private key for asymmetric algorithms. Optional.
56
65
-`public_key_password` - public key password. Optional.
-`claims` - A string containing a JSON object that should be contained in the token payload. If this parameter is defined, token without corresponding payload will be considered invalid. Optional.
@@ -81,63 +92,85 @@ Only one of `static_jwks` or `static_jwks_file` keys must be present in one veri
-`jwks_refresh_timeout` - Period for resend request for refreshing JWKS. Optional, default: 300000.
111
+
-`jwks_cache_lifetime` - Period for resend request for refreshing JWKS. Optional, default: 3600.
100
112
-`claims` - A string containing a JSON object that should be contained in the token payload. If this parameter is defined, token without corresponding payload will be considered invalid. Optional.
101
113
-`verifier_leeway` - Clock skew tolerance (seconds). Useful for handling small differences in system clocks between ClickHouse and the token issuer. Optional.
102
114
103
115
104
-
### Opaque tokens
116
+
## Processors with external providers
117
+
118
+
Some tokens cannot be decoded and validated locally. External service is needed in this case. "Azure" and "OpenID" (a generic type) are supported now.
105
119
106
-
To define a token processor, add `token_processors` section to `config.xml`. Example:
120
+
### Azure
107
121
```xml
108
122
<clickhouse>
109
123
<token_processors>
110
-
<azuure>
111
-
<provider>openid</provider>
112
-
<cache_lifetime>600</cache_lifetime>
113
-
<username_claim>sub</username_claim>
114
-
<groups_claim>groups</groups_claim>
115
-
</azuure>
124
+
<azure_processor>
125
+
<type>azure</type>
126
+
</azure_processor>
116
127
</token_processors>
117
128
</clickhouse>
118
129
```
119
130
120
-
:::note
121
-
Different providers have different sets of parameters.
-`provider` -- name of identity provider. Mandatory, case-insensitive. Supported options: "Google", "Azure", "OpenID".
127
-
-`configuration_endpoint` -- URI of `.well-known/openid-configuration`. Optional parameter, used only for OpenID providers.
128
-
-`userinfo_endpoint` -- URI of userinfo endpoint. Optional parameter. Optional parameter, used only for OpenID providers.
129
-
-`token_introspection_endpoint` -- URI of token introspection endpoint. Optional parameter. Optional parameter, used only for OpenID providers.
130
-
131
155
:::note
132
-
Either `configuration_endpoint` or both `userinfo_endpoint` and `token_introspection_endpoint` shall be set. If none of them are set or all three are set, this is an invalid configuration that will not be parsed.
156
+
Either `configuration_endpoint` or both `userinfo_endpoint` and `token_introspection_endpoint`(and, optionally, `jwks_uri`) shall be set. If none of them are set or all three are set, this is an invalid configuration that will not be parsed.
133
157
:::
134
158
159
+
**Parameters:**
160
+
161
+
-`configuration_endpoint` - URI of OpenID configuration (often ends with `.well-known/openid-configuration`);
162
+
-`userinfo_endpoint` - URI of endpoint that returns user information in exchange for a valid token;
163
+
-`token_introspection_endpoint` - URI of token introspection endpoint (returns information about a valid token);
164
+
-`jwks_uri` - URI of OpenID configuration (often ends with `.well-known/jwks.json`)
165
+
-`jwks_cache_lifetime` - Period for resend request for refreshing JWKS. Optional, default: 3600.
166
+
-`verifier_leeway` - Clock skew tolerance (seconds). Useful for handling small differences in system clocks between ClickHouse and the token issuer. Optional, default: 60
135
167
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`).
136
169
137
170
### Tokens cache
138
-
To reduce number of requests to IdP, tokens are cached internally for no longer then `cache_lifetime` seconds.
139
-
If token expires sooner than `cache_lifetime`, then cache entry for this token will only be valid while token is valid.
140
-
If token lifetime is longer than `cache_lifetime`, cache entry for this token will be valid for `cache_lifetime`.
171
+
To reduce number of requests to IdP, tokens are cached internally for no longer then `token_cache_lifetime` seconds.
172
+
If token expires sooner than `token_cache_lifetime`, then cache entry for this token will only be valid while token is valid.
173
+
If token lifetime is longer than `token_cache_lifetime`, cache entry for this token will be valid for `token_cache_lifetime`.
141
174
142
175
## Enabling token authentication for a user in `users.xml` {#enabling-jwt-auth-in-users-xml}
143
176
@@ -181,17 +214,7 @@ JWT authentication cannot be used together with any other authentication method.
181
214
182
215
## Enabling token authentication using SQL {#enabling-jwt-auth-using-sql}
183
216
184
-
When [SQL-driven Access Control and Account Management](/docs/en/guides/sre/user-management/index.md#access-control) is enabled in ClickHouse, users identified by JWT authentication can also be created using SQL statements.
185
-
186
-
```sql
187
-
CREATEUSERmy_user IDENTIFIED WITH jwt CLAIMS '{"resource_access":{"account": {"roles": ["view-profile"]}}}'
188
-
```
189
-
190
-
Or without additional JWT payload checks:
191
-
192
-
```sql
193
-
CREATEUSERmy_user IDENTIFIED WITH jwt
194
-
```
217
+
Users with "JWT" authentication type cannot be created using SQL now.
195
218
196
219
## Identity Provider as an External User Directory {#idp-external-user-directory}
0 commit comments