feat: Using SameAs generator for dynamic binding of permissions#2267
feat: Using SameAs generator for dynamic binding of permissions#2267mesemus wants to merge 2 commits intoinveniosoftware:masterfrom
Conversation
9e0dc0d to
6085496
Compare
max-moser
left a comment
There was a problem hiding this comment.
Tested with our custom permission policy override in a v13 setup, worked great (see the comment on the other PR)!
LGTM
zzacharo
left a comment
There was a problem hiding this comment.
@mesemus LGTM, one question about the warning you added about the change being incompatible: Until now the only way to override this was to inherit the corresponding permission class and replicate the static bindings. Can you ellaborate on which cases you could see this breaking for instance administrators?
I agree that this situation would be extremely rare (and probably pathological), but I can still envision the following scenario. A user created their permission policy in an older version of InvenioRDM, before a new permission (let's call it One might argue that this effectively "fixes" a misconfiguration in the user's setup. However, it also means that users may gain (or lose) access through can_A without the administrator being aware of it, since its behaviour would now depend on a previously customised permission. I consider permissions to be "a form" of public API. Because of their importance and stability expectations, changing the effective behaviour of already existing permissions should, in my opinion, require a new major version. Sidenote: I would also like to propagate the |
@mesemus fine by me, I agree with releasing as major for granular upgrade of instances following the v14dev track :) Ping @ntarocco @slint for reference. |
i try to understand the scenario. so this would mean that a instance manager has as an example set up their v13 instance with the following custom permission policy as i understand the inheritance does this mean that since now
which by definition is the main feature of |
* Changed the can_abc = can_xyz + [other generators]
into can_abc = SameAs("can_xyz") + [...]
* This allows for an easier inheritance of the permission policy
but semantically clearer alternatives * `can_preview` now extends `can_review` instead of `can_curate`, removing the need to repeat `SubmissionReviewer`. * `can_view` no longer requires an additional `SubmissionReviewer`, as it is already included in `can_preview`. * Replaced `can_authenticated` with `can_create` where it was effectively used to represent creation permissions. * All PID operations now consistently use `can_pid_create` as the base permission. Co-authored-by: Max <maximilian.moser@tuwien.ac.at>
f66f1b7 to
e66330f
Compare
|
I was trying to find an example that would not be too pathological :) Let's try to illustrate it on a pair of In invenio_rdm_records, we've had in RDM13 (with a bit of simplification): class RDMRecordPermissionPolicy:
can_review = [...]
can_publish = can_review # IfConfig there but can_review is used in the endNow let's suppose repository administrator has created the following policy: class ExtendedRecordPermissionPolicy(RDMRecordPermissionPolicy):
can_review = (
[UserWithRole('extra-review-role')] +
RDMRecordPermissionPolicy.can_review
)In RDM13, this results in users with With this PR, |
|
@mesemus so we have this: https://xkcd.com/1172/ situation? and thanks for the explanation. it's clear now |
Yes - one way repository administrators may have extended the permission policy was by copying the entire RDM policy. Those installations are safe with this change, but administrators should still be informed that there is now a better way. Another approach admins might have taken would be to copy/override only the parts they really wanted to change, not the whole policy - like in the example above. With this PR, installations that followed this approach might experience altered access behaviour. Btw, I've also propagated the SameAs to communities and requests - see inveniosoftware/invenio-requests#582 |
Warning
This is a backward-incompatible change, as users might, in rare cases, rely on the static binding inside the base permission policy.
Description
This PR replaces static binding of permissions with a dynamic one using
SameAs.It depends on inveniosoftware/invenio-records-permissions#119
Rationale
A permission policy can be a complicated thing - look for example at the RDM permission policy:
If we inherit from the policy and modify the
can_manageto include another group of users:can_curateis not updated as a user might expect. When evaluating permissions,can_curatewill not contain theUsersWithRolegenerator because it was created statically inside theRDMPermissionPolicyclass.The
SameAsgenerator addresses this issue by introducing dynamic binding — the delegation/inclusion happens at permission evaluation time. If the RDM policy were defined as follows:the example above would work as the user would intuitively expect.
Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: