Repository navigation
fix: allow opt-in roles without group mapping - #533
Conversation
An app can make a role opt-in in its base config before its deployments map groups to it: AccessControlConfig no longer refuses opt-in roles that no group is mapped to. Nobody can opt in to them, and Foca.create_app() warns of them on startup (check_opt_in_roles()). Configured rules that grant opt-in roles are still refused. Closes #530 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Opt-in roles that no group is mapped to are no longer checked via the mapping: refuse resource roles and subject prefixes in opt_in_roles directly. The startup warning notes that service clients mapped to the roles always have them. Add tests for requests asking for unmapped roles and for the permissions API, and update the docs of the startup checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tell deployers to check the startup warning of unmapped opt-in roles, as a misspelled role is only warned of. Tidy the paragraph, a validator docstring and a test string. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR lets applications declare opt-in roles in a base configuration without requiring immediate group mappings. Validation still blocks policy grants, resource roles, and subject-prefixed roles that could bypass opt-in, while startup logging warns when users cannot yet select configured roles; documentation and tests cover the new behavior. Sequence diagram for unmapped opt-in role startup checksequenceDiagram
participant App as Foca.create_app()
participant Check as check_opt_in_roles()
participant Config as AccessControlConfig
participant Logger as Logger
App->>Check: check_opt_in_roles(access_control_config, cors_config)
Check->>Config: Read opt_in_roles and group_mapping
Check->>Logger: Log opt-in roles
alt opt-in role has no mapped group
Check->>Logger: warning: no user can opt in until groups are mapped
end
alt CORS is enabled
Check->>Logger: Warn if opt_in_header is not allowed
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
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 #533 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 55 55
Lines 6667 6667
=========================================
Hits 6667 6667
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:
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the opt-in role is misspelled while a group is mapped to the intended role, the intended role can apply without being requested; the startup warning is the signal to catch that mismatch. Reverting restores the prior configuration behavior, but it cannot undo access or data exposure that occurred before the revert.
Summary
Opt-in roles (
security.access_control.opt_in_roles) no longer need a group mapping to them. This lets an app make a role opt-in in its base config (e.g.,opt_in_roles: [admin]for an admin mode) and leavegroup_mappingto its deployments. Until groups are mapped to such a role, no user can opt in to it.Foca.create_app()warns of these roles on startup.Closes #530
validate_opt_in_rolesdrops the check that opt-in roles must be values ofgroup_mapping.policies) that grant opt-in roles are still refused, also for unmapped roles.validate_mapped_rolesnow checksopt_in_rolesdirectly: noresource_roles, and nouser:,group:orclient:prefixes. These checks used to apply indirectly, through the mapping.check_opt_in_roles()warns of opt-in roles that no group is mapped to. The warning notes that service clients mapped to them always have them.docs/access-control.mdcovers the base-config use case and the restrictions. It asks deployers to check the warning, as a misspelled opt-in role is now only warned of.docs/configuration/access-control.mdanddocs/deployment.mdlist the new warning.Motivation: elixir-cloud-aai/cloud-registry#240, whose Docker Compose and test configs have no admin mapping.
Verification
coverage run -m pyteston MongoDB 7.0.34: 2967 passed, coverage 100%.tests/plugins/test_plugin_backends.py::test_cache(30.00003 vs 30), passed 3 times on rerun.tests/test_foca.pyandtests/models/test_config.pywere rerun: 280 passed.ruff check,ruff format --check,mypy,ast-grep scan,semgrep scan --config .semgrep --errorandmkdocs build --strict: clean.group:opt-in role would have applied without opt-in.group_mapping"; both fixed.Declined review findings
opt_in_rolesused to stop the app and is now only warned of. A strict option, likerequire_admin, could turn the warning into an error once the mapping is final. Declined for now, as it would add a config option before the release. The docs now tell deployers to check the warning. Apps can also enforce the mapping themselves, asrequire_admindoes for admins.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Allow opt-in roles without group mappings while preserving safeguards against unintended role application.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: