Repository navigation
Description
Some misconfigurations leave a FOCA app running, but not as intended, and nothing tells the deployer: no group is mapped to the role admin, so nobody can act as admin; groups are mapped to roles, but no group claim is set (or it has surrounding whitespace, and FOCA looks it up as written), so no mapping ever applies; roles on resources granted to groups don't apply, as keep_group_subjects is not set; or the service info still has the placeholders of a template. FOCA already warns about some settings at startup (e.g., keep_group_subjects without group_mapping, several issuers, verify_audience: false). elixir-cloud-aai/cloud-registry, the template for FOCA apps, checks the others itself: check_admin_groups() and check_no_service_clients() in cloud_registry/ga4gh/registry/permissions.py, and warn_placeholder_service_info() in cloud_registry/app.py, called from its create_app() (tests in tests/test_access_control.py and tests/test_app.py).
Move the generic parts into FOCA, run by Foca.create_app():
- Access control (in
foca.security.access_control.register_access_control, next to the existing warnings; only if access control is enabled):- logs (
INFO) the groups mapped toadmin(ADMIN_ROLE); - warns if no group is mapped to
adminand no configured policy rule (policies) grants it, saying that roles granted via stored rules still apply; - new option
security.access_control.require_admin: bool = False: if true, the app refuses to start (ValueError) instead of warning (cloud-registry'scustom.access_control.require_admin, defaultTruethere); - warns if
group_mappingis set butclaim_groupsis not, or ifclaim_groupshas surrounding whitespace (cloud-registry refuses to start in both cases; FOCA warns, as that keeps existing apps running); - warns if
group_mappingis set butkeep_group_subjectsis not, as roles granted to groups then don't apply (and FOCA's ownership helpers refuse to grant them).
- logs (
- Service clients: a public check
foca.security.auth.require_no_service_clients()(raisesRuntimeErrorifsecurity.auth.service_clientsoron_behalf_of_headeris set), for apps whose endpoints don't support them; not run by FOCA, as service clients are a FOCA feature. - Placeholder service info (in
foca.api.service_info, ifservice_infois set): warns, naming the fields, ifservice.idis in a reserved example domain (reverse DNS starting withexample.,com.example,net.exampleororg.example; RFC 2606), or the host oforganization.url,contactUrlordocumentationUrlis one (example.com,example.net,example.org,*.example, and their subdomains; formailto:URLs the address's domain). No app-specific placeholders, so this covers cloud-registry'sorg.example.cloud-registryandhttps://example.orgwithout configuration. - Backwards compatible: only new log messages; the only new error is opt-in (
require_admin). Messages name the setting to change, as the existing ones do, and contain no claim values other than configured group names. - Docs:
docs/configuration/access-control.md(admin groups,require_admin, the warnings),docs/configuration/service-info.md(placeholders),docs/authentication.md(require_no_service_clients()), and a list of startup checks indocs/deployment.md; the option intemplates/config.yaml.
Follow-up in cloud-registry (separate issue there): set security.access_control.require_admin: true, call require_no_service_clients(), and delete check_admin_groups(), check_no_service_clients(), warn_placeholder_service_info(), the placeholder constants and custom.access_control, keeping its stricter errors only if still wanted.
Open question for the maintainer: should group_mapping without claim_groups, and a group claim with surrounding whitespace, be errors (as in cloud-registry) rather than warnings, e.g., from FOCA 1.0? This issue keeps them warnings.
Acceptance criteria
-
Foca.create_app()runs the checks above;require_admin: truerefuses to start without an admin group. -
require_no_service_clients()is public and documented. - Tests cover all branches at 100% (with
caplogfor each message). - The docs and
templates/config.yamldescribe the option and the checks; the strict docs build passes. -
docs/migration-0.18.mdmentions the new warnings and the new option.
Activity