Skip to content

Commit 97355b5

Browse files
committed
chore(examples): update examples to match new schema
1 parent 097d226 commit 97355b5

File tree

4 files changed

+202
-23
lines changed

4 files changed

+202
-23
lines changed

examples/2022-04/Kitty.jsonc

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Shows an example usage for our Kitty resource
3+
4+
== Example Context
5+
{
6+
kitty: {
7+
state: 'purring',
8+
ownerId: 'sillyLittleMe'
9+
},
10+
subject: {
11+
id: 'sillyLittleMe',
12+
role: 'admin'
13+
}
14+
}
15+
*/
16+
{
17+
"$schema": "../../schemas/resource-policy-2022-04.schema.json",
18+
"resourceType": "Kitty",
19+
"actions": ["create", "read", "update", "pet"],
20+
"definitions": [
21+
{
22+
"environment": "*", // applies across all environments
23+
"policies": [
24+
{
25+
"description": "Allow everyone to create a kitty",
26+
"action": "create", // specify a single action
27+
"effect": "allow",
28+
"constraint": true
29+
},
30+
{
31+
"description": "Allow admins to take any action",
32+
"action": "*",
33+
"effect": "allow",
34+
"constraint": {
35+
// expects that context will include a subject object with a role property
36+
"===": [
37+
{ "var": "subject.role" },
38+
"admin"
39+
]
40+
}
41+
},
42+
{
43+
"description": "allow owners to read, update and pet the kitty",
44+
"action": ["read", "update", "pet"], // specify a list of actions
45+
"effect": "allow",
46+
"constraint": {
47+
"===": [
48+
{ "var": "subject.id" },
49+
{ "var": "kitty.ownerId" }
50+
]
51+
}
52+
},
53+
{
54+
"description": "Do not allow users (even admins!) to pet if the kitty is sleeping or eating",
55+
"action": "pet",
56+
"effect": "deny", // will override any allow statement
57+
"constraint": {
58+
"in": [
59+
{ "var": "kitty.state" },
60+
["eating", "sleeping"]
61+
]
62+
}
63+
}
64+
]
65+
},
66+
{
67+
"environment": ["development", "alpha", "beta"], // specify a list of environments
68+
"policies": [
69+
{
70+
"description": "allow developers to update any kitty in non-prod environments",
71+
"action": "update",
72+
"effect": "allow",
73+
"constraint": true
74+
}
75+
]
76+
}
77+
]
78+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
Shows an example usage for creating policies for our dumbdata service's Document resource
3+
4+
== Example Context
5+
{
6+
Resource: {
7+
Tags: ["Public", "ReadOnly"],
8+
AuthorURI: "urn::12345:whodunnit:users/SillyMe",
9+
...
10+
},
11+
Principal: {
12+
URI: "urn::12345:whodunnit:users/SillyMe",
13+
RoleURI: "urn::12345:whodunnit:roles/StandardUser"
14+
},
15+
Environment: {
16+
CurrentEnv: "Prod-use1"
17+
}
18+
}
19+
*/
20+
{
21+
"$schema": "../../schemas/resource-policy-2022-04.schema.json",
22+
"resourceType": "dumbdata:Document",
23+
"actions": [
24+
"dumbdata:CreateDocument",
25+
"dumbdata:DeleteDocument",
26+
"dumbdata:GetDocument",
27+
"dumbdata:PutDocument",
28+
"dumbdata:QueryDocuments"
29+
],
30+
"definitions": [
31+
{
32+
"environment": "*",
33+
"policies": [
34+
{
35+
"description": "Create a dropbox where anyone can create a document, but can't read or update",
36+
"action": "dumbdata:CreateDocument",
37+
"effect": "allow",
38+
"constraint": true
39+
},
40+
{
41+
"description": "Allow anyone to read/query documents with the Public tag",
42+
"action": ["dumbdata:GetDocument", "dumbdata:QueryDocuments"],
43+
"effect": "allow",
44+
"constraint": {
45+
"some": [
46+
{ "var": "Resource.Tags" },
47+
// { "var": "" } references the current element from Resource.Tags
48+
{ "in": [{ "var": "" }, ["Public"]]}
49+
]
50+
}
51+
},
52+
{
53+
"description": "Allow users to manage documents they've created if the Editable tag is present",
54+
"action": "*",
55+
"effect": "allow",
56+
"constraint": {
57+
"and": [
58+
{
59+
"some": [
60+
{ "var": "Resource.Tags" },
61+
{ "===": [{ "var": "" }, "Editable"] }
62+
]
63+
},
64+
{
65+
"===": [
66+
{ "var": "Principal.URI" },
67+
{ "var": "Resource.AuthorURI" }
68+
]
69+
}
70+
]
71+
}
72+
},
73+
{
74+
"description": "Block users from managing documents if the ReadOnly tag is present and they're not an admin",
75+
"action": ["dumbdata:DeleteDocument", "dumbdata:PutDocument"],
76+
"effect": "deny",
77+
"constraint": {
78+
"all": [
79+
{
80+
"some": [
81+
{ "var": "Resource.Tags" },
82+
{ "===": [{ "var": "" }, "ReadOnly"] }
83+
]
84+
},
85+
{
86+
"!==": [
87+
{ "var": "Principal.RoleURI" },
88+
"urn::12345:whodunnit:roles/Administrator"
89+
]
90+
},
91+
// Don't block mutations in the test suite
92+
// NOTE: this is just a hypothetical example. Please don't actually do this.
93+
{
94+
"!==": [
95+
{ "var": "Environment.CurrentEnv" },
96+
"test"
97+
]
98+
}
99+
]
100+
}
101+
}
102+
]
103+
},
104+
{
105+
"environment": "test",
106+
"policies": [
107+
{
108+
"description": "Allow the test runner to delete documents it created, regardless of the Editable tag being present",
109+
"action": "dumbdata:DeleteItem",
110+
"effect": "allow",
111+
"constraint": {
112+
"===": [
113+
{ "var": "Resource.AuthorURI" },
114+
{ "var": "Principal.URI" }
115+
]
116+
}
117+
}
118+
]
119+
}
120+
]
121+
}

examples/Kitty.jsonc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616
{
1717
"$schema": "../schemas/resource-policy-2023-02.schema.json",
18-
"resourceType": "Kitty",
1918
"actions": ["create", "read", "update", "pet"],
20-
"policies": [
19+
"statement": [
2120
{
2221
"description": "Allow everyone to create a kitty",
2322
"action": "create", // specify a single action

examples/dumbdata-Document.jsonc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,11 @@
1212
URI: "urn::12345:whodunnit:users/SillyMe",
1313
RoleURI: "urn::12345:whodunnit:roles/StandardUser"
1414
},
15-
Environment: {
16-
CurrentEnv: "Prod-use1"
17-
}
1815
}
1916
*/
2017
{
2118
"$schema": "../schemas/resource-policy-2023-02.schema.json",
22-
"resourceType": "dumbdata:Document",
23-
"actions": [
24-
"dumbdata:CreateDocument",
25-
"dumbdata:DeleteDocument",
26-
"dumbdata:GetDocument",
27-
"dumbdata:PutDocument",
28-
"dumbdata:QueryDocuments"
29-
],
30-
"policies": [
19+
"statement": [
3120
{
3221
"description": "Create a dropbox where anyone can create a document, but can't read or update",
3322
"action": "dumbdata:CreateDocument",
@@ -84,17 +73,9 @@
8473
{ "var": "Principal.RoleURI" },
8574
"urn::12345:whodunnit:roles/Administrator"
8675
]
87-
},
88-
// Don't block mutations in the test suite
89-
// NOTE: this is just a hypothetical example. Please don't actually do this.
90-
{
91-
"!==": [
92-
{ "var": "Environment.CurrentEnv" },
93-
"test"
94-
]
9576
}
9677
]
9778
}
9879
}
9980
]
100-
}
81+
}

0 commit comments

Comments
 (0)