Skip to content

Commit 8d4f6c9

Browse files
committed
feat: update example schemas shown in playground
1 parent a376dc7 commit 8d4f6c9

File tree

8 files changed

+73
-192
lines changed

8 files changed

+73
-192
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Developers create a schema that models their permissions requirements and use a
1717
Examples in this repository include:
1818

1919
- How to set up SpiceDB with tracing: see [tracing](./tracing)
20-
- How to invoke SpiceDB as a library: see [library](./library)
20+
- How to invoke SpiceDB as a library: see [library](./spicedb-as-library)
2121
- How to run SpiceDB in a Kubernetes cluster: see [kubernetes](./kubernetes)
2222
- CI/CD Workflows
2323

schemas/basic-rbac/README.md

Lines changed: 0 additions & 99 deletions
This file was deleted.

schemas/basic-rebac/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Simple Relationship Based Access Control (ReBAC)
2+
3+
Access is granted to users based on the relation(s) that they have to a given document.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
---
22
schema: |-
33
/**
4-
* user represents a user that can be granted role(s)
4+
* an entity that can be granted permissions
55
*/
66
definition user {}
77
88
/**
9-
* document represents a document protected by Authzed.
9+
* a resource that we are trying to protect
1010
*/
1111
definition document {
1212
/**
13-
* writer indicates that the user is a writer on the document.
13+
* users can be made writers of specific documents
1414
*/
1515
relation writer: user
1616
1717
/**
18-
* reader indicates that the user is a reader on the document.
18+
* users can be made readers of specific documents
1919
*/
2020
relation reader: user
2121
2222
/**
23-
* edit indicates that the user has permission to edit the document.
23+
* if a user has the writer relationship to a specific document, they automatically get permission to edit it
2424
*/
2525
permission edit = writer
2626
2727
/**
28-
* view indicates that the user has permission to view the document, if they
29-
* are a `reader` *or* have `edit` permission.
28+
* if a user has the reader relation to a document OR the permission to edit a document (or both), they automatically get permission to view it
3029
*/
3130
permission view = reader + edit
3231
}

schemas/caveats/README.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,4 @@
1-
# Caveats for conditional access
1+
# Simple Attribute Based Access Control (ABAC)
22

3-
Models the use of caveats, which allows for conditional access based on information provided at _runtime_ to permission checks.
3+
Access can be granted to users based on information provided at runtime to permission checks.
44

5-
---
6-
7-
## Schema
8-
9-
```
10-
definition user {}
11-
12-
/**
13-
* only allowed on tuesdays. `day_of_week` can be provided either at the time
14-
* the relationship is written, or in the CheckPermission API call.
15-
*/
16-
caveat only_on_tuesday(day_of_week string) {
17-
day_of_week == 'tuesday'
18-
}
19-
20-
definition document {
21-
/**
22-
* reader indicates that the user is a reader on the document, either
23-
* directly or only on tuesday.
24-
*/
25-
relation reader: user | user with only_on_tuesday
26-
27-
permission view = reader
28-
}
29-
```

