Skip to content

Commit 81f3635

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

File tree

1 file changed

+87
-37
lines changed

1 file changed

+87
-37
lines changed
Lines changed: 87 additions & 37 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]
@@ -8,122 +8,172 @@ CREATE ROLE regularUsers;
88
////
99

1010
:page-role: enterprise-edition aura-db-business-critical aura-db-dedicated
11+
1112
[[property-based-access-control]]
1213
= Property-based access control
1314

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

1955
Adding property-based access control may lead to a significant performance overhead in certain scenarios.
2056
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.
2257

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

25-
* The number of properties on the nodes concerned (more properties = greater performance impact)
60+
* The number of properties on the nodes concerned (more properties = greater performance impact).
2661
* 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.
62+
* The type of the privilege: `TRAVERSE` property-based privileges have greater performance impact than `READ` property-based privileges.
63+
* The type of storage medium in operation. The impact of the property-based privileges on performance is considerably amplified by accessing disc storage.
64+
65+
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.
2966

3067
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].
3268

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-
====
3869

39-
Pattern syntax:
70+
== Examples
71+
72+
You can use the following syntax for defining a property-based privilege:
73+
4074
[source, syntax, role="noheader"]
4175
----
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 } } )
76+
GRANT privilege-name ON GRAPH graph-name FOR pattern TO role-name
4577
----
78+
4679
[NOTE]
4780
====
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.
81+
The user role does not need to have `READ` privilege for the property used by the property-based privilege.
5382
====
54-
You can use this pattern syntax for defining read privileges as follows:
5583

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

86+
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`:
6187

62-
.Granting permission to `READ` the `address` property on `Email` or `Website` nodes with domain `exampledomain.com` to role `regularUsers`:
6388
[source, syntax, role="noheader"]
6489
----
6590
GRANT READ { address } ON GRAPH * FOR (n:Email|Website) WHERE n.domain = 'exampledomain.com' TO regularUsers
6691
----
92+
6793
Alternatively, you can use the following syntax:
94+
6895
[source, syntax, role="noheader"]
6996
----
7097
GRANT READ { address } ON GRAPH * FOR (:Email|Website {domain: 'exampledomain.com'}) TO regularUsers
7198
----
7299

73100

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

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

86-
.Granting permission to `READ` all properties on nodes where the property `securityLevel` is higher than `3` to role `regularUsers`:
119+
=== Grant a property-based privilege on all properties using a property value
120+
121+
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`:
122+
87123
[source, syntax, role="noheader"]
88124
----
89125
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.securityLevel > 3 TO regularUsers
90126
----
127+
91128
[NOTE]
92129
====
93130
The role `regularUsers` does not need to have `READ` privilege for the property `securityLevel` used by the property-based privilege.
94131
====
95132

96-
.Denying permission to `READ` all properties on nodes where the property `classification` is not included in the list of `[UNCLASSIFIED, PUBLIC]`
133+
=== Deny a property-based privilege using a list of values
134+
135+
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]`:
136+
97137
[source, syntax, role="noheader"]
98138
----
99139
DENY READ {*} ON GRAPH * FOR (n) WHERE NOT n.classification IN ['UNCLASSIFIED', 'PUBLIC'] TO regularUsers
100140
----
101141

102-
.Granting permission to `READ` all properties on nodes where the property `createdAt` is later than the current date to role `regularUsers`:
142+
// The last two examples were added in 5.26.
143+
144+
=== Grant a property-based privilege using temporal value
145+
146+
The following example shows how to grant permission to `READ` all properties on nodes where the property `createdAt` is later than the current date:
147+
103148
[source, syntax, role="noheader"]
104149
----
105150
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date() TO regularUsers
106151
----
152+
107153
[NOTE]
108154
====
109155
The `date()` function is evaluated, and the value used to evaluate the privilege is the date when the property-based privilege is created.
110156
Keep this in mind when designing your property rules, and use the `SHOW PRIVILEGES AS COMMANDS` command to check the stored value.
111157
This is essential when revoking property-based privileges containing evaluated function values like `date()`.
112158
====
159+
113160
[NOTE]
114161
====
115162
Not all temporal values are comparable, see link:{neo4j-docs-base-uri}/cypher-manual/current/syntax/operators/#cypher-ordering[Cypher Manual -> Syntax -> Operators -> Ordering and comparison of values].
116163
====
117164

118-
.Show the privilege created by the command in the previous example as a revoke command:
165+
You can show the privilege created by the command in the previous example as a revoke command by running:
166+
119167
[source, syntax, role="noheader"]
120168
----
121169
SHOW ROLE regularUsers PRIVILEGES AS REVOKE COMMANDS
122170
----
171+
123172
.Result
124173
[options="header,footer", width="100%", cols="m"]
125174
|===
126175
|command
127176
|"REVOKE GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date('2024-10-25') FROM `regularUsers`"
128177
a|Rows: 1
129-
|===
178+
|===
179+

0 commit comments

Comments
 (0)