Graph and sub-graph access control
Privileges control the access rights to graph elements using a combined whitelist/blacklist mechanism.
It is possible to grant access, or deny access, or a combination of the two.
The user will be able to access the resource if they have a grant (whitelist) and do not have a deny (blacklist) relevant to that resource.
All other combinations of GRANT
and DENY
will result in the matching path being inaccessible.
What this means in practice depends on whether we are talking about a read privilege or a write privilege.
-
If a entity is not accessible due to read privileges, the data will become invisible to attempts to read it. It will appear to the user as if they have a smaller database (smaller graph).
-
If an entity is not accessible due to write privileges, an error will occur on any attempt to write that data.
In this document we will often use the terms 'allows' and 'enables' in seemingly identical ways. However, there is a subtle difference. We will use 'enables' to refer to the consequences of read privileges where a restriction will not cause an error, only a reduction in the apparent graph size. We will use 'allows' to refer to the consequence of write privileges where a restriction can result in an error. |
If a user was not also provided with the database |
The GRANT
, DENY
and REVOKE
commands
The administrators can use Cypher® commands to manage Neo4j graph administrative rights. The components of the graph privilege commands are:
-
the command:
-
GRANT
– gives privileges to roles. -
DENY
– denies privileges to roles. -
REVOKE
– removes granted or denied privilege from roles.
-
-
graph-privilege
-
Can be either a read privilege or write privilege.
-
-
name
-
The graph or graphs to associate the privilege with. Because in Neo4j 4.1 you can have only one graph per database, this command uses the database name to refer to that graph.
If you delete a database and create a new one with the same name, the new one will NOT have the privileges assigned to the deleted graph.
-
It can be
*
which means all graphs. Graphs created after this command execution will also be associated with these privileges.
-
-
entity
-
The graph elements this privilege applies to:
-
NODES
label (nodes with the specified label(s)). -
RELATIONSHIPS
type (relationships of the specific type(s)). -
ELEMENTS
label (both nodes and relationships).
-
-
The label or type can be
*
which means all labels or types. -
Multiple labels or types can be specified, comma-separated.
-
Defaults to
ELEMENTS
*
if omitted. -
Some of the commands for write privileges do not allow an entity part, see Write privileges for details.
-
-
role[, …]
-
The role or roles to associate the privilege with, comma-separated.
-
Command | Description |
---|---|
|
Grant a privilege to one or multiple roles. |
|
Deny a privilege to one or multiple roles. |
|
Revoke a granted privilege from one or multiple roles. |
|
Revoke a denied privilege from one or multiple roles. |
|
Revoke a granted or denied privilege from one or multiple roles. |
|
The general grant and deny syntax is illustrated in the image below.

A more detailed syntax illustration would be the image below for graph privileges.

{
and }
are part of the syntax and not used for grouping.The below image shows the hierarchy between the different graph privileges.

Listing privileges
Available privileges can be displayed using the different SHOW PRIVILEGES
commands.
Command | Description |
---|---|
|
List all privileges. |
|
List privileges for a specific role. |
|
List privileges for a specific user, or the current user. |
Examples for listing all privileges
Available privileges for all roles can be displayed using SHOW PRIVILEGES
.
SHOW [ALL] PRIVILEGES
[YIELD field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
SHOW PRIVILEGES
Lists all privileges for all roles. The table contains columns describing the privilege:
-
access
: whether the privilege is granted or denied -
action
: which type of privilege this is: traverse, read, match, write, a database privilege, a dbms privilege or admin -
resource
: what type of scope this privilege applies to: the entire dbms, a database, a graph or sub-graph access -
graph
: the specific database or graph this privilege applies to -
segment
: for sub-graph access control, this describes the scope in terms of labels or relationship types -
role
: the role the privilege is granted to
access | action | resource | graph | segment | role |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 34 |
It is also possible to filter and sort the results by using YIELD
, ORDER BY
and WHERE
.
SHOW PRIVILEGES YIELD role, access, action ORDER BY action WHERE role = 'admin'
In this example:
-
The number of columns returned has been reduced with the
YIELD
clause. -
The order of the returned columns has been changed.
-
The results have been filtered to only return the
admin
role using aWHERE
clause. -
The results are ordered by the
action
column usingORDER BY
.
SKIP
and LIMIT
can also be used to paginate the results.
role | access | action |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 9 |
WHERE
can be used without YIELD
SHOW PRIVILEGES WHERE graph <> '*'
In this example, the WHERE
clause is used to filter privileges down to those that target specific graphs only.
access | action | resource | graph | segment | role |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 3 |
Examples for listing privileges for specific role
Available privileges for a particular role can be displayed using SHOW ROLE name PRIVILEGES
.
SHOW ROLE name PRIVILEGES
[YIELD field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
SHOW ROLE regularUsers PRIVILEGES
Lists all privileges for role regularUsers
.
access | action | resource | graph | segment | role |
---|---|---|---|---|---|
|
|
|
|
|
|
Rows: 1 |
Examples for listing privileges for specific user
Available privileges for a particular user can be displayed using SHOW USER name PRIVILEGES
.
Please note that if a non-native auth provider like LDAP is in use, |
SHOW USER [name] PRIVILEGES
[YIELD field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
SHOW USER jake PRIVILEGES
Lists all privileges for user jake
.
access | action | resource | graph | segment | role | user |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 2 |
The same command can be used at all times to review available privileges for the current user. For this purpose, a shorter form of the the command also exists: SHOW USER PRIVILEGES.
SHOW USER PRIVILEGES
The REVOKE
command
Privileges that were granted or denied earlier can be revoked using the REVOKE
command.
REVOKE
[ GRANT | DENY ] graph-privilege
FROM role[, ...]
An example usage of the REVOKE
command is given here:
REVOKE GRANT TRAVERSE ON GRAPH neo4j NODES Post FROM regularUsers
0 rows, System updates: 1
While it can be explicitly specified that revoke should remove a GRANT
or DENY
, it is also possible to revoke either one by not specifying at all as the next example demonstrates.
Because of this, if there happen to be a GRANT
and a DENY
on the same privilege, it would remove both.
REVOKE TRAVERSE ON GRAPH neo4j NODES Payments FROM regularUsers
0 rows, System updates: 2