Managing privileges
Privileges control the access rights to graph elements using a combined allowlist/denylist 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 |
Graph privilege commands (GRANT
, DENY
and REVOKE
)
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.3 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. -
HOME GRAPH
refers to the graph associated with the home database for that user. The default database will be used as home database if a user does not have a home database configured. If the user’s home database changes for any reason after privileges have been created then these privileges will be associated with the graph attached to the new database. This can be quite powerful as it allows permissions to be switched from one graph to another simply by changing a user’s home database.
-
-
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 following image:

A more detailed syntax illustration would be the following image for graph privileges:

{
and }
are part of the syntax and not used for grouping.The following 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.
|
When using the RETURN
clause, the YIELD
clause is mandatory and may not be omitted.
For an easy overview of the existing privileges, it is recommended to use the AS COMMANDS
version of the show command.
This returns the privileges as the commands that are granted or denied.
Omitting the AS COMMANDS
clause instead gives the result as multiple columns describing the privilege:
-
access
: whether the privilege is granted or denied. -
action
: which type of privilege this is, for example traverse, read, index management, or role management. -
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
: when applicable, the scope this privilege applies to: labels, relationship types, procedures, functions, or transactions. -
role
: the role the privilege is granted to.
Examples for listing all privileges
Available privileges can be displayed using the different SHOW PRIVILEGES
commands.
SHOW [ALL] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
[WHERE expression]
SHOW [ALL] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
SHOW PRIVILEGES
Lists all privileges for all roles:
access | action | resource | graph | segment | role |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 39 |
The |
It is also possible to filter and sort the results by using YIELD
, ORDER BY
and WHERE
:
SHOW PRIVILEGES YIELD role, access, action, segment 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 | segment |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 12 |
The |
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 | graph | resource | role | segment |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 3 |
Aggregations in the RETURN
clause can be used to group privileges.
In this case, by user and granted / denied:
SHOW PRIVILEGES YIELD * RETURN role, access, collect([graph, resource, segment, action]) as privileges
role | access | privileges |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 8 |
The |
The RETURN
clause can also be used to order and paginate the results, which is useful when combined with YIELD
and WHERE
.
In this example the query returns privileges for display five-per-page, and skips the first five to display the second page.
SHOW PRIVILEGES YIELD * RETURN * ORDER BY role SKIP 5 LIMIT 5
access | action | graph | resource | role | segment |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 5 |
Available privileges can also be output as Cypher commands, by appending AS COMMAND[S]
to the show command:
SHOW PRIVILEGES AS COMMANDS
command |
---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 35 |
Like other SHOW
commands, the output can also be processed using YIELD
/ WHERE
/ RETURN
:
SHOW PRIVILEGES AS COMMANDS WHERE command CONTAINS 'MANAGEMENT'
command |
---|
|
|
|
|
|
|
|
|
Rows: 8 |
It is also possible to get the privilege commands formatted for revoking instead of granting or denying the privileges:
SHOW PRIVILEGES AS REVOKE COMMANDS
command |
---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 35 |
For more info about revoking privileges, please see The REVOKE command.
Examples for listing privileges for specific roles
Available privileges for specific roles can be displayed using SHOW ROLE name PRIVILEGES
.
SHOW ROLE[S] name[, ...] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
[WHERE expression]
SHOW ROLE[S] name[, ...] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
SHOW ROLE regularUsers PRIVILEGES
Lists all privileges for role regularUsers
.
access | action | graph | resource | role | segment |
---|---|---|---|---|---|
|
|
|
|
|
|
Rows: 1 |
SHOW ROLES regularUsers, noAccessUsers PRIVILEGES
Lists all privileges for roles regularUsers
and noAccessUsers
.
access | action | graph | resource | role | segment |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 2 |
Similar to the other show privilege commands, the available privileges for roles can also be output as Cypher commands with the optional AS COMMAND[S]
.
command |
---|
|
|
|
|
|
|
|
|
|
|
|
Rows: 11 |
The output can be processed using YIELD
/ WHERE
/ RETURN
here as well.
SHOW ROLE architect PRIVILEGES AS COMMANDS WHERE command CONTAINS 'MATCH'
command |
---|
|
|
|
Again, is it possible to get the privilege commands formatted for revoking instead of granting or denying the privileges. For more info about revoking privileges, please see The REVOKE command.
SHOW ROLE reader PRIVILEGES AS REVOKE COMMANDS
command |
---|
|
|
|
Rows: 3 |
Examples for listing privileges for specific users
Available privileges for specific users can be displayed using SHOW USER name PRIVILEGES
.
Please note that if a non-native auth provider like LDAP is in use, |
SHOW USER[S] [name[, ...]] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
[WHERE expression]
SHOW USER[S] [name[, ...]] PRIVILEGE[S] [AS [REVOKE] COMMAND[S]]
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
SHOW USER jake PRIVILEGES
Lists all privileges for user jake
.
access | action | resource | graph | resource | role | segment |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 4 |
SHOW USERS jake, joe PRIVILEGES
Lists all privileges for users jake
and joe
.
access | action | resource | graph | resource | role | segment |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 8 |
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
As for the other privilege commands, available privileges for users can also be output as Cypher commands with the optional AS COMMAND[S]
.
When showing user privileges as commands, the roles in the Cypher commands are replaced with a parameter. This can be used to quickly create new roles based on the privileges of specific users. |
SHOW USER jake PRIVILEGES AS COMMANDS
command |
---|
|
|
|
|
Rows: 4 |
Like other SHOW
commands, the output can also be processed using YIELD
/ WHERE
/ RETURN
.
Additionally, similar to the other show privilege commands, it is also possible to show the commands for revoking the privileges.
SHOW USER jake PRIVILEGES AS REVOKE COMMANDS WHERE command CONTAINS 'EXECUTE'
command |
---|
|
|
Rows: 2 |
Revoking privileges
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 HOME GRAPH NODES Post FROM regularUsers
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 HOME GRAPH NODES Payments FROM regularUsers