[Bug 43030] New: Add generic own-resource (self-access) authorization to the REST API
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Bug ID: 43030 Summary: Add generic own-resource (self-access) authorization to the REST API Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com Target Milestone: --- This patch adds a generic mechanism for REST API endpoints to allow access to a caller's own resources without requiring the broader module permission (for example, a staff member managing their own lists, or viewing/editing their own patron record, without list_borrowers/edit_borrowers). Today, authorization is all-or-nothing: an endpoint's x-koha-authorization block requires a specific module permission, with no way to grant reduced access based on ownership of the record. Several controllers (Lists, AdvancedEditorMacro, Patrons/Password, Patrons/SelfRenewal) work around this today with inconsistent, ad hoc ownership checks that do not share a common implementation. This patch introduces: - Koha::Object->is_owned_by($patron) and Koha::Objects->owned_by($patron), a shared ownership interface implemented per class (identity based for Koha::Patron, owner field based for Koha::Virtualshelf) - An allow-owner flag on x-koha-authorization, checked in Koha::REST::V1::Auth, that admits an authenticated caller lacking the module permission when the resource is their own - Koha::REST::Plugin::Objects integration so objects.find and objects.search enforce/scope by ownership automatically, without each controller reimplementing the check, and while continuing to support paging, embeds, and existing query parameters - Write path guards so a caller admitted only via ownership cannot create a resource owned by someone else or reassign ownership away from themselves Permission continues to take priority: a caller who holds the module permission is unaffected and retains full, unrestricted access exactly as today. Ownership is only consulted for callers who lack the permission. Initial scope covers the Lists (virtualshelves) and Patrons endpoints, chosen to exercise both ownership shapes (owner field and identity match). Other existing ad hoc self checks are left as follow up work. Test plan: 1. Apply the patches and run the test suite for the affected modules: prove t/Koha/Object.t t/Koha/Objects.t t/db_dependent/Koha/Virtualshelves.t t/db_dependent/Koha/Patrons.t t/db_dependent/api/v1/patrons.t t/db_dependent/api/v1/lists.t 2. As a staff user without any list/shelf permission, confirm GET /api/v1/lists returns only your own lists, and GET /api/v1/lists/{id} succeeds for your own list and returns 403 for someone else's 3. As a staff user without borrowers permissions, confirm GET and PUT /api/v1/patrons/{patron_id} succeed for your own patron_id and return 403 for another patron_id 4. As a staff user with the relevant module permission, confirm both endpoints behave exactly as before (full, unrestricted access) 5. Confirm creating/updating a list while lacking the module permission cannot set the owner field to another patron -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201746 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201746&action=edit Bug 43030: Add Koha::Exceptions::Object::NotImplemented Patch from commit fca8357 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201747 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201747&action=edit Bug 43030: Add Koha::Object->is_owned_by stub method Patch from commit a4edc98 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #3 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201748 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201748&action=edit Bug 43030: Add Koha::Objects->owned_by stub method Patch from commit 2931f0b -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #4 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201749 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201749&action=edit Bug 43030: Add Koha::Patron(s) is_owned_by/owned_by (identity-based ownership) Patch from commit 682dc6d -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201750 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201750&action=edit Bug 43030: Replace Koha::BackgroundJobs::search_limited with is_owned_by/owned_by Patch from commit da3b542 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201751 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201751&action=edit Bug 43030: Add allow-owner support to x-koha-authorization Patch from commit 0a214ee -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201752 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201752&action=edit Bug 43030: Enforce/scope ownership in Koha::REST::Plugin::Objects Patch from commit 108c9c6 -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #8 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201753 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201753&action=edit Bug 43030: Map Koha::Exceptions::Authorization::Unauthorized to 403 in unhandled_exception Koha::REST::Plugin::Objects (Task 7) throws this exception from inside objects.find_rs when koha.self_access is set and the caller doesn't own the resource. Controllers wrap their bodies in try/catch calling $c->unhandled_exception($_), which only recognised a small allowlist of exception types and rendered everything else as a generic 500. Add this type to that allowlist, matching the rendering Koha::REST::V1::Auth already uses for the same exception at the authentication gate. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #9 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201754 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201754&action=edit Bug 43030: Allow self-access to /patrons and /patrons/{patron_id} Adds allow-owner to the GET /patrons collection and GET/PUT /patrons/{patron_id} endpoints, so a staff member without list_borrowers/edit_borrowers can still view/edit their own patron record, scoped automatically to just themselves on the collection. update() now fetches via objects.find_rs (Koha::Patrons->new, not ->search_limited) so it goes through the new ownership check without also picking up the unrelated branch-visibility restriction that search_limited applies to get()/list() -- update never had that restriction and picking it up would silently break staff who hold edit_borrowers but not view_borrower_infos_from_any_libraries. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #10 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201755 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201755&action=edit Bug 43030: Allow self-access to /jobs and /jobs/{job_id} Replaces the catalogue:1 baseline permission with parameters:manage_background_jobs plus allow-owner, so a caller who lacks that permission can still see jobs they personally triggered. This also retires the last manual ownership check in Koha::REST::V1::BackgroundJobs::get in favour of the shared objects.find_rs enforcement from Task 7. Behavior change: a patron with zero permissions can now see their own background jobs (by id or in the collection) where they previously got 403 outright. They could already do so if they held the unrelated catalogue permission, so this narrows what permission is required without broadening what any non-privileged caller can ultimately see. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #11 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201756 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201756&action=edit Bug 43030: Point generic auth-permission tests away from /api/v1/patrons t/db_dependent/api/v1/{auth,auth_basic,oauth}.t each used GET /api/v1/patrons purely as a stand-in "some endpoint requiring a permission" to exercise generic 401/403/503 branches in authenticate_api_request. Now that this endpoint allows self-access, a permission-less patron is admitted (scoped to their own record) instead of rejected, so these generic checks now point at DELETE /api/v1/patrons/-1 instead, which still requires delete_borrowers unconditionally. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #12 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201757 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201757&action=edit Bug 43030: Add missing POD for Koha::Objects _get_objects_class/DESTROY Pre-existing gap surfaced by QA once this file was touched for owned_by(); unrelated to this bug's actual change but blocks QA on the whole file otherwise. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |arthur.suzuki@biblibre.com --- Comment #13 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Hi Martin, that is interesting and would allow a client software to use the patron's credential only, only stored for the length of a session. Much better than a "portal" account with elevated privileges and credential stored in a configuration, to talk to Koha. That would improve security from my point of view. Wondering, would that allow a patron without any staff privilege (plain borrower) to access the API and change its data? What about access to its own holds and checkouts through the /patrons/{id}/checkouts and /holds , is that covered by your patch set? That's promising anyway. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=24067, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=28907 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dcook@prosentient.com.au --- Comment #14 from David Cook <dcook@prosentient.com.au> --- Hmmm very interesting, although I don't know about the concept of "owner". At some point, we'd probably want to change from "self-access" to "all allowed", no? I think part of the problem is that we're very inconsistent with how authorizations work. The problem I see with "owned" is it implies a 1-1 or 1-many relationship, but it could be a many-many relationship in many practical cases. But I'd have to look at the code more closely... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #15 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- I think we need something like that anyway in Koha. Given each class will implement their own "is_owned_by" method, I think it will be easy to implement many2many. I can see an example for the suggestions, it could belong to both a patron and a librarian (who manages the suggestion?). Then is_owned_by could return "true" in several case? Implementing is easy but deciding who should own something is not and should be discussed. For me this patch is a very good starting point which can be used as example to implement for other data anywhere it is needed. I need to actually test it but overall very happy with the approach! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #16 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- 2 tests files failed with "bad plan" because of wrong number of tests : t/db_dependent/Koha/REST/Plugin/Objects.t: tests => 21 → 22 t/db_dependent/api/v1/patrons.t: list() 4 → 5, get() 5 → 6 the 403 I get when trying to get another patron without the proper "borrowers" permission renders : {"error":"Authorization failure. You do not own this resource.","required_permissions":null} which is... inaccurate? Maybe should state "required_permissions": "borrowers" ? or ommit the required_permissions if undef? Also I had to run "yarn api:bundle" after applying the patch set, otherwise the changes are not effective in the API. Appart from all this, works as expected. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Failed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #201746|0 |1 is obsolete| | Attachment #201747|0 |1 is obsolete| | Attachment #201748|0 |1 is obsolete| | Attachment #201749|0 |1 is obsolete| | Attachment #201750|0 |1 is obsolete| | Attachment #201751|0 |1 is obsolete| | Attachment #201752|0 |1 is obsolete| | Attachment #201753|0 |1 is obsolete| | Attachment #201754|0 |1 is obsolete| | Attachment #201755|0 |1 is obsolete| | Attachment #201756|0 |1 is obsolete| | Attachment #201757|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #17 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210431 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210431&action=edit Bug 43030: Add Koha::Exceptions::Object::NotImplemented Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #18 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210432 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210432&action=edit Bug 43030: Add Koha::Object->is_owned_by stub method Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #19 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210433 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210433&action=edit Bug 43030: Add Koha::Objects->owned_by stub method Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #20 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210434 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210434&action=edit Bug 43030: Add Koha::Patron(s) is_owned_by/owned_by (identity-based ownership) Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #21 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210435 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210435&action=edit Bug 43030: Replace Koha::BackgroundJobs::search_limited with is_owned_by/owned_by Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #22 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210436 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210436&action=edit Bug 43030: Add allow-owner support to x-koha-authorization Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #23 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210437 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210437&action=edit Bug 43030: Enforce/scope ownership in Koha::REST::Plugin::Objects Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #24 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210438 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210438&action=edit Bug 43030: Map Koha::Exceptions::Authorization::Unauthorized to 403 in unhandled_exception Koha::REST::Plugin::Objects (Task 7) throws this exception from inside objects.find_rs when koha.self_access is set and the caller doesn't own the resource. Controllers wrap their bodies in try/catch calling $c->unhandled_exception($_), which only recognised a small allowlist of exception types and rendered everything else as a generic 500. Add this type to that allowlist, matching the rendering Koha::REST::V1::Auth already uses for the same exception at the authentication gate. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #25 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210439 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210439&action=edit Bug 43030: Allow self-access to /patrons and /patrons/{patron_id} Adds allow-owner to the GET /patrons collection and GET/PUT /patrons/{patron_id} endpoints, so a staff member without list_borrowers/edit_borrowers can still view/edit their own patron record, scoped automatically to just themselves on the collection. update() now fetches via objects.find_rs (Koha::Patrons->new, not ->search_limited) so it goes through the new ownership check without also picking up the unrelated branch-visibility restriction that search_limited applies to get()/list() -- update never had that restriction and picking it up would silently break staff who hold edit_borrowers but not view_borrower_infos_from_any_libraries. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #26 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210440 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210440&action=edit Bug 43030: Allow self-access to /jobs and /jobs/{job_id} Replaces the catalogue:1 baseline permission with parameters:manage_background_jobs plus allow-owner, so a caller who lacks that permission can still see jobs they personally triggered. This also retires the last manual ownership check in Koha::REST::V1::BackgroundJobs::get in favour of the shared objects.find_rs enforcement from Task 7. Behavior change: a patron with zero permissions can now see their own background jobs (by id or in the collection) where they previously got 403 outright. They could already do so if they held the unrelated catalogue permission, so this narrows what permission is required without broadening what any non-privileged caller can ultimately see. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #27 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210441 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210441&action=edit Bug 43030: Point generic auth-permission tests away from /api/v1/patrons t/db_dependent/api/v1/{auth,auth_basic,oauth}.t each used GET /api/v1/patrons purely as a stand-in "some endpoint requiring a permission" to exercise generic 401/403/503 branches in authenticate_api_request. Now that this endpoint allows self-access, a permission-less patron is admitted (scoped to their own record) instead of rejected, so these generic checks now point at DELETE /api/v1/patrons/-1 instead, which still requires delete_borrowers unconditionally. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #28 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- Created attachment 210442 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210442&action=edit Bug 43030: Add missing POD for Koha::Objects _get_objects_class/DESTROY Pre-existing gap surfaced by QA once this file was touched for owned_by(); unrelated to this bug's actual change but blocks QA on the whole file otherwise. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |arthur.suzuki@biblibre.com |y.org | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210431|0 |1 is obsolete| | Attachment #210432|0 |1 is obsolete| | Attachment #210433|0 |1 is obsolete| | Attachment #210434|0 |1 is obsolete| | Attachment #210435|0 |1 is obsolete| | Attachment #210436|0 |1 is obsolete| | Attachment #210437|0 |1 is obsolete| | Attachment #210438|0 |1 is obsolete| | Attachment #210439|0 |1 is obsolete| | Attachment #210440|0 |1 is obsolete| | Attachment #210441|0 |1 is obsolete| | Attachment #210442|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #29 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210922 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210922&action=edit Bug 43030: Add Koha::Exceptions::Object::NotImplemented Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #30 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210923 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210923&action=edit Bug 43030: Add Koha::Object->is_owned_by stub method Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #31 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210924 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210924&action=edit Bug 43030: Add Koha::Objects->owned_by stub method Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #32 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210925 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210925&action=edit Bug 43030: Add Koha::Patron(s) is_owned_by/owned_by (identity-based ownership) Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #33 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210926 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210926&action=edit Bug 43030: Replace Koha::BackgroundJobs::search_limited with is_owned_by/owned_by Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #34 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210927 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210927&action=edit Bug 43030: Add allow-owner support to x-koha-authorization Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #35 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210928 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210928&action=edit Bug 43030: Enforce/scope ownership in Koha::REST::Plugin::Objects Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #36 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210929 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210929&action=edit Bug 43030: Map Koha::Exceptions::Authorization::Unauthorized to 403 in unhandled_exception Koha::REST::Plugin::Objects (Task 7) throws this exception from inside objects.find_rs when koha.self_access is set and the caller doesn't own the resource. Controllers wrap their bodies in try/catch calling $c->unhandled_exception($_), which only recognised a small allowlist of exception types and rendered everything else as a generic 500. Add this type to that allowlist, matching the rendering Koha::REST::V1::Auth already uses for the same exception at the authentication gate. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #37 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210930 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210930&action=edit Bug 43030: Allow self-access to /patrons and /patrons/{patron_id} Adds allow-owner to the GET /patrons collection and GET/PUT /patrons/{patron_id} endpoints, so a staff member without list_borrowers/edit_borrowers can still view/edit their own patron record, scoped automatically to just themselves on the collection. update() now fetches via objects.find_rs (Koha::Patrons->new, not ->search_limited) so it goes through the new ownership check without also picking up the unrelated branch-visibility restriction that search_limited applies to get()/list() -- update never had that restriction and picking it up would silently break staff who hold edit_borrowers but not view_borrower_infos_from_any_libraries. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #38 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210931 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210931&action=edit Bug 43030: Allow self-access to /jobs and /jobs/{job_id} Replaces the catalogue:1 baseline permission with parameters:manage_background_jobs plus allow-owner, so a caller who lacks that permission can still see jobs they personally triggered. This also retires the last manual ownership check in Koha::REST::V1::BackgroundJobs::get in favour of the shared objects.find_rs enforcement from Task 7. Behavior change: a patron with zero permissions can now see their own background jobs (by id or in the collection) where they previously got 403 outright. They could already do so if they held the unrelated catalogue permission, so this narrows what permission is required without broadening what any non-privileged caller can ultimately see. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #39 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210932 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210932&action=edit Bug 43030: Point generic auth-permission tests away from /api/v1/patrons t/db_dependent/api/v1/{auth,auth_basic,oauth}.t each used GET /api/v1/patrons purely as a stand-in "some endpoint requiring a permission" to exercise generic 401/403/503 branches in authenticate_api_request. Now that this endpoint allows self-access, a permission-less patron is admitted (scoped to their own record) instead of rejected, so these generic checks now point at DELETE /api/v1/patrons/-1 instead, which still requires delete_borrowers unconditionally. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #40 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210933 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210933&action=edit Bug 43030: Add missing POD for Koha::Objects _get_objects_class/DESTROY Pre-existing gap surfaced by QA once this file was touched for owned_by(); unrelated to this bug's actual change but blocks QA on the whole file otherwise. Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 --- Comment #41 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210934 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210934&action=edit Bug 43030: (QA follow-up) Fix test plans, the 403 body, and do not allow owner edits of patrons * t/db_dependent/Koha/REST/Plugin/Objects.t and t/db_dependent/api/v1/patrons.t planned fewer tests than they run (bad plan): Objects.t 21 -> 22, and patrons.t list() 4 -> 5 and get() 5 -> 6. * The 403 for an authorization failure that is not about a permission, such as not owning the resource, returned "required_permissions": null. The property is now left out when there is no permission to report. * PUT /patrons/{patron_id} is no longer admitted through allow-owner. Any authenticated patron, staff or not, passes allow-owner, and nothing limits the fields they could then write: a patron could change their own category, library, expiry date and so on. Reading one's own record (GET /patrons and GET /patrons/{patron_id}) is unchanged. Editing one's own record can be added later, with an explicit list of fields allowed. The controller is back to the original lookup, as it no longer needs the ownership check. The self-access tests now also cover reading the record of another patron of the same library (403) and that a patron cannot edit their own record. To test: 1. Apply the patches 2. yarn build; restart_all 3. prove t/db_dependent/Koha/REST/Plugin/Objects.t \ t/db_dependent/api/v1/patrons.t xt/api.t => SUCCESS: Tests pass! 4. As a staff user without any borrowers permission, GET /api/v1/patrons/{patron_id} of another patron of your library => 403 {"error":"Authorization failure. You do not own this resource."} without required_permissions 5. GET /api/v1/patrons/{patron_id} of your own patron_id => 200 6. PUT /api/v1/patrons/{patron_id} of your own patron_id => 403 with required_permissions, nothing changed 7. Sign off :-D Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Signed Off --- Comment #42 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Thanks Arthur, thanks David. Arthur, the QA findings: * The bad plans are fixed (Objects.t 22, patrons.t list() 5 and get() 6). * The 403 for a resource that is not the caller's own no longer returns "required_permissions": null; the property is left out when there is no permission to report. * yarn api:bundle is part of yarn build, which is the documented step after changing the swagger files, so nothing to change there. Your question about a plain borrower: yes. Any authenticated patron, staff or not, passes allow-owner. Looking at that again, it is a problem for PUT /patrons/{patron_id}: nothing limits the fields they could write, so a patron could change their own category, library or expiry date. So PUT is no longer admitted through allow-owner. Reading one's own record (GET /patrons and GET /patrons/{patron_id}) is unchanged, and editing one's own record can come later with an explicit list of allowed fields. The checkouts and holds routes under /patrons/{patron_id} are not covered; the series covers /patrons (read only) and /jobs, and the other routes are follow up work. The patches you signed off are unchanged: all of Arthur's sign-offs are kept on the first 12, and the fixes are in one new (QA follow-up) patch on top. The tests of the self-access routes now also cover reading the record of another patron (403) and that a patron cannot edit their own record. David, on "owner": you are right that it assumes one owner. Both implementations here are one-to-one (a patron record is owned by the patron it is, a background job by the patron who enqueued it), but guarantors and guarantees, a suggestion that belongs to both a patron and a librarian, or a list shared with other patrons are many-to-many. Since each class implements its own is_owned_by, a class can return true for several relationships, and owned_by can return the records of all of them. So the approach allows it, and I would not block this patchset on it. What I would like to discuss, for both of you, is how this relates to is_accessible. They are different today: is_accessible is used by to_api to redact fields, defaults to allow, and Koha::Patron implements it as library visibility (can_see_patron_infos), while is_owned_by admits a request or scopes a list, defaults to deny, and is a one column match. What I want in the end is a clear contract for developers about what their authorization methods should implement. Should this rather extend is_accessible, with a documented contract for who may see an object, who may read it and who may change it (and which fields)? Or stay separate and be documented clearly in Koha::Object? Either can be done as a follow-up, and the many-to-many cases fit either one. All patches are re-attached, rebased on current main. Setting back to Signed Off for another look. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43030 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Patch doesn't apply --- Comment #43 from Arthur Suzuki <arthur.suzuki@biblibre.com> --- tried to signoff the followup but patch doesn't apply -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org