Skip to content

refactor!: use FOCA 0.18 features - #338

Merged
uniqueg merged 4 commits into
devfrom
refactor/foca-0.18
Oct 29, 2026
Merged

uniqueg merged 4 commits into
devfrom
refactor/foca-0.18

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Upgrades proTES to FOCA 0.18 and replaces proTES's own copies of features that FOCA now provides, as Cloud Registry did (elixir-cloud-aai/cloud-registry#261). This is the first child of #321 (the plugin engine). The plugin engine itself, the public URL and the backend lists are not part of this PR; they come in #332 to #335.

Closes #331

What changes

  • Dependency: foca>=0.18.0,<0.19; base image elixircloud/foca:0.18.0-py3.13, pinned by digest.
  • Admins: custom.access_control.require_admin moves to FOCA's security.access_control.require_admin (true in the base config, false in config.dev.yaml). The app refuses custom.access_control with a hint, and the chart refuses config.custom.access_control.require_admin with a hint.
  • Startup checks:
    • FOCA now checks for admin groups and for a group claim with group mappings (errors), and warns about placeholders in the service info. proTES's check_role_groups() and warn_placeholder_service_info() are deleted.
    • proTES keeps its own check that access control is enforced, and its warning when no group has the role user (check_user_groups()).
    • Service clients are refused by FOCA's require_no_service_clients(). FOCA's config validation already refuses a client_mapping that isn't for a configured service client.
  • Gunicorn: the image runs with --config python:foca.gunicorn_config, which has the same settings. pro_tes/gunicorn_config.py and its tests are deleted, and tests/test_image_command.py checks the image's command.
  • Typed custom config: foca.get_custom_config(CustomConfig) replaces pro_tes.utils.misc.get_custom_config().
  • Validation details: exceptions.validation_details: True is set explicitly. This is FOCA's new default.
  • Rules changed in the database:
    • In FOCA 0.18, each instance keeps the enforcer in memory. Rules changed in MongoDB directly apply only after a restart or mark_changed().
    • The tests call mark_changed() after such changes, and docs/operations.md tells operators to restart proTES.
  • Docs: docs/upgrading.md (Configuration, Authentication, Image), docs/configuration.md (Server), docs/access-control.md, docs/operations.md, docs/reference.md, chart README and values.yaml.

Breaking changes (for the release notes)

  • custom.access_control.require_admin → security.access_control.require_admin. The old key stops the app and fails chart rendering. The chart needs images built with FOCA 0.18.
  • The image loads foca.gunicorn_config (same settings). Custom commands that load pro_tes.gunicorn_config must change.
  • Requests rejected by the API's validation get the reason as detail (e.g., 'none' is not of type 'array' - 'executors') instead of The request is malformed.
  • Group mappings without claim_groups are now a FOCA startup error.
  • Rules changed in the database directly apply only after a restart.

Verification

Local, Python 3.13, FOCA 0.18.0 from PyPI:

  • coverage run -m pytest (mongomock, Helm 3.19 on PATH, so the chart tests ran too): 1123 passed, 1 skipped; coverage 100%.
  • Full suite against MongoDB 7.0 (own container on a free port, removed afterwards): 1121 passed, 1 skipped. This run was before the review fixes, which only add tests that don't need the database.
  • ruff check, ruff format --check, mypy, ast-grep scan and ast-grep test: clean.
  • mkdocs build --strict: clean.
  • pre-commit run --all-files: passed.
  • python -m build: passed.
  • Not run locally: the Compose smoke test, which needs the image built on FOCA 0.18. CI runs it.
  • Reviews: adversarial and quality reviewer subagents, then a second adversarial round.
    • No high findings.
    • Fixed medium findings: upgrade notes on subjects namespaced by issuer, a Markdown list that swallowed the next paragraph, the stale ast-grep note, a direct unit test of the model's refusal, and the chart now refusing all of custom.access_control.
    • Fixed low findings: restart after a rolling update from 0.17, the Deployment name in the restart command, and docstrings.

CI: all checks passed (Lint, Test on mongomock and MongoDB 7.0, Chart, Docs, Smoke test with the FOCA 0.18 image, Scan image, Release readiness, CodeQL, Read the Docs; gate CI passed).

