Problem/Motivation
Facts for Drupal 8.0 & Drupal 8.1's REST:
- REST module's
EntityResource
respects Entity Access & Field Access. - REST module requires every entity type to be explicitly enabled in
rest.settings.yml
.
Therefore it is very confusing that every entity type gets another permission, per verb, to be able to actually use that REST resource.
Proposed resolution
@klausi at #1816354-1: Add a REST module, starting with DELETE:
Access control is also a problem right now, we don't have that in the routing system yet (see #1793520: Add access control mechanism for new router system for work on that). And we don't have something like entity_access() or access controllers in core (see #1696660: Add an entity access API for single entity access for that). I think I will just expose my own permissions right now ("read resourceXY over REST API", "create resourceXY over REST API" etc.) and check for that.
That is the issue that brought REST to core. It was not at all discussed further. No follow-up was created. In other words: very little scrutiny was applied to the REST module before it could be committed to Drupal 8. I'm certain such a patch would not have been able to land in the past few years (say, since 2014) — it looks like we were far more lax in 2012.
It's totally possible that access handling in general and permission handling in particular were discussed elsewhere, but if so, I could not find it (I looked at all these issues).
The only other issue that was remotely related is #1866908: Honor entity and field access control in REST Services. In there, two commits happened:
the first marked \Drupal\rest\Plugin\rest\resource\EntityResource::permissions()
's permissions as "restricted" (this method no longer exists), as a stopgap. The second commit removed that, and instead added proper entity access checking. But … it did in fact NOT remove the permissions for entities! It just kept them!
In other words, the only reason permissions still exist, at least for EntityResource
, is simply that this was overlooked. No follow-up issue was created, and thus it was simply forgotten. It makes sense to allow @RestResource
to opt in to having a permission, for example in the case of DbLogResource
. But it does not make sense to always have this, without even the ability to opt out!
We (which includes dawehner, Crell, I, and others) also discussed this at DrupalCon New Orleans and unanimously agreed that:
- it does not make sense for Drupal 8 to continue to have permissions enabled by default for
EntityResource
- we should not break BC
- we should therefore make sure that newly installed Drupal 8.2 sites don't need to enable these permissions for
EntityResource
, but existing Drupal 8 sites will continue to use that
This issue/patch therefore proposes:
- we keep permissions enabled by default for
@RestResource
plugins: this guarantees BC for all custom/contrib REST resources - we remove permissions from
EntityResource
in Drupal 8.2.x by default, but keep them enabled for existing Drupal installations - we document A) why we have permissions, B) how you can opt out from permissions for a particular REST resource
Remaining tasks
None.
User interface changes
None.
API changes
- The
EntityResource
@RestResource
opts out from generating the permissions thatResourceBase
generates by default, but only for new sites. - Other
@RestResource
s continue to generate permissions. This means all contrib/custom ones continue to work as they do today. - For details, see the change record: https://www.drupal.org/node/2733435.
Data model changes
New key in rest.settings
configuration: bc_entity_resource_permissions
. Upgrade path provided: rest_update_8203()
.