Skip to content

feat: add startup checks of the config #459

Closed

Description

@uniqueg

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 to admin (ADMIN_ROLE);
    • warns if no group is mapped to admin and 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's custom.access_control.require_admin, default True there);
    • warns if group_mapping is set but claim_groups is not, or if claim_groups has surrounding whitespace (cloud-registry refuses to start in both cases; FOCA warns, as that keeps existing apps running);
    • warns if group_mapping is set but keep_group_subjects is not, as roles granted to groups then don't apply (and FOCA's ownership helpers refuse to grant them).
  • Service clients: a public check foca.security.auth.require_no_service_clients() (raises RuntimeError if security.auth.service_clients or on_behalf_of_header is 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, if service_info is set): warns, naming the fields, if service.id is in a reserved example domain (reverse DNS starting with example., com.example, net.example or org.example; RFC 2606), or the host of organization.url, contactUrl or documentationUrl is one (example.com, example.net, example.org, *.example, and their subdomains; for mailto: URLs the address's domain). No app-specific placeholders, so this covers cloud-registry's org.example.cloud-registry and https://example.org without 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 in docs/deployment.md; the option in templates/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: true refuses to start without an admin group.
  • require_no_service_clients() is public and documented.
  • Tests cover all branches at 100% (with caplog for each message).
  • The docs and templates/config.yaml describe the option and the checks; the strict docs build passes.
  • docs/migration-0.18.md mentions the new warnings and the new option.

Activity

  1. added this to the v0.18.0 milestone on Oct 24, 2026
  2. added
    priority: medium
    status: triage
    type: feature
    workload: hours
    status: in progress
    and removed
    status: triage
    on Oct 24, 2026
  3. removed
    status: in progress
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: featureworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions