Skip to content

Commit ea1b714

Browse files
Turn examples into sections
1 parent f628414 commit ea1b714

File tree

1 file changed

+74
-38
lines changed

1 file changed

+74
-38
lines changed
Lines changed: 74 additions & 38 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,158 @@ 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-
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-
19-
Adding property-based access control may lead to a significant performance overhead in certain scenarios.
20-
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.
22-
23-
Some of the factors that can worsen the impact on performance when having property rules are:
24-
25-
* The number of properties on the nodes concerned (more properties = greater performance impact)
26-
* 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.
29-
30-
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].
15+
In Neo4j, you can grant read privileges based on properties of nodes.
3216

3317
[IMPORTANT]
3418
====
3519
When using property-based access control, ensure the property used for the rule cannot be modified.
3620
Users who can change this property can affect the granted property-based privileges.
3721
====
3822

39-
Pattern syntax:
23+
24+
== Syntax
25+
26+
For information about read privileges and syntax, see xref:authentication-authorization/privileges-reads.adoc[Read privileges].
27+
28+
To specify the property/value conditions of the read privilege, you can use the following `pattern` syntax:
29+
4030
[source, syntax, role="noheader"]
4131
----
4232
([var][:label["|" ...]] "{" property: value "}")
4333
| (var[:label["|" ...]]) WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } }
4434
| (var[:label["|" ...]] WHERE [NOT] var.property { { = | <> | > | >= | < | <= } value | IS NULL | IS NOT NULL | IN { "["[value[, ...]]"]" | listParam } } )
4535
----
46-
[NOTE]
47-
====
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.
53-
====
54-
You can use this pattern syntax for defining read privileges as follows:
36+
37+
38+
== Performance considerations
39+
40+
Adding property-based access control may lead to a significant performance overhead in certain scenarios.
41+
See xref:authentication-authorization/limitations.adoc#property-based-access-control-limitations[Limitations] for more detailed information.
42+
43+
When having property rules, the following factors can worsen the impact on performance:
44+
45+
* The number of properties on the nodes concerned (more properties = greater performance impact).
46+
* The number of property-based privileges (more property-based privileges = greater performance impact).
47+
* The type of the privilege: `TRAVERSE` property-based privileges have greater performance impact than `READ` property-based privileges.
48+
* The type of storage medium in operation. The impact of the property-based privileges on performance is considerably amplified by accessing disc storage.
49+
50+
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.
51+
52+
For performance-critical scenarios, it is recommended to design privileges based on labels.
53+
54+
55+
== Examples
56+
57+
You can use the following syntax for defining a property-based privilege:
5558

5659
[source, syntax, role="noheader"]
5760
----
58-
GRANT ... ON GRAPH ... FOR pattern TO ...
61+
GRANT privilege-name ON GRAPH graph-name FOR pattern TO role-name
5962
----
6063

64+
[NOTE]
65+
====
66+
The user role does not need to have `READ` privilege for the property used by the property-based privilege.
67+
====
68+
69+
=== Grant a property-based privilege on a specific property using its value
70+
71+
The following code shows how to grant permission to `READ` the `address` property on `Email` or `Website` nodes with domain `exampledomain.com` to role `regularUsers`.
6172

62-
.Granting permission to `READ` the `address` property on `Email` or `Website` nodes with domain `exampledomain.com` to role `regularUsers`:
6373
[source, syntax, role="noheader"]
6474
----
6575
GRANT READ { address } ON GRAPH * FOR (n:Email|Website) WHERE n.domain = 'exampledomain.com' TO regularUsers
6676
----
77+
6778
Alternatively, you can use the following syntax:
79+
6880
[source, syntax, role="noheader"]
6981
----
7082
GRANT READ { address } ON GRAPH * FOR (:Email|Website {domain: 'exampledomain.com'}) TO regularUsers
7183
----
7284

7385

74-
.Granting permission to `TRAVERSE` nodes with label `Email` where property `classification` is `NULL` to role `regularUsers`:
86+
=== Grant a property-based privilege using `NULL`
87+
88+
If you want to grant permission to `TRAVERSE` nodes with label `Email` where property `classification` is `NULL` to role `regularUsers`, use the following command:
89+
7590
[source, syntax, role="noheader"]
7691
----
7792
GRANT TRAVERSE ON GRAPH * FOR (n:Email) WHERE n.classification IS NULL TO regularUsers
7893
----
7994

80-
.Denying permission to `READ` and `TRAVERSE` nodes where the property `classification` is different from `UNCLASSIFIED` to role `regularUsers`:
95+
=== Deny a property-based privilege using a comparison operator
96+
97+
To deny permission to `READ` and `TRAVERSE` nodes where the property `classification` is different from `UNCLASSIFIED` to role `regularUsers`, use the code below:
98+
8199
[source, syntax, role="noheader"]
82100
----
83101
DENY MATCH {*} ON GRAPH * FOR (n) WHERE n.classification <> 'UNCLASSIFIED' TO regularUsers
84102
----
85103

86-
.Granting permission to `READ` all properties on nodes where the property `securityLevel` is higher than `3` to role `regularUsers`:
104+
=== Grant a property-based privilege on all properties using a property value
105+
106+
Imagine you need to grant permission to `READ` all properties on nodes where the property `securityLevel` is higher than `3` to role `regularUsers`.
107+
The following example shows how to do that.
108+
87109
[source, syntax, role="noheader"]
88110
----
89111
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.securityLevel > 3 TO regularUsers
90112
----
113+
91114
[NOTE]
92115
====
93116
The role `regularUsers` does not need to have `READ` privilege for the property `securityLevel` used by the property-based privilege.
94117
====
95118

96-
.Denying permission to `READ` all properties on nodes where the property `classification` is not included in the list of `[UNCLASSIFIED, PUBLIC]`
119+
=== Deny a property-based privilege using a list of values
120+
121+
The following code shows how to deny permission to `READ` all properties on nodes where the property `classification` is not included in the list of `[UNCLASSIFIED, PUBLIC]`.
122+
97123
[source, syntax, role="noheader"]
98124
----
99125
DENY READ {*} ON GRAPH * FOR (n) WHERE NOT n.classification IN ['UNCLASSIFIED', 'PUBLIC'] TO regularUsers
100126
----
101127

102-
.Granting permission to `READ` all properties on nodes where the property `createdAt` is later than the current date to role `regularUsers`:
128+
// The last two examples were added in 5.26.
129+
130+
=== Grant a property-based privilege using temporal value
131+
132+
Granting permission to `READ` all properties on nodes where the property `createdAt` is later than the current date
133+
103134
[source, syntax, role="noheader"]
104135
----
105136
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date() TO regularUsers
106137
----
138+
107139
[NOTE]
108140
====
109141
The `date()` function is evaluated, and the value used to evaluate the privilege is the date when the property-based privilege is created.
110142
Keep this in mind when designing your property rules, and use the `SHOW PRIVILEGES AS COMMANDS` command to check the stored value.
111143
This is essential when revoking property-based privileges containing evaluated function values like `date()`.
112144
====
145+
113146
[NOTE]
114147
====
115148
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].
116149
====
117150

118-
.Show the privilege created by the command in the previous example as a revoke command:
151+
Show the privilege created by the command in the previous example as a revoke command
152+
119153
[source, syntax, role="noheader"]
120154
----
121155
SHOW ROLE regularUsers PRIVILEGES AS REVOKE COMMANDS
122156
----
157+
123158
.Result
124159
[options="header,footer", width="100%", cols="m"]
125160
|===
126161
|command
127162
|"REVOKE GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date('2024-10-25') FROM `regularUsers`"
128163
a|Rows: 1
129-
|===
164+
|===
165+

0 commit comments

Comments
 (0)