|
| 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 | +[NOTE] |
| 7 | +==== |
| 8 | +Immutable roles are available starting with Neo4j 5.26. |
| 9 | +==== |
| 10 | + |
| 11 | +Immutable privileges and roles are useful for restricting the actions of users who can themselves administer xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-role-management[roles] xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-privilege-management[privileges]. |
| 12 | + |
| 13 | + |
| 14 | +[CAUTION] |
| 15 | +==== |
| 16 | +Immutable privileges and roles should only be used in situations where changes are rare. |
| 17 | +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). |
| 18 | +Typically, this type of modification should only be made once during the commissioning phase of a DBMS. |
| 19 | +==== |
| 20 | + |
| 21 | +[[administer-immutable-roles-and-privileges]] |
| 22 | +== Administer immutable roles and privileges |
| 23 | + |
| 24 | +After the DBMS is safely isolated from external connections, follow these steps to administer immutable roles and privileges: |
| 25 | + |
| 26 | +. Change the config setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] to `false`. |
| 27 | +. Restart the DBMS. |
| 28 | +. Create or remove immutable privileges and roles in the same way as regular privileges and roles but with the addition of the `IMMUTABLE` keyword. |
| 29 | +See <<immutable-roles-privileges-examples, Examples>>. |
| 30 | +. Change the config setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] back to `true`. |
| 31 | +. Restart the DBMS. |
| 32 | + |
| 33 | +Privileges and roles created in this way can now appear to all users as an immutable part of the DBMS. |
| 34 | +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`. |
| 35 | + |
| 36 | +[[immutable-roles-privileges-examples]] |
| 37 | +== Examples |
| 38 | + |
| 39 | +The following examples demonstrate how to use Cypher to manage immutable roles and privileges. |
| 40 | + |
| 41 | +=== Restricting the actions of users who can manage privileges |
| 42 | + |
| 43 | +To prevent all users, including the `admin` user, from performing *database management*, follow these steps: |
| 44 | + |
| 45 | +. Ensure that you have completed steps 1 an 2 from <<administer-immutable-roles-and-privileges>>. |
| 46 | +. Run the following command to deny the `IMMUTABLE DATABASE MANAGEMENT` privilege to the `PUBLIC` role: |
| 47 | ++ |
| 48 | +[source, cypher, role=test-skip] |
| 49 | +---- |
| 50 | +DENY IMMUTABLE DATABASE MANAGEMENT ON DBMS TO PUBLIC |
| 51 | +---- |
| 52 | + |
| 53 | +. Verify that the `IMMUTABLE` keyword has been added to the privilege: |
| 54 | ++ |
| 55 | +[source, cypher, role=noplay] |
| 56 | +---- |
| 57 | +SHOW PRIVILEGES WHERE IMMUTABLE |
| 58 | +---- |
| 59 | ++ |
| 60 | +.Result |
| 61 | +[options="header,footer", width="100%", cols="1m,2m,1m,1m,1m,1m,1m"] |
| 62 | +|=== |
| 63 | +|access |
| 64 | +|action |
| 65 | +|resource |
| 66 | +|graph |
| 67 | +|segment |
| 68 | +|role |
| 69 | +|immutable |
| 70 | + |
| 71 | +|"DENIED" |
| 72 | +|"database_management" |
| 73 | +|"database" |
| 74 | +|"*" |
| 75 | +|"database" |
| 76 | +|"PUBLIC" |
| 77 | +|true |
| 78 | + |
| 79 | +7+a|Rows: 2 |
| 80 | +|=== |
| 81 | ++ |
| 82 | +The result shows that all users are restricted from adding or removing privileges, including the `admin` user. |
| 83 | +. Ensure you have completed steps 4 and 5 from <<administer-immutable-roles-and-privileges>>. |
| 84 | + |
| 85 | +=== Restricting the actions of users who can manage roles and privileges |
| 86 | + |
| 87 | +If you want permanent privileges but with more control over which users they apply to, you need to use immutable roles with immutable privileges. |
| 88 | +For example, you have a user called `alice` who has `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges. |
| 89 | +To prevent `alice` from dropping any databases and from being able to remove this restriction using their `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges, follow these steps: |
| 90 | + |
| 91 | +. Ensure that you have completed steps 1 an 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 restrictedAdmin |
| 97 | +---- |
| 98 | + |
| 99 | +. Immutably deny the `DROP DATABASE` privilege: |
| 100 | ++ |
| 101 | +[source, cypher, role=noplay] |
| 102 | +---- |
| 103 | +DENY IMMUTABLE DROP DATABASE ON DBMS TO restrictedAdmin |
| 104 | +---- |
| 105 | + |
| 106 | +. Grant the restrictedAdmin role to `alice` to prevent her dropping databases: |
| 107 | ++ |
| 108 | +[source, cypher, role=noplay] |
| 109 | +---- |
| 110 | +GRANT restrictedAdmin TO alice |
| 111 | +---- |
| 112 | ++ |
| 113 | +. Ensure you have completed steps 4 and 5 from <<administer-immutable-roles-and-privileges>>. |
| 114 | ++ |
| 115 | +Now, despite having `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges, `alice` will not be able do any of the following: |
| 116 | ++ |
| 117 | +.Drop databases: |
| 118 | +[source, cypher, role=noplay] |
| 119 | +---- |
| 120 | +DROP DATABASE foo |
| 121 | +---- |
| 122 | ++ |
| 123 | +.Remove the restrictedAdmin role from `alice` |
| 124 | +[source, cypher, role=noplay] |
| 125 | +---- |
| 126 | +REVOKE ROLE restrictedAdmin FROM alice |
| 127 | +---- |
| 128 | ++ |
| 129 | +.Remove the `DROP DATABASE` privilege from the restrictedAdmin role |
| 130 | +[source, cypher, role=noplay] |
| 131 | +---- |
| 132 | +DROP ROLE restrictedAdmin |
| 133 | +---- |
| 134 | ++ |
| 135 | +.Remove `DENY DROP DATABASE` from the restrictedAdmin role |
| 136 | +[source, cypher, role=noplay] |
| 137 | +---- |
| 138 | +REVOKE DENY DROP DATABASE ON DBMS FROM restrictedAdmin |
| 139 | +---- |
| 140 | + |
| 141 | +[NOTE] |
| 142 | +==== |
| 143 | +Only immutable privileges (e.g. `DENY IMMUTABLE DROP DATABASE` in the example above) can be assigned to immutable roles. |
| 144 | +This is to make sure that the role and all of its privileges is explicitly and completely immutable. |
| 145 | +==== |
| 146 | + |
0 commit comments