Changing the default access control on the REST API? (multiple auth-enabled collections) #11767
Unanswered
LucienLeMagicien
asked this question in
Q&A
Replies: 1 comment
-
|
I am having the same issues, probably going to use pnpm patch 😔 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I just started trying Payload out (it's been pretty great so far!), so sorry if I missed something.
The Admin Overview page says that it's possible to have multiple collections that support Authentication (for example
adminsandcustomers) so I went with this pattern. This same page says that settingadmin: { user: 'admins' }in my Payload Config makes sure the Admin panel uses theadminscollection.However, when I use the REST API to log in through the
customerscollection, thenGET /api/access, it tells me I have full create/read/update/delete rights to every collection, includingadminsand internal ones likepayload-locked-documents,payload-preferencesandpayload-migrations.I'm not sure if this is somehow wrong (I assume that the
payload-preferencescollection checks that the user id matches), but it makes sense: the Access Control page says that the "Default access control" looks something like this:Which would also return
trueto mycustomersusers.To limit access to
adminsusers, I have written a simple Access check:However, I can't seem to find a way to override the
defaultPayloadAccessfunction. Do I need to go through all my collections and setaccess? (Is this something I should be doing anyway?)If so, how do I set
accesson internal collections (payload-locked-documents,payload-preferencesandpayload-migrations)?Or am I missing something obvious?Thanks!
For the record, it seems that the "auth" RBAC example would have the same issue. It only has a Users collection, but I don't see how it would avoid having to set
accessfor every collection manually:payload/examples/auth/src/collections/Users.ts
Lines 23 to 29 in ef527fe
(This example also seems to disable access to the Admin Panel to users without the "admin" role, but as far as I can see they'd still have access to the API and full permissions to the internal tables.)
Edit after looking through the code:
The
payload-locked-documentscollection was recently made auth-only: #11624, though as far as I can tell it's still accessible for non-"admin" usersThe
payload-preferencescollection (as I suspected) makes sure all calls to it are from it's owning user. However from what I can tell, thepreferenceAccesscheck doesn't make sure that the current user is from the right collection, so an user in mycustomerstable with id1could read preferences of the user with id1in theadminscollection.payload/packages/payload/src/preferences/config.ts
Lines 9 to 19 in ef527fe
However, it does check correctly in
updateHandlerpayload/packages/payload/src/preferences/operations/update.ts
Lines 20 to 26 in ef527fe
(But I don't think this handles changes made through the graphQL API?)
(By the way, the documentation on custom endpoints doesn't specifically mention that you can override the handlers this way:
payload/packages/payload/src/preferences/config.ts
Lines 43 to 47 in ef527fe
And finally The
payload-migrationscollection has it's REST and GraphQL API disabled, so there's no problem for this one:payload/packages/payload/src/database/migrations/migrationsCollection.ts
Line 8 in ef527fe
Beta Was this translation helpful? Give feedback.
All reactions