|
| 1 | +[role=label--new-5.24] |
| 2 | +[role=enterprise-edition not-on-aura] |
| 3 | +[[access-control-privileges-immutable]] |
| 4 | += Immutable privileges and roles |
| 5 | +:description: This section explains how to use Cypher to manage immutable privileges and roles. |
| 6 | + |
| 7 | +[NOTE] |
| 8 | +==== |
| 9 | +Immutable roles are newly introduced in Neo4j 5.24. Immutable privileges have been available since Neo4j 5.0. |
| 10 | +==== |
| 11 | + |
| 12 | +[[access-control-privileges-immutable-admin]] |
| 13 | +== How to administer immutable privileges and roles |
| 14 | + |
| 15 | +Unlike for regular privileges and roles, immutable privileges and roles cannot be administered by users with xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-privilege-management[PRIVILEGE MANAGEMENT] and xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-role-management[ROLE MANAGEMENT] privileges. Instead, they can only be administered when auth is disabled -- that is, when the configuration setting <<config_dbms.security.auth_enabled,`dbms.security.auth_enabled`>> is set to `false`. |
| 16 | + |
| 17 | +[CAUTION] |
| 18 | +It is intended that administering immutable privileges and roles is an extraordinarily rare scenario and one which should be undertaken with extreme caution (i.e. when the dbms has been isolated by some other means and unauthorized access can be reliably prevented). It is considered to be the kind of action which may be performed once during the commissioning phase of a database. |
| 19 | + |
| 20 | +When the configuration setting <<config_dbms.security.auth_enabled,`dbms.security.auth_enabled`>> is set to `false`, immutable privileges and roles can be administered in a similar way to regular privileges and roles, using the `IMMUTABLE` keyword. |
| 21 | + |
| 22 | +Once the dbms is safely isolated from external connections, follow these steps to administer immutable privileges and roles: |
| 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 xref:authentication-authorization/privileges-and-roles-immutable.adoc#access-control-privileges-immutable-usecase[here] for 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 will now appear to all users as an immutable part of the DBMS. |
| 32 | +The only way to subsequently change or remove them it would be to repeat the process of setting xref:configuration/configuration-settings.adoc#config_dbms.security.auth_enabled[`dbms.security.auth_enabled`] to `false`. |
| 33 | + |
| 34 | + |
| 35 | +[[access-control-privileges-immutable-usecase]] |
| 36 | +== When to use immutable privileges and roles |
| 37 | + |
| 38 | +Immutable privileges and roles are useful for restricting the actions of users who can themselves xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-privilege-management[administer privileges] and xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-role-management[roles]. |
| 39 | + |
| 40 | +=== Immutable privileges |
| 41 | + |
| 42 | +You may want to prevent all users from performing Database Management, even the `admin` user (who are themselves able to add or remove privileges). |
| 43 | +To do so, it would not be adequate to run: |
| 44 | + |
| 45 | +[source, cypher] |
| 46 | +---- |
| 47 | +DENY DATABASE MANAGEMENT ON DBMS TO PUBLIC |
| 48 | +---- |
| 49 | + |
| 50 | +This is because the `admin` user could subsequently runs this: |
| 51 | + |
| 52 | +[source, cypher] |
| 53 | +---- |
| 54 | +REVOKE DENY DATABASE MANAGEMENT ON DBMS FROM PUBLIC |
| 55 | +---- |
| 56 | + |
| 57 | +They would then effectively regain Database Management privileges. |
| 58 | + |
| 59 | +Instead, you could use an immutable privilege. |
| 60 | + |
| 61 | +.Create an immutable privilege |
| 62 | +====== |
| 63 | +
|
| 64 | +[source, cypher, role=test-skip] |
| 65 | +---- |
| 66 | +DENY IMMUTABLE DATABASE MANAGEMENT ON DBMS TO PUBLIC |
| 67 | +---- |
| 68 | +[source, cypher, role=noplay] |
| 69 | +---- |
| 70 | +SHOW PRIVILEGES WHERE IMMUTABLE |
| 71 | +---- |
| 72 | +.Result |
| 73 | +[options="header,footer", width="100%", cols="m,m,m,m,m,m,m"] |
| 74 | +|=== |
| 75 | +|access |
| 76 | +|action |
| 77 | +|resource |
| 78 | +|graph |
| 79 | +|segment |
| 80 | +|role |
| 81 | +|immutable |
| 82 | +
|
| 83 | +|"DENIED" |
| 84 | +|"database_management" |
| 85 | +|"database" |
| 86 | +|"*" |
| 87 | +|"database" |
| 88 | +|"PUBLIC" |
| 89 | +|true |
| 90 | +
|
| 91 | +7+a|Rows: 1 |
| 92 | +|=== |
| 93 | +
|
| 94 | +====== |
| 95 | + |
| 96 | +=== Immutable roles |
| 97 | + |
| 98 | +Immutable _privileges_ are useful when wanting to attach a permanent privilege to the `PUBLIC` role, which will apply to all users (because the `PUBLIC` role applies to all users). |
| 99 | + |
| 100 | +If you want permanent privileges, but with more control over which users they apply to, then you need to use immutable roles in conjunction with immutable privileges. |
| 101 | + |
| 102 | +For example you have a user called `alice` who also has `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges, but you want to prevent them from dropping any databases (and you want to prevent them from being able to simple remove this restriction using their `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges). |
| 103 | + |
| 104 | +.Create an immutable role |
| 105 | +====== |
| 106 | +
|
| 107 | +Create an immutable role to hold the immutable privileges |
| 108 | +[source, cypher, role=noplay] |
| 109 | +---- |
| 110 | +CREATE IMMUTABLE ROLE restrictedAdmin |
| 111 | +---- |
| 112 | +Immutably deny the `DROP DATABASE` privilege. |
| 113 | +[source, cypher, role=noplay] |
| 114 | +---- |
| 115 | +DENY IMMUTABLE DROP DATABASE ON DBMS TO restrictedAdmin |
| 116 | +---- |
| 117 | +Grant the restrictedAdmin role to alice to prevent her dropping databases. |
| 118 | +[source, cypher, role=noplay] |
| 119 | +---- |
| 120 | +GRANT restrictedAdmin TO alice |
| 121 | +---- |
| 122 | +Now (despite having `ROLE MANAGEMENT` and `PRIVILEGE MANAGEMENT` privileges) alice will not be able do any of the following: |
| 123 | +[source, cypher, role=noplay] |
| 124 | +---- |
| 125 | +DROP DATABASE foo |
| 126 | +---- |
| 127 | +[source, cypher, role=noplay] |
| 128 | +---- |
| 129 | +REVOKE ROLE restrictedAdmin FROM alice |
| 130 | +---- |
| 131 | +[source, cypher, role=noplay] |
| 132 | +---- |
| 133 | +DROP ROLE restrictedAdmin |
| 134 | +---- |
| 135 | +[source, cypher, role=noplay] |
| 136 | +---- |
| 137 | +REVOKE DENY DROP DATABASE ON DBMS FROM restrictedAdmin |
| 138 | +---- |
| 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. This is to make sure that the role and all of its privileges is explicitly and completely immutable. |
| 144 | +==== |
| 145 | + |
| 146 | + |
| 147 | + |
0 commit comments