Skip to content

Commit 4fa7c42

Browse files
authored
Merge pull request #338 from Accenture/251-blacklist-docs
251 - added docs section for JWT blacklisting
2 parents 4196c8f + 58b2ba3 commit 4fa7c42

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Added new version - `v3` - for internal endpoints to support response code in the `/responses` endpoint
1717
- Added Helm v3 template to the `deployment` folder [#288](https://github.com/Accenture/reactive-interaction-gateway/issues/288)
1818
- Added detailed features summary on the website with architecture diagrams. [#284](https://github.com/Accenture/reactive-interaction-gateway/issues/284)
19+
- Added [documentation section](https://accenture.github.io/reactive-interaction-gateway/docs/jwt-blacklisting.html) for the JWT Blacklist feature. [#156](https://github.com/Accenture/reactive-interaction-gateway/issues/156)
1920

2021
### Changed
2122

docs/jwt-blacklisting.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
id: jwt-blacklisting
3+
title: JWT Blacklisting
4+
sidebar_label: JWT Blacklisting
5+
---
6+
7+
[JWT](https://jwt.io/) Blacklisting is one of the RIG's core features. Imagine a use case where someone does a malicious action using specific JWT. By blacklisting this JWT, you can prevent any other malicious actions. Once it's blacklisted, user is not able to do any action within the RIG (unless it's an unsecured action -- e.g. unsecured reverse proxy endpoint).
8+
9+
You can blacklist a JWT via REST API call to `POST :4010/v3/session-blacklist` and in body specify the `sessionId` and `validityInSeconds`. `sessionId` is by default expecting [JWT ID - JTI](https://tools.ietf.org/html/rfc7519#page-10), but you can change it via `JWT_SESSION_FIELD` env var.
10+
11+
Blacklist is using so called [ETS](http://erlang.org/doc/man/ets.html) tables to store JTIs and their expiration time. These information are automatically synchronized across RIG cluster. That means you can blacklist a JWT via whatever RIG node and it will apply to all RIG nodes. Blacklisted JTIs in ETS tables are cleaned up based on the `validityInSeconds` property provided in a request.
12+
13+
> `validityInSeconds` should be ideally set to at least _**JWT expiration time - current time**_.
14+
15+
## API
16+
17+
There are 2 APIs that are easily accessible via built-in Swagger UI (`your_host:4010/swagger-ui`).
18+
19+
- `POST :4010/v3/session-blacklist` - to blacklist a JWT
20+
- `GET :4010/v3/session-blacklist/{sessionId}` - to check whether JWT is blacklisted at the moment
21+
22+
## Example
23+
24+
JWT used below has the following payload:
25+
26+
```json
27+
{
28+
"sub": "1234567890",
29+
"name": "John Doe",
30+
"iat": 1516239022,
31+
"jti": "johndoe",
32+
"exp": 4516239022
33+
}
34+
```
35+
36+
Run in terminal:
37+
38+
```bash
39+
# run RIG - note the "secured" field in the PROXY_CONFIG_FILE
40+
docker run -d --name rig \
41+
-e PROXY_CONFIG_FILE='[{"id":"service","name":"service","auth_type":"jwt","auth":{"use_header":true,"header_name":"Authorization","use_query":false,"query_name":""},"versioned":false,"version_data":{"default":{"endpoints":[{"id":"secured","path_regex":"todos/1","method":"GET","secured":true}]}},"proxy":{"target_url":"http://jsonplaceholder.typicode.com","port":80}}]' \
42+
-e JWT_SECRET_KEY='rigsecret' \
43+
-p 4000:4000 \
44+
-p 4010:4010 \
45+
accenture/reactive-interaction-gateway
46+
47+
# check if JWT is blacklisted - should return "Not found.", that means it's not blacklisted
48+
curl "http://localhost:4010/v3/session-blacklist/johndoe" \
49+
-H "accept: application/json"
50+
51+
# call an API - should return some data
52+
curl http://localhost:4000/todos/1 \
53+
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJqdGkiOiJqb2huZG9lIiwiZXhwIjo0NTE2MjM5MDIyfQ.gPP_Ya_QphNAas3NXqqlfwvyzy_TSN5sh_eMqX0Xnf4"
54+
55+
# blacklist the JWT for 60 seconds
56+
curl -X POST "http://localhost:4010/v3/session-blacklist" -H "accept: application/json" -H "content-type: application/json" -d "{ \"validityInSeconds\": 60,\"sessionId\": \"johndoe\"}"
57+
58+
# check if JWT is blacklisted - should return empty response, that means it's blacklisted
59+
curl "http://localhost:4010/v3/session-blacklist/johndoe" \
60+
-H "accept: application/json"
61+
62+
# call an API - should return "Authentication failed."
63+
curl http://localhost:4000/todos/1 \
64+
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJqdGkiOiJqb2huZG9lIiwiZXhwIjo0NTE2MjM5MDIyfQ.gPP_Ya_QphNAas3NXqqlfwvyzy_TSN5sh_eMqX0Xnf4"
65+
```
66+
67+
You can restrict access also to your WS/SSE/Longpolling connections/subscriptions via `SUBSCRIPTION_CHECK` env var, check the [ops guide](./rig-ops-guide.md).

website/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"title": "Intro",
6666
"sidebar_label": "Intro"
6767
},
68+
"jwt-blacklisting": {
69+
"title": "JWT Blacklisting",
70+
"sidebar_label": "JWT Blacklisting"
71+
},
6872
"metrics-details": {
6973
"title": "Metrics Details",
7074
"sidebar_label": "Metrics Details"

website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"Advanced Guides": [
2020
"api-gateway-management",
2121
"api-gateway-synchronization",
22-
"avro"
22+
"avro",
23+
"jwt-blacklisting"
2324
],
2425
"RIG in Production": [
2526
"rig-ops-guide",

0 commit comments

Comments
 (0)