Tim Möhlmann
3f6ea78c87
perf: role permissions in database ( #9152 )
...
# Which Problems Are Solved
Currently ZITADEL defines organization and instance member roles and
permissions in defaults.yaml. The permission check is done on API call
level. For example: "is this user allowed to make this call on this
org". This makes sense on the V1 API where the API is permission-level
shaped. For example, a search for users always happens in the context of
the organization. (Either the organization the calling user belongs to,
or through member ship and the x-zitadel-orgid header.
However, for resource based APIs we must be able to resolve permissions
by object. For example, an IAM_OWNER listing users should be able to get
all users in an instance based on the query filters. Alternatively a
user may have user.read permissions on one or more orgs. They should be
able to read just those users.
# How the Problems Are Solved
## Role permission mapping
The role permission mappings defined from `defaults.yaml` or local
config override are synchronized to the database on every run of
`zitadel setup`:
- A single query per **aggregate** builds a list of `add` and `remove`
actions needed to reach the desired state or role permission mappings
from the config.
- The required events based on the actions are pushed to the event
store.
- Events define search fields so that permission checking can use the
indices and is strongly consistent for both query and command sides.
The migration is split in the following aggregates:
- System aggregate for for roles prefixed with `SYSTEM`
- Each instance for roles not prefixed with `SYSTEM`. This is in
anticipation of instance level management over the API.
## Membership
Current instance / org / project membership events now have field table
definitions. Like the role permissions this ensures strong consistency
while still being able to use the indices of the fields table. A
migration is provided to fill the membership fields.
## Permission check
I aimed keeping the mental overhead to the developer to a minimal. The
provided implementation only provides a permission check for list
queries for org level resources, for example users. In the `query`
package there is a simple helper function `wherePermittedOrgs` which
makes sure the underlying database function is called as part of the
`SELECT` query and the permitted organizations are part of the `WHERE`
clause. This makes sure results from non-permitted organizations are
omitted. Under the hood:
- A Pg/PlSQL function searches for a list of organization IDs the passed
user has the passed permission.
- When the user has the permission on instance level, it returns early
with all organizations.
- The functions uses a number of views. The views help mapping the
fields entries into relational data and simplify the code use for the
function. The views provide some pre-filters which allow proper index
usage once the final `WHERE` clauses are set by the function.
# Additional Changes
# Additional Context
Closes #9032
Closes https://github.com/zitadel/zitadel/issues/9014
https://github.com/zitadel/zitadel/issues/9188 defines follow-ups for
the new permission framework based on this concept.
2025-01-16 10:09:15 +00:00
..
2023-12-08 15:30:55 +01:00
2024-05-04 11:55:57 +02:00
2024-07-31 14:42:12 +02:00
2024-11-28 10:06:52 +00:00
2024-07-31 14:42:12 +02:00
2024-11-28 10:06:52 +00:00
2024-11-28 10:06:52 +00:00
2024-11-28 10:06:52 +00:00
2024-11-28 10:06:52 +00:00
2023-12-08 15:30:55 +01:00
2024-06-17 09:50:12 +00:00
2024-12-19 10:37:46 +01:00
2024-12-19 10:37:46 +01:00
2024-11-04 10:44:51 +00:00
2023-12-05 17:01:03 +00:00
2024-11-28 10:06:52 +00:00
2024-08-12 22:32:01 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-08-28 05:33:20 +00:00
2024-08-28 05:33:20 +00:00
2022-12-01 13:31:46 +01:00
2024-09-11 08:24:00 +00:00
2024-09-11 08:24:00 +00:00
2024-09-11 08:24:00 +00:00
2022-04-26 23:01:45 +00:00
2024-09-03 13:19:00 +00:00
2024-09-17 13:21:49 +00:00
2024-09-17 13:21:49 +00:00
2024-09-11 10:53:55 +00:00
2023-10-19 15:21:31 +00:00
2022-04-26 23:01:45 +00:00
2022-04-26 23:01:45 +00:00
2022-10-17 19:19:15 +00:00
2024-05-07 06:11:20 +00:00
2024-08-12 22:32:01 +02:00
2024-07-04 14:11:06 +00:00
2023-12-08 15:30:55 +01:00
2024-05-23 05:04:07 +00:00
2024-06-19 12:56:33 +02:00
2024-05-13 16:01:50 +02:00
2024-04-03 10:43:43 +00:00
2024-08-28 05:33:20 +00:00
2024-06-17 12:47:38 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-17 12:47:38 +00:00
2023-10-19 12:19:10 +02:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2023-10-19 12:19:10 +02:00
2024-11-22 17:25:28 +01:00
2023-12-08 15:30:55 +01:00
2023-10-19 15:21:31 +00:00
2024-12-19 10:37:46 +01:00
2024-07-31 18:00:38 +03:00
2025-01-16 10:09:15 +00:00
2024-09-04 10:14:50 +00:00
2025-01-16 10:09:15 +00:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2024-04-09 19:32:00 +00:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-05-23 05:04:07 +00:00
2024-04-05 09:35:49 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-12-03 10:38:28 +00:00
2024-12-03 10:38:28 +00:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-11 09:16:10 +02:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2025-01-16 10:09:15 +00:00
2023-12-08 15:30:55 +01:00
2024-08-12 22:32:01 +02:00
2023-12-21 10:03:37 +01:00
2023-10-26 05:54:09 +00:00
2024-08-12 22:32:01 +02:00
2024-05-23 12:28:46 +02:00
2022-04-26 23:01:45 +00:00
2023-10-19 12:19:10 +02:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-19 10:25:50 +00:00
2024-04-03 10:43:43 +00:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-01-25 09:49:41 +01:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-10 09:14:55 +00:00
2024-08-12 22:32:01 +02:00
2024-05-30 22:08:48 +00:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2024-05-13 16:01:50 +02:00
2024-03-20 10:18:46 +00:00
2024-02-28 10:21:11 +00:00
2023-10-19 12:19:10 +02:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-09-13 13:22:25 +00:00
2024-12-19 10:37:46 +01:00
2024-08-12 22:32:01 +02:00
2024-07-31 18:00:38 +03:00
2024-07-31 18:00:38 +03:00
2025-01-16 10:09:15 +00:00
2022-04-26 23:01:45 +00:00
2024-08-14 14:18:14 +00:00
2024-08-14 14:18:14 +00:00
2024-01-17 10:16:48 +00:00
2024-01-17 10:16:48 +00:00
2024-08-12 22:32:01 +02:00
2024-01-17 10:16:48 +00:00
2024-10-31 15:57:17 +01:00
2024-10-31 15:57:17 +01:00
2024-07-31 18:00:38 +03:00
2022-04-26 23:01:45 +00:00
2022-10-07 09:44:28 +00:00
2024-10-28 08:29:34 +00:00
2024-11-04 10:44:51 +00:00
2024-10-28 08:29:34 +00:00
2024-11-27 15:01:17 +00:00
2022-04-26 23:01:45 +00:00
2024-05-16 07:07:56 +02:00
2024-11-12 15:20:48 +00:00
2024-11-12 15:20:48 +00:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-05-13 16:01:50 +02:00
2022-04-26 23:01:45 +00:00
2024-08-28 05:33:20 +00:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-11-28 17:09:00 +00:00
2024-08-12 22:32:01 +02:00
2024-07-31 18:00:38 +03:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-11-14 14:04:39 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-05-23 05:04:07 +00:00
2024-04-05 09:35:49 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-12-03 10:38:28 +00:00
2024-12-03 10:38:28 +00:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2022-09-20 14:32:09 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2022-11-30 17:01:17 +01:00
2023-12-08 15:30:55 +01:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-10 09:14:55 +00:00
2024-04-10 09:14:55 +00:00
2024-06-19 12:56:33 +02:00
2022-11-30 17:01:17 +01:00
2022-04-26 23:01:45 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2023-01-25 09:49:41 +01:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-07-31 18:00:38 +03:00
2024-07-31 18:00:38 +03:00
2023-12-08 15:30:55 +01:00
2024-09-26 09:14:33 +02:00
2023-10-26 05:54:09 +00:00
2022-04-26 23:01:45 +00:00
2023-07-20 04:06:16 +00:00
2022-04-26 23:01:45 +00:00
2023-01-25 09:49:41 +01:00
2022-12-08 08:11:49 +01:00
2022-04-26 23:01:45 +00:00
2023-12-08 15:30:55 +01:00
2024-04-10 09:14:55 +00:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2024-04-05 09:35:49 +00:00
2024-08-28 18:19:50 +00:00
2024-08-28 18:19:50 +00:00
2024-04-03 10:43:43 +00:00
2024-04-05 09:35:49 +00:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2024-12-19 10:37:46 +01:00
2024-12-19 10:37:46 +01:00
2024-12-19 10:37:46 +01:00
2023-04-05 11:42:00 +00:00
2024-10-28 08:29:34 +00:00
2024-10-28 08:29:34 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-12-19 10:37:46 +01:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-06-20 13:31:58 +00:00
2024-10-30 08:53:00 +00:00
2024-12-03 14:38:25 +00:00
2024-12-03 14:38:25 +00:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2024-10-30 08:53:00 +00:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-07-03 15:00:56 +00:00
2024-10-28 08:29:34 +00:00
2024-10-28 08:29:34 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2023-10-19 12:19:10 +02:00
2023-09-15 16:58:45 +02:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2023-12-09 08:59:51 +00:00
2023-12-05 11:12:01 +00:00
2024-08-12 22:32:01 +02:00
2024-04-08 08:15:44 +00:00
2024-12-19 11:11:40 +00:00
2024-12-19 11:11:40 +00:00
2024-12-19 11:11:40 +00:00
2024-12-19 11:11:40 +00:00
2024-12-19 11:11:40 +00:00
2024-12-19 11:11:40 +00:00
2023-08-11 15:36:18 +00:00
2024-09-26 09:14:33 +02:00
2024-10-07 07:12:44 +02:00
2024-10-10 13:53:32 +00:00
2024-08-12 22:32:01 +02:00
2024-05-30 22:08:48 +00:00
2023-12-08 15:30:55 +01:00
2024-10-07 07:12:44 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-12 06:27:29 +02:00
2024-09-12 06:27:29 +02:00
2022-04-26 23:01:45 +00:00
2025-01-16 10:09:15 +00:00
2024-09-04 10:14:50 +00:00
2025-01-16 10:09:15 +00:00
2023-10-19 15:21:31 +00:00
2024-01-02 14:26:31 +00:00
2024-05-16 07:07:56 +02:00
2023-12-08 15:30:55 +01:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2022-08-24 11:38:59 +02:00
2024-08-12 22:32:01 +02:00
2024-07-04 16:18:43 +00:00
2024-04-03 10:43:43 +00:00
2022-04-26 23:01:45 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-24 17:50:58 +02:00
2024-08-12 22:32:01 +02:00
2024-07-17 06:43:07 +02:00
2024-04-24 17:50:58 +02:00
2024-08-12 22:32:01 +02:00
2024-05-02 11:50:13 +02:00
2023-09-07 14:06:11 +00:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-12-03 10:14:04 +00:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-12-03 10:14:04 +00:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-05-16 07:07:56 +02:00
2024-10-31 15:57:17 +01:00
2023-08-11 15:36:18 +00:00
2024-12-03 10:14:04 +00:00
2025-01-14 15:44:41 +01:00
2023-08-04 11:35:36 +02:00
2024-08-14 13:04:26 +00:00
2024-08-14 13:04:26 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-05 09:35:49 +00:00
2024-08-12 22:32:01 +02:00
2024-04-05 09:35:49 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2022-07-06 14:09:49 +02:00
2022-11-30 17:01:17 +01:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2025-01-14 15:44:41 +01:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-09-17 08:27:48 +00:00
2024-08-28 19:46:45 +00:00
2024-09-17 08:27:48 +00:00
2024-08-12 22:32:01 +02:00
2024-12-27 16:34:38 +01:00
2024-12-27 16:34:38 +01:00
2024-11-28 17:09:00 +00:00
2025-01-14 15:44:41 +01:00
2024-09-11 10:53:55 +00:00
2024-09-11 10:53:55 +00:00
2024-12-03 10:14:04 +00:00
2024-10-07 07:12:44 +02:00
2024-09-26 09:14:33 +02:00
2024-12-03 10:14:04 +00:00
2024-12-03 10:14:04 +00:00
2024-10-07 07:12:44 +02:00
2024-12-03 10:14:04 +00:00
2024-09-26 09:14:33 +02:00
2024-12-03 10:14:04 +00:00
2024-08-12 22:32:01 +02:00
2024-05-14 09:20:31 +02:00
2024-05-07 05:38:26 +00:00
2024-07-31 18:00:38 +03:00
2024-05-07 05:38:26 +00:00
2024-07-05 09:36:00 +02:00
2024-12-03 10:14:04 +00:00
2024-09-25 13:31:31 +00:00
2024-09-25 13:31:31 +00:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-11 10:53:55 +00:00
2024-08-14 14:18:14 +00:00
2024-08-14 14:18:14 +00:00
2024-08-14 14:18:14 +00:00