Skip to content

Commit ddbac49

Browse files
committed
feat: update readme
1 parent dbfb907 commit ddbac49

File tree

2 files changed

+198
-198
lines changed

2 files changed

+198
-198
lines changed

README.md

Lines changed: 198 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,205 @@ plugins of EMQ for forwarding these requests to Soteria and doing Authentication
6363
EMQ has caching mechanism, but it sends requests almost for each Publish message to Soteria.
6464
PS: On Subscribe we have only one message from client that need authorization and other messages are coming from server.
6565

66-
## Deployment
66+
## Architecture
6767

68-
### Add Vendor
68+
![arch](docs/arch.png)
6969

70-
Soteria is a multivendor authenticator for EMQX.
71-
Follow instruction from [here](docs/vendor.md)
70+
## Support Vendors
7271

73-
### Architecture
72+
Soteria supports having multiple vendors at the same time.
73+
Means you can use single cluster for multiple companies at the same time and validate their tokens
74+
and control accesses.
7475

75-
![architectureOfSoteria](docs/arch.png)
76+
### Vendor Configuration
77+
78+
```yaml
79+
company: "<<company_name>>"
80+
driver_salt: ""
81+
passenger_salt: ""
82+
passenger_hash_length: 15
83+
driver_hash_length: 15
84+
allowed_access_types: ["pub", "sub"]
85+
keys:
86+
iss-0: "key-value"
87+
iss-1: "key-value"
88+
iss_entity_map:
89+
0: "entity-0"
90+
1: "entity-1"
91+
default: "default-entity"
92+
iss_peer_map:
93+
0: "peer-0"
94+
1: "peer-1"
95+
default: "default-peer"
96+
jwt:
97+
iss_name: "iss"
98+
sub_name: "sub"
99+
signing_method: "RS512"
100+
topics:
101+
- topic1
102+
- topic2
103+
- ...
104+
```
105+
106+
### HashID Manager
107+
108+
`driver_salt`,`passenger_salt`, `passenger_hash_length`, `driver_hash_length` are used for HashIDManager.
109+
This component only works for passenger and driver issuers.
110+
111+
### Keys
112+
113+
This is a map of issuer to key for opening JWT token.
114+
115+
#### IssEntityMap & IssPeerMap
116+
117+
These two configuration map iss to entity and peer respectively.
118+
119+
**Note**: default case is `required`
120+
121+
```yaml
122+
iss_entity_map:
123+
0: "driver"
124+
1: "passenger"
125+
default: "none"
126+
iss_peer_map:
127+
0: "passenger"
128+
1: "driver"
129+
default: "none"
130+
```
131+
132+
In the example above, we have two maps for entity & peer maps. As it's clear for **entity** structure **0** and **1** is mapped to **driver** and **passenger**, respectively. Vice Versa, for peer structure it can be seen that **1** and **0** is mapped to **driver** and **passenger**. We have also the **default** key for both two cases.
133+
134+
In the topic example, we have an accesses section in which **0** is mapped to **2** and **1** is mapped to **-1** which can be interpreted as a map from **IssEntity's Keys** to **Access Types**. In the other words this structure means:
135+
136+
- **Driver** has a **Pub** access on topic
137+
- **Passenger** has a **None** access on topic (No Access)
138+
139+
### JWT
140+
141+
This is the JWT configuration. `iss_name` and `sub_name` are the name of issuer
142+
and subject in the JWT token's payload respectively.
143+
144+
`signing_method` is the method that is used to sign the JWT token.
145+
Here are list of different signing methods
146+
147+
- ES384
148+
- RS512 \*
149+
- PS512
150+
- RS384 \*
151+
- HS256 \*
152+
- HS384 \*
153+
- RS256 \*
154+
- PS384
155+
- ES256
156+
- ES512
157+
- EdDSA
158+
- HS512 \*
159+
- PS256
160+
**Note**: only the methods with `*` are supported for now.
161+
162+
### Topic Configuration
163+
164+
```yaml
165+
type: "<<Name>>"
166+
template: "<<regex template>>"
167+
hash_type: 0|1
168+
accesses:
169+
iss-0: "<<access>>"
170+
iss-1: "<<access>>"
171+
```
172+
173+
### Template
174+
175+
Topic template is a string consist of [Variables](##Available_Variables) and [Functions](##Available_Functions)
176+
and regular expressions.
177+
178+
Variables and Function are replaced first, and then the whole template will compile as a regular expression.
179+
The end result will be compared against the requested topic.
180+
181+
#### Example
182+
183+
This is template topic given in `vendor:topics[#]:template`.
184+
185+
```yaml
186+
- type: driver_location
187+
template: ^{{.company}}/driver/{{.sub}}/location$
188+
accesses:
189+
0: "2"
190+
1: "-1"
191+
```
192+
193+
```regex
194+
^{{.company}}/driver/{{HashID .hashType .sub (IssToSnappID .iss)}}/location/[a-zA-Z0-9-_]+$
195+
```
196+
197+
After parsing the template we get something like this
198+
199+
```regex
200+
// company=snapp
201+
// hashType=0
202+
// sub=D96ZbvJakLp4PYd
203+
// iss=0
204+
^snapp/driver/D96ZbvJakLp4PYd/location/[a-zA-Z0-9-_]+$
205+
```
206+
207+
Now if the requested topic match the created topic it is considered as a valid topic for that particular user.
208+
209+
```text
210+
requested_topic: snapp/driver/D96ZbvJakLp4PYd/location/23fw49vxd
211+
created_topic_regex: ^snapp/driver/D96ZbvJakLp4PYd/location/[a-zA-Z0-9-_]+$
212+
```
213+
214+
#### Available Variables
215+
216+
These are the variables available to use in the topic templates.
217+
218+
- `iss`
219+
issuer obtained from JWT token
220+
- `sub`
221+
subject obtained from JWT token
222+
- `hashType`
223+
Hash type field defined in topic template configuration
224+
225+
| HashType | Value |
226+
| -------- | ----- |
227+
| HashID | 0 |
228+
| MD5 | 1 |
229+
230+
- `company`
231+
company field defined in vendor configuration
232+
233+
#### Available Functions
234+
235+
These are the function available to use in the topic templates.
236+
237+
- `IssToEntity(iss string) string`
238+
convert `iss` obtained from JWT token to defined entity in `issEntityMap`
239+
- `IssToPeer(iss string) string`
240+
convert `iss` obtained from JWT token to define peer in `issPeerMap`
241+
- `IssToSnappID(iss string) string`
242+
convert `iss` obtained from JWT token to `snappid.audience`
243+
- `HashID(hashType int, sub string, snappID snappid.audience)`
244+
generated `hashID` for the given `subject` base on the `hashType` and `snappid.audience`
245+
246+
**Note**: `snappid.audience` only is available for issuer 0 and 1 which are for driver and passenger respectively.
247+
248+
#### Accesses
249+
250+
List of all types of access on a topic.
251+
252+
| Access | Value |
253+
| ------------------- | ----- |
254+
| Subscribe | 1 |
255+
| Publish | 2 |
256+
| Subscribe & Publish | 3 |
257+
| None | -1 |
258+
259+
#### Suggested Issuers
260+
261+
Use any value for issuer but if you have an entity called `Driver` or `Passenger`,
262+
we recommend use the following issuers for them.
263+
264+
| Issuer | Value |
265+
| --------- | ----- |
266+
| Driver | 0 |
267+
| Passenger | 1 |

0 commit comments

Comments
 (0)