Comments

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Status: Active » Needs review
StatusFileSize
new12.23 KB

Attached is a proof of concept that requires the two Entity API patches listed above. It hasn't got tests yet, but it shows how we would handle any entity query through this system. If it works, we can do away with node grants altogether.

berdir’s picture

Note that suddenly enforcing this has a lot of side effects on existing sites. The same for groups broke a lot of our custom queries in cron jobs, tests and drush commands where we didn't have a proper authenticated user context, so we have to disable access checking in all those places.

Sure, that's the point of this change in a way, but it should at least be noted *very* prominently in the release notes then :)

kristiaanvandeneynde’s picture

@Berdir I've thought of that :)

  • Existing entities will not get any change unless they implement the permission_provider handler in their GroupContentEnabler plugin.
  • GroupNode will receive this change, but we'll be deleting all of the grants code at the same time so the net result should be (almost) no changes, aside from a hopefully large performance boost
  • Group memberships don't enforce entity access so nothing changes there either

And the release notes will indeed very prominently explain the new option of a permission provider and the fact that adding one to your plugin, even if only the default one, will automagically make all your entity lists secure.


More on point: having to change your queries is indeed a nuisance we have to get past. It's either have no query access checking and be considered insecure, or have query access checking and require people to update their custom queries so they have proper access checks (or none at all).

Commerce ran into the same issue, which is why Bojan did not want to break core all of a sudden by polyfilling the access handlers for all of core's entity types. See #3086409-2: Provide a default query_access handler for core (maybe all?) entity types

kristiaanvandeneynde’s picture

+++ b/src/EventSubscriber/QueryAccessSubscriber.php
@@ -0,0 +1,239 @@
+        // For backwards compatibility reasons, if the group content enabler
+        // plugin used by the group content type does not specify a permission
+        // provider, we do not alter the query for that group content type. In
+        // 8.2.x all group content types will get a permission handler by
+        // default, so this check can be safely removed then.
+        if (!$this->pluginManager->hasHandler($plugin_id, 'permission_provider')) {
+          continue;
+        }

These lines will ensure no sites break all of a sudden. In the other patch (for the relation aka GroupContent entities), we took the same approach. So only GroupContent queries might break for members and group nodes. And by "break" we mean they will no longer return all members, but only the ones you are allowed to see. So it really boils down to a security fix again.

berdir’s picture

Ok, cool, didn't look at the code yet, just wanted to leave a note about that. Just found another bug in a rarely used drush command this week due to the group access changes :)

kristiaanvandeneynde’s picture

StatusFileSize
new14.41 KB

This is the latest version, it has cache tags and deals with the owner properly. Was previously looking for the owner of the group content, whereas it should be looking at the owner of the grouped entities. The beauty of this all is that bundles are taken care of automatically because plugins are bundle-aware :)

Will start writing tests now. I have similar tests in Subgroup, so I'll use those as a starting point.

Status: Needs review » Needs work

The last submitted patch, 8: group-3134072-8-POC.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Fails are expected, they relate to the new Entity API code (which we can't require yet until a new Entity API release is out).

dww’s picture

Coming from #3152324: Add a getPluginIdsByEntityType() method to src/Plugin/GroupContentEnablerManager

Didn't fully review or test anything, but a quick note/nit:

+++ b/src/Plugin/GroupContentEnablerManagerInterface.php
@@ -154,6 +154,17 @@ interface GroupContentEnablerManagerInterface extends PluginManagerInterface, Ca
+   * @return int[]
+   *   The plugin IDs.

Plugin IDs are strings, not ints, right? This should be @return string[] no?

kristiaanvandeneynde’s picture

Yup, thanks for that. Found a few bugs while writing tests, will update in the next patch.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new49.3 KB

Now with working tests and various fixes, as soon as Entity API commits and releases #3086409: Provide a default query_access handler for core (maybe all?) entity types

Status: Needs review » Needs work

The last submitted patch, 13: group-3134072-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new47.97 KB
new324 bytes

Temporary patch to test against entity 1.x-dev, once a release is out we'll want to set it to that min release instead.

Status: Needs review » Needs work

The last submitted patch, 15: group-3134072-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Note quite green yet, but these all look like kernel test fails where node module isn't enabled, so either just enable it or add a check there?

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new2.73 KB
new52.13 KB

Yeah I added new test-only plugins and that caused the issue. "Documented" this in the test module's info.yml file even though that doesn't do anything and added it to the tests that were failing on it.

kristiaanvandeneynde’s picture

StatusFileSize
new52.19 KB

Reroll, going to commit with the dev dependency for now so I can test/clean up the rest of the release. Will change to entity:1.1 before release.

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.