Skip to content

Commit 2ea57a5

Browse files
NataliaIvakinarenetapopovaphil198
authored
Turn examples into sections (#2201) (#2207)
To make the page consistent with other pages. --------- Co-authored-by: Reneta Popova <[email protected]> Co-authored-by: Phil Wright <[email protected]>
1 parent 49558c2 commit 2ea57a5

File tree

1 file changed

+88
-36
lines changed

1 file changed

+88
-36
lines changed
Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:description: How to use Cypher to manage property-based access control on graphs.
1+
:description: How to use Cypher to manage property-based access control on a graph.
22

33
////
44
[source, cypher, role=test-setup]
@@ -7,123 +7,175 @@ CREATE ROLE regularUsers;
77
----
88
////
99

10+
1011
:page-role: enterprise-edition aura-db-business-critical aura-db-dedicated new-5.24
12+
1113
[[property-based-access-control]]
1214
= Property-based access control
1315

14-
It is possible to create read privileges that are based on properties of nodes.
16+
Property-based access control grants permissions to users to read node properties based on property/value conditions.
1517
Each property-based privilege can only be restricted by a single property.
16-
To specify the property/value conditions of the read privilege the `pattern` syntax described below is used,
17-
for more information about read privilege syntax see xref:authentication-authorization/privileges-reads.adoc[read privilege] page.
18+
For information about read privileges and their syntax, see xref:authentication-authorization/privileges-reads.adoc[Read privileges].
19+
20+
[IMPORTANT]
21+
====
22+
When using property-based access control, ensure the property used for the rule cannot be modified.
23+
Users who can change this property can affect the granted property-based privileges.
24+
====
25+
26+
27+
== Syntax
28+
29+
To specify the property/value conditions of the read privilege, you can use the following syntax:
30+
31+
[source, syntax, role="noheader"]
32+
----
33+
{GRANT | DENY | REVOKE [GRANT | DENY]}
34+
[IMMUTABLE]
35+
{MATCH | READ | TRAVERSE}
36+
ON { HOME GRAPH | GRAPH[S] { * | name[, ...] } }
37+
[
38+
ELEMENT[S] { * | label-or-rel-type[, ...] }
39+
| NODE[S] { * | label[, ...] }
40+
| RELATIONSHIP[S] { * | rel-type[, ...] }
41+
| FOR {
42+
43+
([var][:label["|" ...]] "{" property: value "}")
44+
| (var[:label["|" ...]])
45+
WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } }
46+
| (var[:label["|" ...]]
47+
WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } } )
48+
}
49+
50+
{TO | FROM} role[, ...]
51+
----
52+
53+
54+
== Performance considerations
1855

1956
Adding property-based access control may lead to a significant performance overhead in certain scenarios.
2057
See xref:authentication-authorization/limitations.adoc#property-based-access-control-limitations[Limitations] for more detailed information.
21-
To reduce the performance impact, it is recommended to use the Block Storage format as it is better optimized for the kind of read required for the resolution of property-based privileges.
2258

23-
Some of the factors that can worsen the impact on performance when having property rules are:
59+
When having property rules, the following factors can worsen the impact on performance:
2460

25-
* The number of properties on the nodes concerned (more properties = greater performance impact)
61+
* The number of properties on the nodes concerned (more properties = greater performance impact).
2662
* The number of property-based privileges (more property-based privileges = greater performance impact).
27-
* The type of the privilege: `TRAVERSE` property-based privileges have a greater performance impact than `READ` property-based privileges.
28-
* The type of storage medium in operation. The performance impact of property-based privileges will be considerably amplified by accessing disc storage.
63+
* The type of the privilege: `TRAVERSE` property-based privileges have greater performance impact than `READ` property-based privileges.
64+
* The type of storage medium in operation. The impact of the property-based privileges on performance is considerably amplified by accessing disc storage.
65+
66+
To reduce the performance impact, it is recommended to use the `block` storage format as it is better optimized for the kind of read required for the resolution of property-based privileges.
2967

3068
For performance-critical scenarios, it is recommended to design privileges based on labels.
31-
For more information, see xref:authentication-authorization/privileges-reads.adoc[Read privileges].
3269

33-
[IMPORTANT]
34-
====
35-
When using property-based access control, ensure the property used for the rule cannot be modified.
36-
Users who can change this property can affect the granted property-based privileges.
37-
====
3870

39-
Pattern syntax:
71+
== Examples
72+
73+
You can use the following syntax for defining a property-based privilege:
74+
4075
[source, syntax, role="noheader"]
4176
----
42-
([var][:label["|" ...]] "{" property: value "}")
43-
| (var[:label["|" ...]]) WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } }
44-
| (var[:label["|" ...]] WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } } )
77+
GRANT privilege-name ON GRAPH graph-name FOR pattern TO role-name
4578
----
79+
4680
[NOTE]
4781
====
48-
For more details about the syntax descriptions, see xref:database-administration/syntax.adoc[Cypher syntax for administration commands].
49-
====
50-
[NOTE]
51-
====
52-
The role does not need to have `READ` privilege for the property used by the property-based privilege.
82+
The user role does not need to have `READ` privilege for the property used by the property-based privilege.
5383
====
54-
You can use this pattern syntax for defining read privileges as follows:
5584

