Skip to content

Commit 98172fc

Browse files
author
Rishav Kumar
committed
Update documentation about support of direct JWKS with JWT
1 parent 5ab4593 commit 98172fc

File tree

1 file changed

+90
-7
lines changed
  • _security/authentication-backends

1 file changed

+90
-7
lines changed

_security/authentication-backends/jwt.md

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,25 +227,108 @@ Validating the signature of the signed JWT is the last step in granting user acc
227227

228228
Rather than store the cryptographic key used for validation in the local `config.yml` file's `authc` section, you can specify a JSON Web Key Set (JWKS) endpoint to retrieve the key from its location on the issuer's server. This method of validating the JWT can help streamline management of public keys and certificates.
229229

230-
In OpenSearch, this method of validation makes use of the [OpenID Connect authentication domain configuration]({{site.url}}{{site.baseurl}}/security/authentication-backends/openid-connect/#configure-openid-connect-integration). To specify the JWKS endpoint, replace the `openid_connect_url` setting in the configuration with the `jwks_uri` setting and add the URL to the setting as its value. This is shown in the following example:
230+
Starting with OpenSearch 3.3, JWT authentication now supports JWKS endpoints directly.
231+
232+
### Direct JWKS support with JWT authentication
233+
234+
You can now configure JWKS endpoints directly in the JWT authentication domain. This approach provides enhanced security through automated key rotation and dynamic key management.
231235

232236
```yml
233-
openid_auth_domain:
237+
jwt_auth_domain:
238+
description: "Authenticate via JSON Web Token"
234239
http_enabled: true
235240
transport_enabled: true
236241
order: 0
237242
http_authenticator:
238-
type: openid # use the OpenID Connect domain, since JWT is part of this authentication.
243+
type: jwt
239244
challenge: false
240245
config:
241-
subject_key: preferred_username
242-
roles_key: roles
243-
jwks_uri: https://keycloak.example.com:8080/auth/realms/master/.well-known/jwks-keys.json
246+
jwks_uri: "https://example.com/.well-known/jwks.json"
247+
signing_key: null # Not used when jwks_uri is specified
248+
jwt_header: "Authorization"
249+
jwt_url_parameter: null
250+
jwt_clock_skew_tolerance_seconds: 30
251+
roles_key: "roles"
252+
subject_key: "sub"
244253
authentication_backend:
245254
type: noop
246255
```
247256

248-
The endpoint should be documented by the JWT issuer. You can use it to retrieve the keys needed to validate the signed JWT. For more information about the content and format of JSON Web Keys, see [JSON Web Key (JWK) format](https://datatracker.ietf.org/doc/html/rfc7517#section-4).
257+
### JWKS configuration parameters
258+
259+
The following table describes the JWKS-specific configuration parameters:
260+
261+
Name | Description | Default
262+
:--- | :--- | :---
263+
`jwks_uri` | The JWKS endpoint URL. When specified, `signing_key` is ignored and keys are retrieved from this endpoint. | `null`
264+
265+
### (Advanced) Security protection
266+
267+
To help protect against denial-of-service (DoS) attacks and ensure secure JWKS operations, the Security plugin provides several protective measures including request limits, timeouts, and response size restrictions.
268+
269+
Name | Description | Default
270+
:--- | :--- | :---
271+
`max_jwks_keys` | Maximum number of keys to process from the JWKS response. Set to `-1` for no limits. | `-1`
272+
`jwks_request_timeout_ms` | Maximum time in milliseconds allowed for a single HTTP request to the JWKS endpoint. | `5000`
273+
`jwks_queued_thread_timeout_ms` | Maximum time in milliseconds a request can wait in the queue before processing. | `2500`
274+
`max_jwks_response_size_bytes` | Maximum size in bytes for JWKS endpoint responses. | `1048576` (1MB)
275+
`refresh_rate_limit_count` | Maximum number of JWKS refresh requests allowed within the time window. | `10`
276+
`refresh_rate_limit_time_window_ms` | Time window in milliseconds for rate limiting JWKS refresh requests. | `10000` (10 seconds)
277+
278+
### JWT header with Key ID
279+
280+
When using JWKS, your JWT header must include a Key ID (`kid`) that identifies which specific key to use for verification:
281+
282+
```json
283+
{
284+
"alg": "RS256",
285+
"typ": "JWT",
286+
"kid": "V-diposfUJIk5jDBFi_QRouiVinG5PowskcSWy5EuCo"
287+
}
288+
```
289+
290+
The `kid` parameter is required when using JWKS endpoints and must match a key identifier in the JWKS response.
291+
292+
### Sample JWKS response
293+
294+
The JWKS endpoint should return a JSON object containing an array of public keys. Each key must include metadata such as the key type (`kty`), usage (`use`), key ID (`kid`), and algorithm (`alg`):
295+
296+
```json
297+
{
298+
"keys": [
299+
{
300+
"kty": "RSA",
301+
"use": "sig",
302+
"kid": "V-diposfUJIk5jDBFi_QRouiVinG5PowskcSWy5EuCo",
303+
"alg": "RS256",
304+
"n": "nCJ9ve8zRv_4pdSja5i_8GgozoVZrUocD6UnMyQmh6fRBZWspoIRSGdTjcKktevnKWXlg7mqe7FIx6CdVqR5rVfM0o61_7cgxJqdNdnCXsFR8_S_98qMIJ-gxmlwE2a1X1VrCSmYh60APUGoGypm0sAsjvYTzU04LTN7K0Gip3H5qpkFD-Mxlev75WeC8WrvsfUFl6XN1h55HZW2wlYJGmbFVQx5839d8o6BxDVvQrGdN8MzLRFTMG8wiPhVDQL5NHt3vKgDnD6zT0c_S5Kz42i4bcktRRoAbR3LjDn5YbAatmfKzwOuL0XsbEnn-kgnt2aJ5GCaggukY3mMc-Bhew",
305+
"e": "AQAB"
306+
}
307+
]
308+
}
309+
```
310+
311+
### Caching and performance
312+
313+
JWKS responses are cached to optimize performance:
314+
315+
- **Initial cache**: When JWKS is enabled, the system caches the JWKS endpoint response
316+
- **Cache refresh triggers**:
317+
- When a JWT contains a `kid` not found in the cache
318+
- When cache entries expire based on HTTP cache headers
319+
- During background refresh cycles
320+
- **Rate limiting**: Prevents excessive requests to the JWKS endpoint (10 requests per 10-second window by default)
321+
322+
### Backward compatibility
323+
324+
The JWKS feature maintains full backward compatibility:
325+
326+
- When `jwks_uri` is not specified or set to `null`, the system uses the existing static `signing_key` mechanism
327+
- Existing JWT configurations continue to work without modification
328+
- You can switch between static keys and JWKS by updating the configuration
329+
- When both `jwks_uri` and `signing_key` are configured, `jwks_uri` takes precedence and `signing_key` is ignored
330+
331+
For more information about the content and format of JSON Web Keys, see [JSON Web Key (JWK) format](https://datatracker.ietf.org/doc/html/rfc7517#section-4).
249332

250333

251334
## Troubleshooting common issues

0 commit comments

Comments
 (0)