1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# API Authn/Authz
* Authn: Prove who you say you are (e.g. passport)
* Authz: Prove that you're allowed to do what you're trying to do. (e.g. plane ticket)
## Example
* [Auth0][5]
* provides [OpenID Connect][4].
* returns an access token.
* UI (:3000)
* initiates a login/logout with Auth0.
* retrieves data from the api using the access token.
* API (:4000)
* authorizes requests using the access token from the request.
* returns data via a REST API.
```
||========================||
---------- --------- || --------------- ------ ||
| UI | | Auth0 | || | API ||| PDP | | DB | ||
---------- --------- || --------------- ------ ||
| | || | | | ||
| GET /login | || | | | ||
|----------->| || | | | ||
|<-----------| || | | | ||
| "x.y.z" | || | | | ||
| | || | | | ||
| GET /atlas/{id} || | | | ||
| Authorization: "x.y.z" | | | ||
|----------------------->| | | ||
| | || |------>| | ||
| | || | allow | | ||
| | || |<------| | ||
| | || | | | ||
| | || |-------------->| ||
| | || | | | ||
| | || |<--------------| ||
|<-----------------------| | | ||
| | || | | | ||
| DELETE /atlas/{id}| | | | ||
| Authorization: "x.y.z" | | | ||
|----------------------->| | | ||
| | || |------>| | ||
| | || | deny | | ||
| | || |<------| | ||
|<-----------------------| | | ||
| | ||========================||
```
## Access Token
```json
{
"iss": "https://cmd0-dev.us.auth0.com/",
"sub": "auth0|627b10e1019dd10068e03db4",
"aud": [
"https://api.cmdzero.io",
"https://cmd0-dev.us.auth0.com/userinfo"
],
"iat": 1652843177,
"exp": 1652929577,
"azp": "zap85dH6ugiMvGCaXeHRjvD4AC1AOiU9",
"scope": "openid profile email offline_access",
"permissions": [
"read:incidents"
]
}
```
## Policy
The [PDP][1] enforces policy by checking:
* casbin policies to match the subject, request path, and request method.
* subject is defined in the access token.
* permissions are defined in the access token.
## Example
Rule
```conf
[request_definition]
r = subject, resource, action
[policy_definition]
p = subject, resource, action
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = (p.subject == "*" || r.subject == p.subject) && r.resource == p.resource && r.action == p.action
```
| policy | subject | resource | method |
| ------ | ------------------------ | ------------------------------- | ------ |
| p | * | /api/atlas | GET |
| p | * | /api/notifications/global | GET |
| p | * | /api/public | GET |
| p | 627b10e1019dd10068e03db4 | /api/notifications/QwfsJDutXwPD | GET |
Example 1:
```http
GET /api/public
200 OK
```
Example 2:
```http
GET /api/public
Authorization: Bearer access_token("627b10e1019dd10068e03db4")
200 OK
```
Example 3:
```http
GET /api/notifications/QwfsJDutXwPD
Authorization: Bearer access_token("627b10e1019dd10068e03db4")
200 OK
```
Example 4:
```http
GET /api/notifications/QwfsJDutXwPD
Authorization: Bearer access_token("f00d1e")
401 Unauthorized
```
[ABAC][2]
## Roles
What about Roles?
Rule
```
[request_definition]
r = subject, resource, action
[role_definition]
g = subject, role, domain
[policy_definition]
p = role, domain, resource, action
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.subject, p.role, r.domain) && r.resource == p.resource && r.action == p.action
```
Policies
| policy | role | domain | resource | action |
| ------ | ----- | ------- | -------- | ------ |
| p | admin | domain1 | data1 | read |
| p | admin | domain1 | data1 | write |
| p | admin | domain2 | data2 | read |
| p | admin | domain2 | data2 | write |
Groups
| group | subject | role | domain |
| ----- | ------- | ---- | ------ |
| g | alice | admin | * |
| g | bob | admin | domain2 |
[RBAC][3]
[1]: https://csrc.nist.gov/glossary/term/policy_decision_point
[2]: https://casbin.org/docs/en/abac
[3]: https://casbin.org/docs/en/rbac
[4]: https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse
[5]: https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#control-access-token-audience
|