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
-
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
admins
andcustomers
) so I went with this pattern. This same page says that settingadmin: { user: 'admins' }
in my Payload Config makes sure the Admin panel uses theadmins
collection.However, when I use the REST API to log in through the
customers
collection, thenGET /api/access
, it tells me I have full create/read/update/delete rights to every collection, includingadmins
and internal ones likepayload-locked-documents
,payload-preferences
andpayload-migrations
.I'm not sure if this is somehow wrong (I assume that the
payload-preferences
collection 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
true
to mycustomers
users.To limit access to
admins
users, I have written a simple Access check:However, I can't seem to find a way to override the
defaultPayloadAccess
function. 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
access
on internal collections (payload-locked-documents
,payload-preferences
andpayload-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
access
for 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-documents
collection was recently made auth-only: #11624, though as far as I can tell it's still accessible for non-"admin" usersThe
payload-preferences
collection (as I suspected) makes sure all calls to it are from it's owning user. However from what I can tell, thepreferenceAccess
check doesn't make sure that the current user is from the right collection, so an user in mycustomers
table with id1
could read preferences of the user with id1
in theadmins
collection.payload/packages/payload/src/preferences/config.ts
Lines 9 to 19 in ef527fe
However, it does check correctly in
updateHandler
payload/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-migrations
collection 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