Repository navigation
Conversation
Since subjects are always namespaced by issuer (#773), rules naming users without the namespace of a trusted issuer apply to nobody. FOCA refused them only in configured rules; the permissions API and the endpoints for managing roles still stored them, so clients written for 0.22 granted roles that never applied. With the models that FOCA ships and an issuer that namespaces its subjects, the permissions API now refuses such values (code unknown-user, at the value's pointer, without the value), and grant_role() and add_owner() raise ValueError (400 at the endpoints), as for groups and clients to which roles don't apply. Stored roles of such users don't count as owners and can still be revoked or deleted. The checks of packaged models move to the new module foca.security.access_control.users, with unknown_user_matcher(); the tokens of the packaged models are read once. Closes #826 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Reviewer's GuideImplementationIntroduce
Reject role grants to users that no trusted issuer has, so stale roles cannot be granted or count as applicable owners while remaining revocable.
Reject permission-rule values naming unknown users with an
DocumentationDocument which role subjects and policy-rule users are rejected, and explain the migration behavior and new
Expose
TestsTest rejection and acceptance of permission rules, custom-model behavior, and deletion of previously stored unknown-user rules.
Test role rejection for unknown users, their owner-check behavior and revocation, and the custom-model exception.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #827 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 76 77 +1
Lines 10708 10739 +31
=========================================
+ Hits 10708 10739 +31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Deferred out of 0.23.0 after the pre-release review (#826 moved to v0.24.0). Two medium findings need a design decision first:
Option for 0.24.0: refuse only new grants of bare users and keep stored bare owners counting as before. 0.23.0 documents instead that these APIs still accept bare users, which apply to nobody (#823). |
Summary
Found in the pre-release review of 0.23.0. Since #773, users are named in rules as
user:<namespace>|<subject>also with a single trusted issuer. FOCA refused configured rules naming other users (with the models it ships) but the APIs still stored them, so clients written for 0.22 granted roles that apply to nobody (e.g.,PUT /pets/1/permissions/users/bobreturned200).With the models that FOCA ships and at least one issuer that namespaces its subjects (the same conditions as the startup check of configured rules;
namespace: ""keeps bare users valid):POST/PUT /permissions): values naming such users are invalid fields with the new codeunknown-user, at the value's pointer (e.g.,#/rule/v0), without the value.grant_role()/add_owner()(and so the endpoints for managing roles,400):ValueError, as for groups and clients to which roles don't apply (_check_applicable()). Stored roles of such users therefore don't count as owners (so they don't blockLastOwnerchecks) and can still be revoked; stored rules can still be deleted via the permissions API._is_packaged_model,_model_tokens) moves fromregister_access_controlto the new modulefoca.security.access_control.users, withunknown_user_matcher(); the packaged models' tokens are read once (lru_cache).Docs:
docs/access-control.md(grant_role(), rule values),docs/problems/invalid-request.md(codeunknown-user),docs/migration-0.23.md(section "Subjects are always namespaced by issuer"),docs/reference.md(unknown_user_matcher).Closes #826
Verification
tests/security/access_control/test_ownership.py::TestNamespacedBySingleIssuer::test_users_without_namespace*andtests/security/access_control/test_access_control_server.py::TestUsersWithoutNamespacefailed before the fix (DID NOT RAISE), pass after.coverage run -m pytest: 5642 passed, 2 skipped;coverage report: 100%.ruff check .,ruff format --check .,mypy(192 files): pass.ast-grep scan --error=flask-import,semgrep scan --config .semgrep --error: no findings.mkdocs build --strict: pass.tests/integration_gateway_tests.py(Docker compose stack); CI runs it.Review
The adversarial-reviewer and quality-reviewer subagents were not run before this push (the agent that wrote this PR couldn't start subagents); they are to be run on this branch before the PR is marked ready.
Declined review findings
None.
Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary by Sourcery
Prevent permissions and role APIs from accepting users that no trusted issuer can identify.
Bug Fixes:
Enhancements:
Documentation:
Tests: