Skip to content

Commit 92c100e

Browse files
etorreborremrinalwadhwa
authored andcommitted
add a description of simple boolean policies
1 parent bcf9535 commit 92c100e

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

reference/protocols/access-controls.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,85 @@ This table lists all the available operators:
4444
| `member?` | 2 | Return true if the first value is present in the second expression, which must be a sequence `Seq` of values |
4545
| `exists?` | >= 1 | Return true if all the expressions are identifiers with values present in the environment |
4646

47+
48+
### Examples
49+
50+
Here are a few more examples of policies.
51+
52+
> The subject must have a `component` attribute with a value that is either `web` or `database`:
53+
54+
```scheme
55+
(or (= subject.component "web")
56+
(= subject.component "database"))
57+
```
58+
59+
Note that attribute names can have dots in their name, so you could also write:
60+
61+
```scheme
62+
(or (= subject.component.web "true")
63+
(= subject.component.database "true"))
64+
```
65+
66+
You can also declare more complex logical expressions, by nesting `and` and `or` operators:
67+
68+
> The subject must either by the "Smart Factory" application or being a member of the "Field Engineering" department in San Francisco:
69+
70+
```scheme
71+
(or (= subject.application "Smart Factory")
72+
(and (= subject.department "Field Engineering")
73+
(= subject.city "San Francisco")))
74+
```
75+
76+
### Boolean policies
77+
78+
Since many policies are just need to test for the presence of an attribute, we provide simpler ways to write them.
79+
80+
For example we can write:
81+
```scheme
82+
(or (= subject.web "true")
83+
(= subject.database "true"))
84+
```
85+
86+
Simply as (note that logical operators can now be written as infix operators):
87+
```scheme
88+
web or database
89+
```
90+
91+
String comparisons are still supported, so you could also have a `component` attribute and write:
92+
```scheme
93+
component="web" or component="database"
94+
```
95+
96+
More complex expressions require parentheses:
97+
```scheme
98+
(web or not database) and analytics
99+
```
100+
101+
Since identities are frequently used in policies, we provide a shortcut for them. For example, this is a valid boolean policy:
102+
```scheme
103+
I84502ce0d9a0a91bae29026b84e19be69fb4203a6bdd1424c85a43c812772a00
104+
```
105+
106+
It translates to:
107+
```scheme
108+
(= subject.identifier = "I84502ce0d9a0a91bae29026b84e19be69fb4203a6bdd1424c85a43c812772a00")
109+
```
110+
111+
This table summarizes the elements you can use in a simple boolean policy:
112+
113+
| Operator | Description |
114+
|------------------------|-----------------------------------------------------------------------------------|
115+
| `name` | Equivalent to `(= subject.name "true")` |
116+
| `name="string value"` | Equivalent to `(= subject.name "string value")` |
117+
| `and` | Conjunction of 2 expressions |
118+
| `or` | Disjunction of 2 expressions |
119+
| `not` | Negation of an expression |
120+
| `identifier` | Equivalent to `(= subject.identifier "identifier")` |
121+
| `()` | Parentheses. Used to group expressions. The precedence rules are `not > and > or` |
122+
123+
124+
### Evaluation
125+
47126
We evaluate a policy by doing the following:
48127

49128
* Each attribute `attribute_name/attribute_value` is added to the environment as an identifier `subject.attribute_name` associated to the value `attribute_value` (always as a `String`). In the example of a policy given above the identifier `subject.name` means that we are expecting an attribute `name` associated to the identity which sent a message.

0 commit comments

Comments
 (0)