Skip to content

Commit 5dcad75

Browse files
committed
fix crash when key id not found, fix failing tests
1 parent ab0b1fe commit 5dcad75

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

src/Access/TokenProcessorsJWT.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ bool JwksJwtProcessor::resolveAndValidate(TokenCredentials & credentials) const
322322
return false;
323323
}
324324

325+
if (!decoded_jwt.has_key_id())
326+
{
327+
LOG_ERROR(getLogger("TokenAuthentication"), "{}: 'kid' (key ID) claim not found in token", processor_name);
328+
return false;
329+
}
330+
325331
auto jwk = provider->getJWKS().get_jwk(decoded_jwt.get_key_id());
326332
auto username = decoded_jwt.get_payload_claim(username_claim).as_string();
327333

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<clickhouse>
2-
<jwt_validators>
2+
<token_processors>
33

4-
<single_key_validator>
4+
<single_key_processor>
5+
<type>jwt</type>
56
<algo>HS256</algo>
67
<static_key>my_secret</static_key>
78
<static_key_in_base64>false</static_key_in_base64>
8-
</single_key_validator>
9+
</single_key_processor>
910

10-
<another_single_key_validator>
11+
<another_single_key_processor>
12+
<type>jwt</type>
1113
<algo>hs256</algo>
1214
<static_key>other_secret</static_key>
1315
<static_key_in_base64>false</static_key_in_base64>
14-
</another_single_key_validator>
16+
</another_single_key_processor>
1517

16-
<static_jwks_validator>
17-
<static_jwks>{"keys": [{"kty": "RSA", "alg": "rs256", "kid": "mykid", "n": "lICGC8S5pObyASih5qfmwuclG0oKsbzY2z9vgwqyhTYQOWcqYcTjVV4aQ30qb6E0-5W6rJ-jx9zx6GuAEGMiG_aWJEdbUAMGp-L1kz4lrw5U6GlwoZIvk4wqoRwsiyc-mnDMQAmiZLBNyt3wU6YnKgYmb4O1cSzcZ5HMbImJpj4tpYjqnIazvYMn_9Pxjkl0ezLCr52av0UkWHro1H4QMVfuEoNmHuWPww9jgHn-I-La0xdOhRpAa0XnJi65dXZd4330uWjeJwt413yz881uS4n1OLOGKG8ImDcNlwU_guyvk0n0aqT0zkOAPp9_yYo13MPWmiRCfOX8ozdN7VDIJw", "e": "AQAB"}]}</static_jwks>
18-
</static_jwks_validator>
19-
20-
<jwks_server>
21-
<uri>http://resolver:8080/.well-known/jwks.json</uri>
22-
</jwks_server>
23-
</jwt_validators>
18+
<remote_jwks_processor>
19+
<type>jwt</type>
20+
<jwks_uri>http://resolver:8080/.well-known/jwks.json</jwks_uri>
21+
</remote_jwks_processor>
22+
</token_processors>
2423
</clickhouse>

tests/integration/test_jwt_auth/test.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,6 @@ def test_static_key(started_cluster):
6363
assert res == "jwt_user\n"
6464

6565

66-
def test_static_jwks(started_cluster):
67-
res = client.exec_in_container(
68-
[
69-
"bash",
70-
"-c",
71-
curl_with_jwt(
72-
token="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im15a2lkIn0."
73-
"eyJzdWIiOiJqd3RfdXNlciIsImlzcyI6InRlc3RfaXNzIn0."
74-
"CUioyRc_ms75YWkUwvPgLvaVk2Wmj8RzgqDALVd9LWUzCL5aU4yc_YaA3qnG_NoHd0uUF4FUjLxiocRoKNEgsE2jj7g_"
75-
"wFMC5XHSHuFlfIZjovObXQEwGcKpXO2ser7ANu3k2jBC2FMpLfr_sZZ_GYSnqbp2WF6-l0uVQ0AHVwOy4x1Xkawiubkg"
76-
"W2I2IosaEqT8QNuvvFWLWc1k-dgiNp8k6P-K4D4NBQub0rFlV0n7AEKNdV-_AEzaY_IqQT0sDeBSew_mdR0OH_N-6-"
77-
"FmWWIroIn2DQ7pq93BkI7xdkqnxtt8RCWkCG8JLcoeJt8sHh7uTKi767loZJcPPNaxKA",
78-
ip=cluster.get_instance_ip(instance.name),
79-
),
80-
]
81-
)
82-
assert res == "jwt_user\n"
83-
84-
8566
def test_jwks_server(started_cluster):
8667
res = client.exec_in_container(
8768
[

0 commit comments

Comments
 (0)