Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement permission policies in the API #22384

Draft
wants to merge 241 commits into
base: auditus
Choose a base branch
from
Draft

Conversation

rijkvanzanten
Copy link
Member

@rijkvanzanten rijkvanzanten commented May 3, 2024

Scope

What's changed:

  • Implements policy-system based permissions handling on the API
  • Replaces AuthorizationService with new set of functions in the api/src/permissions folder
  • Allows roles to be nested
  • Adds new roles flag to accountability object. This is an ordered array of all the parent roles of the current user
  • Cleans up get-ast-from-query by splitting it into multiple files
  • Permissions are now injected into the AST through cases and whenCase. This allows us to dynamically generate the case/when SQL to have dynamic field output per item.
  • Cleans up run-ast by splitting it up into smaller files

Potential Risks / Drawbacks

  • The risks are very high. This replaces the full permissions system, and thus needs a lot of testing

Review Notes / Questions

  • This PR now compiles, but doesn't run yet.
  • There was some weird logic happening in the users controller for TFA enable/disable that I'm not sure we need to keep. Needs a bit more testing

Todos

  • Add permissions processing for $CURRENT_USER etc flags
    • Introduce $CURRENT_POLICIES and $CURRENT_ROLES for permissions
    • Decide if $CURRENT_POLICIES and $CURRENT_ROLES should be available in presets as well
  • Add permissions merging when you're accessing from a share
  • Add caching to:
    • Fetching Policies
    • Fetching permissions
    • Fetching the roles tree
    • Fetching the field map
    • Fetching allowed fields
    • Fetching allowed collections
  • Enable validation for admin users for wrong paths
  • Figure out what we want to do with Presets
  • Use whenCases in run-ast
  • Use applyCases in Meta Service for permissions aware counts
  • Handle admin-checks in roles and users services1 -> Handled in Rework user integrity checks for Auditus #22737
  • Add unit testing for clear method in memory/cache
  • Make sure graphql gracefully handles optional fields when you have different fields for the same collection in multiple permission sets
  • Add changeset
  • Unbork /permissions endpoint
  • Invalidate cache on permission changes
    • On directus_access changes
    • On directus_roles changes
    • On directus_permissions changes
    • On directus_policies changes
  • Purge request level cache on permission related changes
  • Bring back check-ip middlewares?
  • Fix down migration
  • Fix telemetry user counting -> Handled in Rework user integrity checks for Auditus #22737
  • Fix user limit checking -> Handled in Rework user integrity checks for Auditus #22737
  • Reduce accountability used in the withCache to the known keys -> Handled in Use ip in global access and stabilize accountability keys #22727
  • Fix $FOLLOW field key for filters (Fixed in c00ff5d)
  • Fix handling of o2m fields that have partial permissions set (currently if some access to a o2m related field is given, it is returned for all items, even if the user should not see the field for some items)
  • Account for user IP in the global request cache
  • Make sure that the globalAccess for a public user always has app_access and admin_access false
  • Add new collections to GraphQL
  • Add new collections to websockets
  • Add new endpoints + types to SDK
  • Before merging this one in main, either retarget Add roles and permissions to the app #22654 to main, or merge it in here

Closes #21778, closes #21765, closes #22163, closes #21769, closes #21768, closes #21767, closes #21766

Footnotes

  1. Eg check to make sure there's still >=1 admin left after the mutation is done

hanneskuettner and others added 15 commits June 14, 2024 10:29
* Changes to user counting and integrity checks

* Ensure that user validation happens in both create one and create many

* Rename `checkType` to `flags`

* Update api/src/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.ts

Co-authored-by: Daniel Biegler <[email protected]>

* Update to enum usage

Co-authored-by: Daniel Biegler <[email protected]>

* A few more changes to enum instead of number

* One more enum type update

* Make sure to correctly override the callback when combining options

* Clean up option type

* Update api/src/services/users.ts

Co-authored-by: ian <[email protected]>

* Only take validation shortcut for users

We can only be sure that the deletion of users does not increase any other access types count, so in all other cases we need to verify that for example the App or API users have not increased over the limit

* Make both app and admin users count against app access limit

* Update api/src/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.ts

Co-authored-by: Pascal Jufer <[email protected]>

* One post-merge fix, two small fixes

* Simplify flag updating and callback calling

* Changing app access in a policy only requires user limit checking, not full check

* Only the status of a created user should matter to determine if a check is neccessary

* Add count alias to count query

---------

Co-authored-by: Daniel Biegler <[email protected]>
Co-authored-by: ian <[email protected]>
Co-authored-by: Pascal Jufer <[email protected]>
Co-authored-by: Rijk van Zanten <[email protected]>
* Initial app changes

* Fix getRelationsForField

* Add changeset

* Remove app-permissions from role settings

* Make sure access row uuids are auto generated

* Move a few things around, set up policies m2m properly

* Show roles as tree in sidebar
Change avatar field query for user

* Show user and role count in policy table

* Default to not adding app access for a policy, makes composability less annoying

* Correctly fall back to 0 for counts

* Change the structure of current user permissions

* Start bringing back the public role

* Make the public role a real role rather than a virtual one

* Revert public role changes

* Extend list-m2m to allow for very custom junction matching and a primary key of `null`

* Remove unused

* Fix public role policy update payload

* Fix app access for users without role (which is a thing now apparently)

* Make sure that the /me endpoints always return minimal information, similar to /users/me

* Tweak nav icons

* Pull policy id from constants

* Update permissions interface design to match

New design language in figma

* Some minor adjustments

- Make chip hover border more consistent
- Add "Remove" button to remove a full row of permissions, as in the UI mockup
- Fix table layout

* Clean up a few more things

* Fix `setFullAccess`

* Align collection view icons with navigation

* Don't query 'admin_access' for role

* Fix relation extraction and permissions for `$FOLLOW` fields

* Don't show `0 Items` for child rows, but `--` instead

* Make policy detail work in nested policy creating use case

* Remove unused v-icon override

* Move system collections to separate visual table

* Navigate before refresh

Prevents a flash of the previous value to be visible in the table

* Move composable to separate file

---------

Co-authored-by: Daniel Biegler <[email protected]>
Co-authored-by: Rijk van Zanten <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

None yet

7 participants