Repository navigation
Description
Blocked by the FOCA 0.18.0 release (no release issue to link as a dependency).
Cloud Registry, the template for FOCA apps, has its own code for things that FOCA 0.18 now provides for all apps, moved there from this repo: the Gunicorn settings (elixir-cloud-aai/foca#458, elixir-cloud-aai/foca#463), the startup checks of the config (elixir-cloud-aai/foca#459, elixir-cloud-aai/foca#466), the public URL and typed custom config (elixir-cloud-aai/foca#460, elixir-cloud-aai/foca#465), and request-specific problem details, including those of validation errors (elixir-cloud-aai/foca#461, elixir-cloud-aai/foca#464). Keeping both copies means two implementations to maintain, and apps that copy Cloud Registry copy code they no longer need.
Upgrade to FOCA 0.18 (foca>=0.18.0,<0.19), use its features, and delete the copies here. Besides what was merged, FOCA has decided (in progress) to make group_mapping without claim_groups and a group claim with surrounding whitespace startup errors, to turn exceptions.validation_details on by default, to remove get_enforcer() (in favour of locked_enforcer()), and to use a Gunicorn keep-alive of 100 s (also in the foca-common chart); this issue follows the released behaviour.
What changes
Gunicorn settings
Dockerfile:CMD ["gunicorn", "--config", "python:foca.gunicorn_config", "cloud_registry.app:create_app()"](comment and module docstring ofcloud_registry/app.pyupdated).- Delete
cloud_registry/gunicorn_config.py,tests/test_gunicorn_config.pyand its entry indocs/reference.md; keep only the test that the image's command matches its health check (port), andtests/gunicorn_settings.pyas far astests/test_chart.pystill needs it (test_gunicorn_defaults,test_gunicorn_values, adapted to the chart's new keep-alive default). docs/configuration.md("Gunicorn") links to FOCA's settings ("Running in production" in FOCA's deployment docs) instead of listing its own; overrides viaGUNICORN_CMD_ARGSandcloudRegistry.gunicornare unchanged.gunicornstays a runtime dependency (the image runs it).
Startup checks (cloud_registry/app.py, cloud_registry/ga4gh/registry/permissions.py)
- Set
security.access_control.require_admin: trueincloud_registry/config.yaml(falseinconfig.dev.yaml); deletecheck_admin_groups(),AccessControlConfigandcustom.access_control(CustomConfig.access_control). - Replace
check_no_service_clients()withfoca.security.auth.require_no_service_clients(app.app)increate_app(). - Delete
warn_placeholder_service_info(),PLACEHOLDER_IDandPLACEHOLDER_ORGANIZATION; FOCA'scheck_service_info()warns oforg.example.cloud-registryandhttps://example.orgwithout configuration. - Keep the app's own checks (
server.max_content_lengthnot null,add_service_keys(),warn_invalid_urls(),warn_url_schemes()). - Chart (
deployment/templates/_helpers.tpl,cloud-registry.validate): readconfig.security.access_control.require_admininstead ofconfig.custom.access_control.require_admin(defaulttrue, as the base config), and fail with an upgrade hint ifconfig.custom.access_controlis still set, as for the other removedcustomkeys. The chart's checks ofclaim_groupsstay (they mirror FOCA's, now errors there too). tests/test_access_control.py: replaceget_enforcer()(imported fromfoca.security.access_control.enforcement, used once) withlocked_enforcer().cloud_registry/ga4gh/registry/permissions.pyitself has noget_enforcer()calls ondev; check again when this is implemented.
Public URL and typed custom config (cloud_registry/utils.py)
- Replace
custom.endpoints.service(url_prefix,external_host,external_port,api_path) with FOCA'sserver.public_url; deleteServiceConfigandEndpointsConfig.servicefromcloud_registry/service_models/custom_config.py. - Delete
get_public_url()and_format_host();server.pyusesfoca.utils.urls.get_public_url(path)for theLocationheader ofPOST /services. - Delete
get_custom_config(); callers (permissions.py,service.py) usefoca.get_custom_config(CustomConfig). - FOCA raises
RuntimeErroron the firstPOST /servicesifserver.public_urlis not set, socreate_app()refuses to start without it, as forserver.max_content_length(the base config leaves it unset;config.dev.yamlsetshttp://localhost:8080). - Chart:
hostNamesetsserver.public_urltohttps://<hostName>(instead ofcustom.endpoints.service); a new optional valuepublicUrl(camelCase, as Helm's conventions and the chart's other keys) overrides it, e.g., for a path prefix of a proxy, and is added tovalues.yaml,values.schema.jsonanddeployment/README.md. Rendering fails with an upgrade hint ifconfig.custom.endpoints.serviceis still set.
Problem details (cloud_registry/exceptions.py, cloud_registry/app.py)
- Set
exceptions.validation_details: trueincloud_registry/config.yaml(also explicit once it is FOCA's default;exceptions.max_detail_lengthkeeps FOCA's default of 500, asMAX_DETAIL_LENGTHhere). - Delete
validation_problem(),problem(),_response(),_mapped(),shorten_detail()andMAX_DETAIL_LENGTH, and increate_app()the handler registrations forBadRequestProblem/ExtraParameterProblem, the logger setting andVALIDATION_LOGGER. FOCA filters Connexion's request validation log records instead of raising its logger toCRITICAL, so response validation errors are still logged. Keep the mappingexceptions. - Callers use
foca.errors.exceptions.problem_response()andshorten_detail():server.py(InvalidService,DuplicateServicewithserviceId=...,DuplicateService.hidden()) andverification.py(_not_verified()). All pass werkzeug exceptions (subclasses ofBadRequestandConflict) and notype,title,statusordetailextension, whichproblem_response()rejects (ValueError); check that this still holds, and that every exception passed has an error status code and a description. tests/test_exceptions.pykeeps only the tests of the mapping;tests/test_app.pyusesget_config().exceptions.max_detail_lengthinstead ofMAX_DETAIL_LENGTH.
Breaking changes and upgrade notes
For the next release (0.5.0), in docs/upgrading.md and deployment/README.md ("Upgrades", "To app version 0.5.0"):
- Public URL:
custom.endpoints.serviceis removed; setserver.public_urlto the absolute URL of the app as clients see it, including any path prefix of a proxy (formerlyapi_path), e.g.,https://registry.example.org/instead ofurl_prefix: https,external_host: registry.example.org,external_port: 443. The app refuses to start without it, and FOCA rejects URLs with query or fragment. In the chart,hostNamekeeps working; setpublicUrlfor anything else instead ofconfig.custom.endpoints.service. - Admins required:
custom.access_control.require_adminmoves tosecurity.access_control.require_admin(defaulttruein the base config, as before);custom.access_controlis rejected. - Gunicorn: the image loads
foca.gunicorn_config;cloud_registry.gunicorn_configno longer exists. The settings are the same; custom commands that load the old module must load FOCA's. - Behaviour differences (no action needed, but noticeable):
- No warning any more if no group claim is set at all (
claim_groupsunset withoutgroup_mapping); FOCA only warns ofgroup_mappingwithoutclaim_groups(now an error). - FOCA's admin check also counts service clients mapped to
adminand configuredgrules (policies) granting it; the registry refuses service clients, so only the latter applies. - FOCA additionally warns of
contactUrlanddocumentationUrlin reserved example domains, and does not checkorganization.name("Example Organization"). - Log messages of the checks and of rejected requests are FOCA's (other wording and loggers).
- No warning any more if no group claim is set at all (
Acceptance criteria
- FOCA 0.18.0 is released, and the app depends on
foca>=0.18.0,<0.19(pyproject.toml; the image requirements follow viascripts/image_requirements.py). - The code, config keys, tests and docs listed above are deleted or replaced; no copies of FOCA's features remain (
grepfor the names above finds nothing outside the release history). - Tests pass at 100% coverage, including the startup refusal without
server.public_url, theLocationheader behind a path prefix, validation error details, andrequire_admin. - Chart tests cover
hostName,publicUrl,require_adminundersecurity.access_control, and the failures forconfig.custom.endpoints.serviceandconfig.custom.access_control;helm lintand the chart README check pass. - The docs describe
server.public_url,publicUrlandrequire_admin, and link to FOCA's docs for the Gunicorn settings and startup checks; the strict docs build passes. - The upgrade notes cover the breaking changes and behaviour differences above.
Activity
build: pin released FOCA 0.18.0
test: assert the complete image command