Declined review findings

  • The chart refuses issuer maps (FOCA 0.18's per-issuer settings, e.g., namespace: ""). This is a new chart feature, not part of the upgrade. Cloud Registry declined it likewise. Follow-up: feat(chart): accept issuer settings #337. The upgrade notes say that the chart doesn't support issuer maps yet.
  • The tests match FOCA's log and error texts (placeholder warning, wrapped custom config error). This is deliberate: they pin FOCA's behaviour, which proTES now relies on. The model's own message is tested directly, too.
  • The restart advice is in both docs/upgrading.md and docs/operations.md. It is kept in both places: one is for the upgrade, the other for day-to-day operations.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Adopt FOCA 0.18 throughout proTES, replacing duplicated configuration, validation, startup, and server behavior while documenting the resulting migration requirements.

Enhancements:

  • Upgrade proTES to FOCA 0.18 and adopt FOCA-provided configuration validation, startup checks, typed custom configuration access, and container Gunicorn settings.
  • Move the admin requirement to security.access_control.require_admin and reject the removed custom.access_control configuration.
  • Document FOCA 0.18 configuration, subject namespacing, validation responses, and restart requirements for database rule changes.

Build:

  • Update the dependency and container base image to FOCA 0.18.

Deployment:

  • Update the Helm chart to validate the FOCA 0.18 security configuration and reject the removed access-control settings.

Documentation:

  • Refresh configuration, upgrade, operations, access-control, reference, and deployment documentation for FOCA 0.18 behavior and breaking changes.

Tests:

  • Update tests for FOCA 0.18 startup behavior, configuration validation, image commands, chart validation, and in-memory access-control rule changes.

Chores:

  • Remove proTES-owned Gunicorn configuration and custom configuration helper now provided by FOCA.

uniqueg and others added 3 commits October 28, 2026 21:33
Upgrade to FOCA 0.18 (foca>=0.18.0,<0.19, base image 0.18.0-py3.13)
and replace proTES's copies of what FOCA now provides, as Cloud
Registry did (elixir-cloud-aai/cloud-registry#261):

- require_admin moves from custom.access_control to FOCA's
  security.access_control.require_admin; the old key stops the app
  and the chart with a hint
- FOCA's startup checks replace the admin and group claim checks and
  the placeholder warning of the service info; proTES keeps its check
  of enforced access control and the warning without user groups
- service clients are refused by require_no_service_clients()
- the image runs Gunicorn with foca.gunicorn_config (same settings);
  pro_tes.gunicorn_config is gone
- foca.get_custom_config(CustomConfig) replaces proTES's own
- validation details are set explicitly (FOCA's new default)

Tests apply rules changed in the database directly with
mark_changed(), and the docs tell operators to restart proTES after
such changes (FOCA 0.18 caches the enforcer).

BREAKING CHANGE: custom.access_control.require_admin is now
security.access_control.require_admin; the image loads
foca.gunicorn_config; rejected requests get the validation reason as
detail.

Closes #331

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document subjects namespaced by issuer and the restart after a rolling
update, refuse all of custom.access_control in the chart, test the
model's refusal directly, and fix the ast-grep note and docstrings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Upgrades proTES to FOCA 0.18 and replaces duplicated configuration, security validation, Gunicorn, and custom-config functionality with FOCA-provided implementations, while updating application behavior, Helm validation, tests, and migration documentation for the resulting breaking changes.

Sequence diagram for FOCA 0.18 startup validation

sequenceDiagram
    participant Image as Container image
    participant Foca as FOCA
    participant App as proTES
    participant Config as Configuration

    Image->>Foca: load foca.gunicorn_config
    App->>Foca: Foca(config_file)
    Foca->>Config: validate security.access_control
    alt invalid configuration
        Config-->>Foca: raise validation error
        Foca-->>App: refuse startup
    else valid configuration
        Foca-->>App: initialized application
        App->>Foca: require_no_service_clients(app)
        App->>App: check_task_ownership()
        App->>App: check_user_groups()
        App-->>Image: serve application
    end
Loading

Flow diagram for FOCA 0.18 access-control rule changes

flowchart LR
    Operator[Operator changes rules in MongoDB] --> Mongo[(MongoDB policy_rules)]
    Mongo --> Cached[In-memory FOCA enforcer]
    Cached -->|unchanged until restart| API[proTES API]
    Operator -->|kubectl rollout restart| Restart[Restart all proTES instances]
    Restart --> Reload[Reload rules into memory]
    Reload --> API
Loading

File-Level Changes

Change Details Files
Upgrade the FOCA dependency and container base image to 0.18, adopting its configuration, validation, security, and Gunicorn integrations.
  • Pin FOCA 0.18 in Python dependencies and the Docker base image.
  • Load FOCA’s container Gunicorn configuration and remove the proTES-owned configuration module.
  • Enable explicit validation details and use FOCA’s typed custom-configuration accessor.
  • Update static analysis rules and image-command tests for the new integration.
pyproject.toml
Dockerfile
.ast-grep/rules/foca-config-attribute.yml
pro_tes/gunicorn_config.py
pro_tes/utils/misc.py
tests/test_image_command.py
tests/gunicorn_settings.py
tests/utils/test_misc.py
Move administrator configuration and startup validation to FOCA while retaining proTES-specific access-control checks.
  • Move require-admin configuration from custom.access_control to security.access_control and reject the removed key in application and chart configuration.
  • Delegate admin-group, group-claim, placeholder service-info, and service-client validation to FOCA.
  • Retain checks for enforced access control, user-role groups, backend credentials, and task ownership.
  • Update startup, security, configuration-model, chart, and application tests for FOCA’s errors and warnings.
pro_tes/config.yaml
pro_tes/config_models.py
pro_tes/app.py
pro_tes/security.py
deployment/templates/_helpers.tpl
deployment/values.yaml
config.dev.yaml
tests/test_security.py
tests/test_config_examples.py
tests/test_chart.py
tests/test_app.py
Adapt proTES runtime configuration access and tests to FOCA’s typed custom configuration API.
  • Replace the deleted proTES configuration helper with foca.get_custom_config(CustomConfig).
  • Update backend discovery, task execution, progress tracking, middleware, and related tests to use the typed accessor.
pro_tes/ga4gh/tes/backends.py
pro_tes/ga4gh/tes/discovery.py
pro_tes/ga4gh/tes/task_runs.py
pro_tes/tasks/track_task_progress.py
tests/ga4gh/tes/conftest.py
tests/ga4gh/tes/test_backends.py
tests/ga4gh/tes/test_discovery.py
tests/ga4gh/tes/test_server.py
tests/plugins/middlewares/task_distribution/test_random.py
tests/tasks/test_track_task_progress.py
Account for FOCA 0.18’s in-memory access-control rule cache and changed user identity semantics.
  • Mark the Casbin adapter changed in tests after direct MongoDB rule updates.
  • Document restart requirements for direct database rule changes and rolling upgrades.
  • Document issuer-namespaced subjects and migration implications for stored owners and roles.
tests/ga4gh/tes/test_access_control.py
docs/operations.md
docs/upgrading.md
Revise deployment and reference documentation for the FOCA 0.18 migration and breaking changes.
  • Update access-control, server, configuration, image, chart, and upgrade guidance to use FOCA-owned settings and behavior.
  • Remove the deleted Gunicorn module from generated references and describe the new image command and operational requirements.
docs/access-control.md
docs/configuration.md
docs/reference.md
docs/upgrading.md
deployment/README.md
deployment/values.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#331 Upgrade proTES to FOCA 0.18, including the dependency constraint, pinned base image, and applicable FOCA 0.18 behavior changes. ✅
#331 Replace proTES-owned copies of functionality now provided by FOCA, move the admin setting, and refuse the removed configuration key with a helpful hint in the app and Helm chart. ✅
#331 Update configuration, operational, reference, and upgrade documentation and tests for the FOCA 0.18 migration and its breaking changes. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35486261 | 📁 Comparing 72fc707 against latest (5f8b35c)

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5f8b35c) to head (72fc707).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #338   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        28    -1     
  Lines         2470      2420   -50     
=========================================
- Hits          2470      2420   -50     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 29, 2026 00:04

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deployment/templates/_helpers.tpl" line_range="160" />
<code_context>
-{{- end -}}
 {{- if and (eq $requireAdmin "true") (not (has "admin" (values $mapping))) -}}
-{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.custom.access_control.require_admin to false" -}}
+{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.security.access_control.require_admin to false" -}}
 {{- end -}}
 {{- end -}}
</code_context>
<issue_to_address>
**Helm rejects policy-granted admin**

When `require_admin` is true, no group mapping grants `admin`, and a configured policy grants the admin role, `deployment/templates/_helpers.tpl` checks only whether `group_mapping` contains `admin`, so Helm fails rendering even though FOCA accepts the policy and satisfies `require_admin`; the deployment cannot be installed through Helm.

Update the chart check to accept an admin role granted by a configured access-control policy.
</issue_to_address>

### Comment 2
<location path="docs/upgrading.md" line_range="50" />
<code_context>
+  `issuers: [{issuer: "https://login.example.org/oidc/", namespace: ""},
+  "https://other.example.org/"]`; not supported by the Helm chart yet,
+  which accepts issuers as URLs only, see [#337](https://github.com/elixir-cloud-aai/proTES/issues/337)), or rewrite the stored subjects to the
+  namespaced form (see FOCA's [migration
+  guide](https://foca.readthedocs.io/en/latest/migration-0.18/#subjects-of-several-issuers)).
+  Deployments with a single trusted issuer are not affected.
</code_context>
<issue_to_address>
**Owner metadata stays ambiguous**

When a deployment trusts several issuers and chooses the rewrite route rather than configuring an issuer with `namespace: ""`, `tasks.user_id` remains the old bare subject if operators rewrite only the stored access-control subjects; the new namespaced identity then does not match the owner recorded on existing task rows, so owner lookups using the documented `user_id` query miss or misidentify those tasks.

Include updating existing `tasks.user_id` values in the namespacing migration instructions, or state explicitly that the field remains historical and must be queried by its old value.
</issue_to_address>

### Comment 3
<location path="pyproject.toml" line_range="120" />
<code_context>
     # FOCA minors are bumped by hand, together with the base image in the
     # `Dockerfile` (`.github/dependabot.yml`).
-    "foca>=0.17.0,<0.18",
+    "foca>=0.18.0,<0.19",
     "geopy>=2.2.0,<3",
     "gunicorn>=26.2.0,<27",
</code_context>
<issue_to_address>
**Owners temporarily lose task access**

When a rolling upgrade has both 0.17 and 0.18 replicas serving requests, an older replica can create a task and its owner rule after a FOCA 0.18 replica has cached the rules. The 0.18 replica then rejects that owner’s requests for the task until the post-rollout restart refreshes its cache.

Drain or stop old replicas from creating tasks before 0.18 replicas begin serving, or otherwise prevent requests from reaching stale 0.18 caches until the post-upgrade refresh.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and with multiple trusted issuers, FOCA now namespaces subjects, so existing task owners and permission grants stored with bare subjects may stop matching; tasks or grants created during the rollout can also remain in the new format. Reverting restores the old interpretation for old records, but may not restore access to records written with namespaced subjects without a data repair.

Blocking findings: deployment/templates/_helpers.tpl:160, docs/upgrading.md:50, pyproject.toml:120


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread docs/upgrading.md Resolved
Comment thread pyproject.toml Resolved
@uniqueg

uniqueg commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deployment/templates/_helpers.tpl" line_range="111-116" />
<code_context>
 {{- if hasKey $securityAccessControl "group_mapping" -}}
 {{- $mapping = get $securityAccessControl "group_mapping" -}}
 {{- end -}}
+{{- if hasKey $securityAccessControl "require_admin" -}}
+{{- $requireAdmin = include "protes.parseBool" (dict
+  "value" (get $securityAccessControl "require_admin")
+  "key" "config.security.access_control.require_admin"
+) -}}
+{{- end -}}
 {{- if hasKey $securityAccessControl "claim_groups" -}}
 {{- $claimGroups = get $securityAccessControl "claim_groups" -}}
</code_context>
<issue_to_address>
**Policy-granted admins are rejected**

When an admin role is granted through `security.access_control.policies` without a group mapping while `require_admin` remains true, `protes.checkSecurity` checks only `$mapping` for `admin`, so Helm fails during rendering even though FOCA accepts the policy-based grant; the deployment cannot start.

Include roles granted by `security.access_control.policies` when validating that `require_admin` is satisfied.

Also at `deployment/templates/_helpers.tpl:160`.
</issue_to_address>

### Comment 2
<location path="pyproject.toml" line_range="120" />
<code_context>
     # FOCA minors are bumped by hand, together with the base image in the
     # `Dockerfile` (`.github/dependabot.yml`).
-    "foca>=0.17.0,<0.18",
+    "foca>=0.18.0,<0.19",
     "geopy>=2.2.0,<3",
     "gunicorn>=26.2.0,<27",
</code_context>
<issue_to_address>
**Owner queries miss namespaced users**

When a multi-issuer deployment chooses the documented option to rewrite stored subjects to the namespaced form rather than configuring an issuer with an empty namespace, the task-owner lookup and repair examples in `docs/operations.md` use a bare `<sub>`, so operators following them cannot find newly created tasks by their stored `user_id` or grant their owner roles to the namespaced subject. The affected tasks remain inaccessible to the intended user.

Update the task-owner lookup and repair examples to use the issuer-namespaced subject, and explain the empty-namespace alternative.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and FOCA 0.18 keeps access-control rules in memory, so a rule removed directly from the database may continue granting access until every proTES instance is restarted; any access during that window cannot be undone by reverting. In deployments with multiple trusted issuers, the new issuer-prefixed subjects also stop matching existing task owners and permissions unless those stored subjects are migrated or configured for compatibility.

Blocking findings: deployment/templates/_helpers.tpl:116, pyproject.toml:120


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread pyproject.toml Resolved
Rewrite user_id along with the owner roles, show owners in their
namespaced form in the operations examples, and say how to avoid the
window of rolling updates from 0.17.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 183dd5b into dev Oct 29, 2026
19 checks passed
@uniqueg
uniqueg deleted the refactor/foca-0.18 branch October 29, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor!: use FOCA 0.18 features

1 participant