56-
[source, syntax, role="noheader"]
57-
----
58-
GRANT ... ON GRAPH ... FOR pattern TO ...
59-
----
85+
=== Grant a property-based privilege on a specific property using its value
6086

87+
The following example shows how to grant permission to `READ` the `address` property on `Email` or `Website` nodes with domain `exampledomain.com` to role `regularUsers`:
6188

62-
.Granting permission to `READ` the `address` property on `Email` or `Website` nodes with domain `exampledomain.com` to role `regularUsers`:
6389
[source, syntax, role="noheader"]
6490
----
6591
GRANT READ { address } ON GRAPH * FOR (n:Email|Website) WHERE n.domain = 'exampledomain.com' TO regularUsers
6692
----
93+
6794
Alternatively, you can use the following syntax:
95+
6896
[source, syntax, role="noheader"]
6997
----
7098
GRANT READ { address } ON GRAPH * FOR (:Email|Website {domain: 'exampledomain.com'}) TO regularUsers
7199
----
72100

73101

74-
.Granting permission to `TRAVERSE` nodes with label `Email` where property `classification` is `NULL` to role `regularUsers`:
102+
=== Grant a property-based privilege using `NULL`
103+
104+
The following example shows how to grant permission to `TRAVERSE` nodes with the label `Email` where property `classification` is `NULL` to role `regularUsers`:
105+
75106
[source, syntax, role="noheader"]
76107
----
77108
GRANT TRAVERSE ON GRAPH * FOR (n:Email) WHERE n.classification IS NULL TO regularUsers
78109
----
79110

80-
.Denying permission to `READ` and `TRAVERSE` nodes where the property `classification` is different from `UNCLASSIFIED` to role `regularUsers`:
111+
=== Deny a property-based privilege using a comparison operator
112+
113+
The following example shows how to deny permission to `READ` and `TRAVERSE` nodes where the property `classification` is different from `UNCLASSIFIED` to role `regularUsers`:
114+
81115
[source, syntax, role="noheader"]
82116
----
83117
DENY MATCH {*} ON GRAPH * FOR (n) WHERE n.classification <> 'UNCLASSIFIED' TO regularUsers
84118
----
85119

86-
.Granting permission to `READ` all properties on nodes where the property `securityLevel` is higher than `3` to role `regularUsers`:
120+
=== Grant a property-based privilege on all properties using a property value
121+
122+
The following example shows how to grant permission to `READ` all properties on nodes where the property `securityLevel` is higher than `3` to role `regularUsers`:
123+
87124
[source, syntax, role="noheader"]
88125
----
89126
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.securityLevel > 3 TO regularUsers
90127
----
128+
91129
[NOTE]
92130
====
93131
The role `regularUsers` does not need to have `READ` privilege for the property `securityLevel` used by the property-based privilege.
94132
====
95133

96-
.Denying permission to `READ` all properties on nodes where the property `classification` is not included in the list of `[UNCLASSIFIED, PUBLIC]`
134+
=== Deny a property-based privilege using a list of values
135+
136+
The following example shows how to deny permission to `READ` all properties on nodes where the property `classification` is not included in the list of `[UNCLASSIFIED, PUBLIC]`:
137+
97138
[source, syntax, role="noheader"]
98139
----
99140
DENY READ {*} ON GRAPH * FOR (n) WHERE NOT n.classification IN ['UNCLASSIFIED', 'PUBLIC'] TO regularUsers
100141
----
101142

102-
.Granting permission to `READ` all properties on nodes where the property `createdAt` is later than the current date to role `regularUsers`:
143+
// The last two examples were added in 5.26.
144+
145+
[role=label--new-5.26]
146+
=== Grant a property-based privilege using temporal value
147+
148+
The following example shows how to grant permission to `READ` all properties on nodes where the property `createdAt` is later than the current date:
149+
103150
[source, syntax, role="noheader"]
104151
----
105152
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date() TO regularUsers
106153
----
154+
107155
[NOTE]
108156
====
109157
The `date()` function is evaluated, and the value used to evaluate the privilege is the date when the property-based privilege is created.
110158
Keep this in mind when designing your property rules, and use the `SHOW PRIVILEGES AS COMMANDS` command to check the stored value.
111159
This is essential when revoking property-based privileges containing evaluated function values like `date()`.
112160
====
161+
113162
[NOTE]
114163
====
115164
Not all temporal values are comparable, see link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/syntax/operators/#cypher-ordering[Cypher Manual -> Syntax -> Operators -> Ordering and comparison of values].
116165
====
117166

118-
.Show the privilege created by the command in the previous example as a revoke command:
167+
You can show the privilege created by the command in the previous example as a revoke command by running:
168+
119169
[source, syntax, role="noheader"]
120170
----
121171
SHOW ROLE regularUsers PRIVILEGES AS REVOKE COMMANDS
122172
----
173+
123174
.Result
124175
[options="header,footer", width="100%", cols="m"]
125176
|===
126177
|command
127178
|"REVOKE GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date('2024-10-25') FROM `regularUsers`"
128179
a|Rows: 1
129180
|===
181+

0 commit comments

Comments
 (0)