|
| 1 | +[role=enterprise-edition not-on-aura] |
| 2 | +[[immutable-roles-and-privileges]] |
| 3 | += Immutable roles and privileges |
| 4 | +:description: This section explains how to use Cypher to manage immutable roles and privileges. |
| 5 | + |
| 6 | + |
| 7 | +Immutable privileges are useful for restricting the actions of users who can themselves administer xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-privilege-management[privileges]. |
| 8 | +Starting with Neo4j 5.26, Neo4j also introduces immutable roles. |
| 9 | +Immutable roles are useful for providing _system roles_, which appear as permanent parts of the DBMS. |
| 10 | + |
| 11 | + |
| 12 | +[CAUTION] |
| 13 | +==== |
| 14 | +Immutable privileges and roles should only be used in situations where changes are rare. |
| 15 | +They are intentionally difficult to modify, so changes should be undertaken with caution (e.g., when the DBMS has been isolated by some other means and unauthorized access can be reliably prevented). |
| 16 | +Typically, this type of modification should only be made once during the commissioning phase of a DBMS. |
| 17 | +==== |
| 18 | + |
| 19 | +[[administer-immutable-roles-and-privileges]] |
| 20 | +== Administer immutable roles and privileges |
| 21 | + |
| 22 | +After the DBMS is safely isolated from external connections, follow these steps to administer immutable roles and privileges: |
| 23 | + |
| 24 | +. Change the config setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] to `false`. |
| 25 | +. Restart the DBMS. |
| 26 | +. Create or remove immutable privileges and roles in the same way as regular privileges and roles but with the addition of the `IMMUTABLE` keyword. |
| 27 | +See <<immutable-roles-privileges-examples, Examples>>. |
| 28 | +. Change the config setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] back to `true`. |
| 29 | +. Restart the DBMS. |
| 30 | + |
| 31 | +Privileges and roles created in this way now appear as an immutable part of the DBMS. |
| 32 | +If you want to change or remove them, you must repeat the process of setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] to `false`. |
| 33 | + |
| 34 | +[[immutable-roles-privileges-examples]] |
| 35 | +== Examples |
| 36 | + |
| 37 | +The following examples demonstrate how to use Cypher to manage immutable roles and privileges. |
| 38 | + |
| 39 | +=== Restricting the actions of users who can manage privileges |
| 40 | + |
| 41 | +To prevent all users (including those with `PRIVILEGE MANAGEMENT` privileges) from performing *database management*, attach an immutable privilege to the `PUBLIC` role. |
| 42 | +The `PUBLIC` role implicitly and irrevocably applies to all users. |
| 43 | + |
| 44 | +. Ensure that you have completed steps 1 and 2 from <<administer-immutable-roles-and-privileges>>. |
| 45 | +. Run the following command to deny the `IMMUTABLE DATABASE MANAGEMENT` privilege to the `PUBLIC` role: |
| 46 | ++ |
| 47 | +[source, cypher, role=test-skip] |
| 48 | +---- |
| 49 | +DENY IMMUTABLE DATABASE MANAGEMENT ON DBMS TO PUBLIC |
| 50 | +---- |
| 51 | + |
| 52 | +. Verify that the `IMMUTABLE` keyword has been added to the privilege: |
| 53 | ++ |
| 54 | +[source, cypher, role=noplay] |
| 55 | +---- |
| 56 | +SHOW PRIVILEGES WHERE IMMUTABLE |
| 57 | +---- |
| 58 | ++ |
| 59 | +.Result |
| 60 | +[options="header,footer", width="100%", cols="1m,2m,1m,1m,1m,1m,1m"] |
| 61 | +|=== |
| 62 | +|access |
| 63 | +|action |
| 64 | +|resource |
| 65 | +|graph |
| 66 | +|segment |
| 67 | +|role |
| 68 | +|immutable |
| 69 | + |
| 70 | +|"DENIED" |
| 71 | +|"database_management" |
| 72 | +|"database" |
| 73 | +|"*" |
| 74 | +|"database" |
| 75 | +|"PUBLIC" |
| 76 | +|true |
| 77 | + |
| 78 | +7+a|Rows: 2 |
| 79 | +|=== |
| 80 | ++ |
| 81 | +The result shows that all users are restricted from adding or removing privileges, including the `admin` user. |
| 82 | +. Ensure you have completed steps 4 and 5 from <<administer-immutable-roles-and-privileges>>. |
| 83 | + |
| 84 | +=== Creating permanent roles that cannot be changed |
| 85 | + |
| 86 | +You can use immutable roles to create permanent built-in system roles that cannot be modified even by users who have xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-role-management[`ROLE MANAGEMENT` privileges]. |
| 87 | + |
| 88 | +For example, you want to create an `analyst` role that cannot be dropped, renamed, or have any of its privileges changed (even by users with the `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges). |
| 89 | + |
| 90 | + |
| 91 | +. Ensure that you have completed steps 1 and 2 from <<administer-immutable-roles-and-privileges>>. |
| 92 | +. Create an immutable role to hold the immutable privileges: |
| 93 | ++ |
| 94 | +[source, cypher, role=noplay] |
| 95 | +---- |
| 96 | +CREATE IMMUTABLE ROLE analyst |
| 97 | +---- |
| 98 | + |
| 99 | +. Immutably grant the `MATCH` privilege: |
| 100 | ++ |
| 101 | +[source, cypher, role=noplay] |
| 102 | +---- |
| 103 | +GRANT IMMUTABLE MATCH {*} ON GRAPH * ELEMENTS * TO analyst |
| 104 | +---- |
| 105 | + |
| 106 | +. Ensure you have completed steps 4 and 5 from <<administer-immutable-roles-and-privileges>>. |
| 107 | ++ |
| 108 | +Now, even users with `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges will not be able do any of the following: |
| 109 | ++ |
| 110 | +.Drop the `analyst` role |
| 111 | +[source, cypher, role=noplay] |
| 112 | +---- |
| 113 | +DROP ROLE analyst |
| 114 | +---- |
| 115 | ++ |
| 116 | +.Revoke the `MATCH` privilege from the `analyst` role |
| 117 | +[source, cypher, role=noplay] |
| 118 | +---- |
| 119 | +REVOKE MATCH {*} ON GRAPH * ELEMENTS * FROM analyst |
| 120 | +---- |
| 121 | ++ |
| 122 | +.Rename the `analyst` role |
| 123 | +[source, cypher, role=noplay] |
| 124 | +---- |
| 125 | +RENAME ROLE analyst TO dataReader |
| 126 | +---- |
| 127 | + |
| 128 | +[NOTE] |
| 129 | +==== |
| 130 | +While the make-up (name, existence, associated privileges) of immutable roles is immutable, their assignment to users is not. |
| 131 | +This means that an immutable role can itself be granted to or revoked from a user by any user with `ROLE MANAGEMENT` privileges. |
| 132 | +==== |
| 133 | +[NOTE] |
| 134 | +==== |
| 135 | +Only immutable privileges (e.g. `GRANT IMMUTABLE MATCH {*} ON GRAPH * ELEMENTS * TO analyst` in the example above) can be assigned to immutable roles. |
| 136 | +This is to make sure that an immutable role and all of its privileges is explicitly and completely immutable. |
| 137 | +==== |
| 138 | + |
0 commit comments