schemas/caveats/schema-and-data.yaml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
11
---
22
schema: |-
3+
/**
4+
* an entity that can be granted permissions
5+
*/
36
definition user {}
47
58
/**
6-
* only allowed on tuesdays. `day_of_week` can be provided either at the time
7-
* the relationship is written, or in the CheckPermission API call.
9+
* a resource that we are trying to protect
810
*/
9-
caveat only_on_tuesday(day_of_week string) {
10-
day_of_week == 'tuesday'
11-
}
12-
13-
caveat ip_allowlist(user_ip ipaddress, cidr string) {
14-
user_ip.in_cidr(cidr)
15-
}
16-
1711
definition document {
1812
/**
19-
* reader indicates that the user is a reader on the document, either directly,
20-
* only on tuesday, or from allowed IPs.
13+
* users can be made readers of specific documents,
14+
* either directly, or only if they have a valid IP, or only if they aren't rate limited.
2115
*/
22-
relation reader: user | user with only_on_tuesday | user with ip_allowlist
16+
relation reader: user | user with has_valid_ip | user with not_rate_limited
2317
18+
/**
19+
* if a user has the reder relationship to a specific document, they automatically get permission to view it
20+
*/
2421
permission view = reader
2522
}
23+
24+
/**
25+
* only allowed if the IP address is allowed.
26+
* we can provide cidr at the time we write the relation, and
27+
* we can provide user_ip at the time the CheckPermission is made.
28+
*/
29+
caveat has_valid_ip(user_ip ipaddress, cidr string) {
30+
user_ip.in_cidr(cidr)
31+
}
32+
33+
/**
34+
* only allowed if rate limits haven't been exceeded.
35+
* we can provide allowed_max at the time we write the relation, and
36+
* we can provide current at the time the CheckPermission is made.
37+
*/
38+
caveat not_rate_limited(allowed_max int, current int) {
39+
current < allowed_max
40+
}
2641
relationships: |-
2742
document:firstdoc#reader@user:fred
28-
document:firstdoc#reader@user:tom[only_on_tuesday]
29-
document:firstdoc#reader@user:alice[ip_allowlist:{"cidr":"1.2.3.0/24"}]
43+
document:firstdoc#reader@user:tom[not_rate_limited:{"allowed_max":100}]
44+
document:firstdoc#reader@user:alice[has_valid_ip:{"cidr":"1.2.3.0/24"}]
3045
assertions:
3146
assertTrue:
32-
- 'document:firstdoc#view@user:tom with {"day_of_week": "tuesday"}'
47+
- 'document:firstdoc#view@user:tom with {"current": 1}'
3348
- "document:firstdoc#view@user:fred"
3449
- 'document:firstdoc#view@user:alice with {"user_ip": "1.2.3.4"}'
3550
assertCaveated:
3651
- "document:firstdoc#view@user:tom"
3752
- "document:firstdoc#view@user:alice"
3853
assertFalse:
39-
- 'document:firstdoc#view@user:tom with {"day_of_week": "wednesday"}'
54+
- 'document:firstdoc#view@user:tom with {"current": 500}'
4055
- 'document:firstdoc#view@user:alice with {"user_ip": "8.8.8.8"}'
4156
validation:
4257
document:firstdoc#view:

schemas/superuser/README.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
# Super-admin / site-wide permissions
22

3-
Models providing site-wide (or superuser) permissions for all resources of a specific type
4-
5-
---
6-
7-
## Schema
8-
9-
```
10-
definition platform {
11-
relation administrator: user
12-
permission super_admin = administrator
13-
}
14-
15-
definition organization {
16-
// The platform is generally a singleton pointing to the same
17-
// platform object, on which the superuser is in turn granted
18-
// access.
19-
relation platform: platform
20-
permission admin = platform->super_admin
21-
}
22-
23-
definition resource {
24-
relation owner: user | organization
25-
permission admin = owner + owner->admin
26-
}
27-
28-
definition user {}
29-
```
3+
Provide site-wide (or superuser) permissions for all resources of a specific type
Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
---
22
schema: |-
3-
definition platform {
4-
relation administrator: user
5-
permission super_admin = administrator
3+
/**
4+
* an entity that can be granted permissions
5+
*/
6+
definition user {}
7+
8+
/**
9+
* a resource that we are trying to protect
10+
*/
11+
definition document {
12+
relation owner: user | organization
13+
14+
/**
15+
* if a user has the (direct) owner relation OR if they are admin of the owner organization, they get the admin permission on the document.
16+
*/
17+
permission admin = owner + owner->admin
618
}
7-
19+
820
definition organization {
921
// The platform is generally a singleton pointing to the same
1022
// platform object, on which the superuser is in turn granted
1123
// access.
12-
relation platform: platform
13-
permission admin = platform->super_admin
14-
}
15-
16-
definition resource {
17-
relation owner: user | organization
18-
permission admin = owner + owner->admin
24+
relation platform: platform
25+
permission admin = platform->super_admin
1926
}
27+
28+
/**
29+
* a root object
30+
*/
31+
definition platform {
32+
relation administrator: user
33+
permission super_admin = administrator
34+
}
2035
21-
definition user {}
2236
relationships: |-
2337
platform:evilempire#administrator@user:drevil
2438
organization:virtucon#platform@platform:evilempire
25-
resource:lasers#owner@organization:virtucon
39+
document:lasers#owner@organization:virtucon
2640
assertions:
2741
assertTrue:
28-
- "resource:lasers#admin@user:drevil"
42+
- "document:lasers#admin@user:drevil"
2943
assertFalse: null
3044
validation: null

0 commit comments

Comments
 (0)