Skip to content

refactor!: list TES backends with FOCA - #340

Merged
uniqueg merged 6 commits into
devfrom
refactor/backend-list
Oct 29, 2026
Merged

uniqueg merged 6 commits into
devfrom
refactor/backend-list

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #321. TES backends come from one place, custom.tes.backends, a typed backend list of FOCA 0.18 (foca.plugins.backends), instead of custom.tes.service_list plus one registry in custom.tes.discovery. proTES no longer has registry discovery or address checks of its own.

  • Backend list (breaking): entries are TES instances (type: ga4gh-tes: url, url_schemes, id, auth, basic, labels, location) and service registries (type: ga4gh-service-registry), in order. custom.tes.service_list and custom.tes.discovery stop the app with a hint that gives the mapping: the service_list entries become ga4gh-tes entries, in order, followed by the registry as one ga4gh-service-registry entry.
  • Candidates and lookup: pro_tes.ga4gh.tes.backends.get_backends() returns BackendList(...).expand(), and the middlewares get it as before. get_backend(url) uses find() and returns the backend together with its entry (entry_for()). The entry supplies the credentials (auth, basic), which proTES still adds itself.
  • Discovered backends: before each request, FOCA's check_public_host() checks the host, unless the registry entry sets allow_private_addresses. Failures map to BackendAddressNotAllowed. Redirects are not followed.
  • Public URL: proTES refuses to start if registries are configured but server.public_url is not set. This keeps proTES from discovering itself. check_backends() also runs in the Celery worker, with the worker's config.
  • Service info: backends now comes from describe(). Each backend is an object with id, url, source, group and labels; before, it was a URL.
  • Kept: custom.tes.client_credentials and custom.tes.timeout. custom.tes.url_schemes now applies to the identity provider only; backends and registries set url_schemes per entry.
  • Deleted: pro_tes/ga4gh/tes/discovery.py (discovery, check_public_host, is_public_address), its 982-line test module, and the exceptions HostNotResolved and RegistryError. A smaller tests/ga4gh/tes/test_backend_list.py tests how proTES uses FOCA's list, with a fake registry and fake DNS.
  • Chart:
    • New value tes.backends, with camelCase keys (urlSchemes, refreshInterval, maxStale, allowPrivateAddresses, registryAllowPrivateAddresses, basic.usernameEnv/passwordEnv; the keys of labels are kept as given), rendered into custom.tes.backends. values.schema.json checks it with one strict schema per entry type.
    • Rendering fails on config.custom.tes.service_list and discovery, on backends set both in tes.backends and in config.custom.tes.backends, and on registries when the app has no public URL.
    • New value publicUrl. server.public_url is set to publicUrl, or else to https://<hostName>/, the same way Cloud Registry's chart does it. Unlike Cloud Registry's chart, it is left unset when hostName is empty, since proTES does not require hostName.
    • The app also refuses to start when configured TES instances are at or below the public URL. FOCA never uses them, so without this check they would be dropped silently. This matters when the chart's hostName is shared with other apps.
    • deployment/ci/optional-values.yaml now lists backends, so helm lint covers them.
  • Compose and smoke test: tests/smoke/config.yaml uses the new list, with url_schemes: [http] on the entry. docker-compose.yaml needed no change (it mounts config.dev.yaml, whose commented example is updated).
  • Docs: configuration (TES instances, discovery as registry entries, public URL), access control (credentials per entry), middlewares, operations, README, the chart README and values, and Upgrading (the mapping, with an example; url_schemes per entry; max_stale; registry_allow_private_addresses; the service info shape; the chart values). Examples in the docs and the chart are validated; the chart examples are now rendered with Helm and then validated.

Breaking changes (release notes)

  • custom.tes.service_list and custom.tes.discovery are replaced by custom.tes.backends; the old keys stop the app with the mapping. In the chart, use tes.backends (camelCase keys) instead of config.custom.tes.service_list/discovery.
  • Registries need server.public_url (the chart sets it from hostName or publicUrl).
  • custom.tes.url_schemes applies to the identity provider only; entries with http URLs need url_schemes: [https, http].
  • A registry whose last good read is older than max_stale seconds (default 3600) yields no backends. Earlier versions kept the last list indefinitely.
  • The service info lists backends as objects instead of URLs.

Verification

  • coverage run -m pytest: 1079 passed, 1 skipped, 100% coverage (mongomock).
  • Same suite against MongoDB 7.0 (MONGODB_TEST_URI): passed.
  • pre-commit run --all-files (ruff, mypy, ast-grep, semgrep, ...): passed.
  • mkdocs build --strict: passed.
  • helm lint deployment -f deployment/ci/test-values.yaml -f deployment/ci/optional-values.yaml: passed; chart tests (tests/test_chart.py) passed.
  • CI: all checks passed (Lint, Test with mongomock and MongoDB 7.0, Chart, Docs, Smoke test, Scan image, Release readiness, CodeQL, codecov, CI passed).

Declined review findings

  • Adversarial, medium: DNS rebinding of discovered backends. The per-request check_public_host() resolves separately from the request, so a rebinding host can pass it. This is not new (the deleted discovery had the same gap, and the docs name it). Fixing it means sending requests through FOCA's GuardedClient, which belongs with refactor!: process tasks with FOCA plugins #333 (TesClient sending the forward phase's requests). Tracked in fix: check connections to discovered backends #339.
  • Quality, low: unreachable auth branch in TesClient._request_params. Kept deliberately: unknown credential names fail closed instead of being sent without credentials (tested in test_client_auth_unknown). In refactor!: process tasks with FOCA plugins #333, plugins choose credentials by name, so the branch becomes reachable.
  • Quality, low: the mapping hint is written in three places (app, chart, Upgrading). The app and the chart cannot share text; the wording is aligned.
  • Sourcery, medium: the service info exposes backend metadata. The issue decided that describe() feeds the service info. URLs were already public; the change adds the admin-set ids and labels. The docs say the service info is public and recommend an explicit id for internal registries, and runtime_fields: null hides the field.
  • Quality, low: a BackendList is built per call. Kept; it costs one validation of the entries. The docstring now says so.

Open questions

None.

Closes #332

🤖 Generated with Claude Code

uniqueg and others added 5 commits October 29, 2026 03:27
Replace custom.tes.service_list and custom.tes.discovery with
custom.tes.backends, a typed backend list of FOCA 0.18
(foca.plugins.backends): TES instances (ga4gh-tes) and service
registries (ga4gh-service-registry), in order. The old keys stop the
app with a hint of the mapping.

- Candidates come from BackendList.expand(); get_backend() uses
  find() and returns the entry with the credentials
- discovered backends are checked with FOCA's check_public_host()
- registries need server.public_url (checked on startup)
- the service info lists the backends from describe()
- pro_tes/ga4gh/tes/discovery.py and its tests are deleted

BREAKING CHANGE: custom.tes.service_list and custom.tes.discovery
are replaced by custom.tes.backends; custom.tes.url_schemes applies
to the identity provider only; the service info lists backends as
objects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
List the TES backends in the chart value tes.backends, with the
chart's camelCase keys, rendered into custom.tes.backends; rendering
fails on config.custom.tes.service_list and discovery, on backends in
both places, and on registries without a public URL. The chart sets
server.public_url to publicUrl or https://<hostName>/, as Cloud
Registry's chart does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document custom.tes.backends and registries as entries of it, the
public URL that registries need, and the mapping of service_list and
discovery in Upgrading; validate the chart examples by rendering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- refuse configured backends at or below server.public_url, which
  FOCA never uses, instead of dropping them silently
- check_backends keeps a public URL given without conf
- test that the worker refuses registries without a public URL
- chart: config.server.public_url takes precedence in the registry
  check (also null), registries in config.custom.tes.backends are
  checked, and config.custom.tes must be a map
- docs: registry labels, ids in the public service info, duplicate
  URLs, the public URL exclusion; rewrap edited text

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Advise serving proTES under a host or path prefix of its own when a
configured backend is below its public URL, clarify the chart error
for backends set in both places, add unit tests of the public URL
check, and rewrap edited docs.

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

sourcery-ai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This breaking refactor centralizes configured and discovered TES backends in FOCA's typed custom.tes.backends list, delegates registry expansion and caching to FOCA, and adapts proTES clients, middleware, service metadata, startup safety checks, Helm values, documentation, and tests around the new model. Review especially the entry-to-client credential mapping, public-URL self-discovery protections, request-time address validation, chart key translation, and the intentional removal of the legacy discovery implementation.

Sequence diagram for registry-backed TES request authentication

sequenceDiagram
    participant Middleware
    participant BackendList as FOCA BackendList
    participant Registry as Service Registry
    participant Client as TesClient
    participant DNS as Host validation
    participant TES as TES backend

    Middleware->>BackendList: expand()
    BackendList->>Registry: read verified services
    Registry-->>BackendList: verified TES entries
    BackendList-->>Middleware: ordered backends
    Middleware->>Client: create_client(url)
    Client->>BackendList: find(url)
    BackendList-->>Client: backend and entry_for()
    Client->>DNS: check_public_host()
    DNS-->>Client: allowed host
    Client->>TES: TES request with entry credentials
    TES-->>Client: response
Loading

Entity relationship diagram for backend entry sources

erDiagram
    BACKEND_LIST ||--o{ TES_ENTRY : contains
    BACKEND_LIST ||--o{ REGISTRY_ENTRY : contains
    REGISTRY_ENTRY ||--o{ DISCOVERED_BACKEND : expands_to
    TES_ENTRY {
        string id
        string url
        string auth
    }
    REGISTRY_ENTRY {
        string id
        string url
        string auth
        int max_stale
    }
    DISCOVERED_BACKEND {
        string id
        string url
        string source
        string group
    }
Loading

Flow diagram for backend safety validation

flowchart TD
    Start[Application or Celery worker starts] --> Check["check_backends()"]
    Check --> Registry{Registry entry configured?}
    Registry -->|yes| PublicURL{server.public_url set?}
    PublicURL -->|no| FailRegistry[Refuse startup]
    PublicURL -->|yes| Configured[Validate configured TES entries]
    Registry -->|no| Configured
    Configured --> Self{Configured TES at or below public URL?}
    Self -->|yes| FailSelf[Refuse startup]
    Self -->|no| Credentials[Validate credential environment variables]
    Credentials --> Ready[Start process]
Loading

File-Level Changes

Change Details Files
Replace the separate TES service list and discovery configuration with FOCA's typed, ordered backend list.
  • Accept configured TES entries and service-registry entries through custom.tes.backends.
  • Reject legacy keys with migration guidance and delegate validation, normalization, deduplication, expansion, and caching to FOCA.
  • Preserve per-entry authentication, labels, locations, URL schemes, and registry settings.
pro_tes/config_models.py
pro_tes/ga4gh/tes/backends.py
pro_tes/ga4gh/tes/discovery.py
pro_tes/exceptions.py
pro_tes/config.yaml
Integrate FOCA backend discovery and enforce request-time backend safety.
  • Return expanded backends and their originating entries for client creation and credential selection.
  • Check discovered backend hosts before every request, disallow redirects, and map FOCA HTTP errors to BackendAddressNotAllowed.
  • Require a public URL when registries are configured and reject configured TES URLs at or below that URL in both app and Celery-worker startup checks.
pro_tes/ga4gh/tes/backends.py
pro_tes/security.py
pro_tes/celery_worker.py
pro_tes/config_models.py
Update service metadata and middleware behavior for the new backend model.
  • Source service-info backend data from FOCA describe() with identifiers, URLs, source, group, and labels.
  • Use the expanded ordered backend list in task-distribution middlewares and backend lookup.
  • Update client and task-tracking interfaces to carry FOCA backend objects plus their configuration entries.
pro_tes/ga4gh/tes/backends.py
pro_tes/plugins/middlewares/task_distribution/base.py
pro_tes/plugins/middlewares/task_distribution/distance.py
pro_tes/tasks
pro_tes/config.yaml
Add Helm support for typed TES backends and public application URLs.
  • Introduce tes.backends and publicUrl, translating chart camelCase keys to app configuration keys.
  • Add strict per-entry schema validation and render-time failures for legacy, duplicated, invalid, or registry-without-public-URL configurations.
  • Generate server.public_url from publicUrl or hostName, while honoring explicit config precedence.
deployment/values.yaml
deployment/values.schema.json
deployment/templates/_helpers.tpl
deployment/README.md
deployment/ci/optional-values.yaml
tests/test_chart.py
Migrate examples, documentation, smoke configuration, and tests to the new backend architecture.
  • Update configuration, access-control, middleware, operations, README, and upgrade guidance with the breaking-change mapping and new service-info shape.
  • Replace the large proTES discovery test suite with focused integration tests using fake registry responses and DNS checks.
  • Validate application and rendered chart examples, worker behavior, public URL safeguards, credentials, ordering, service info, and request-time address checks.
docs/configuration.md
docs/access-control.md
docs/middlewares.md
docs/operations.md
docs/upgrading.md
README.md
config.dev.yaml
tests/ga4gh/tes/test_backend_list.py
tests/ga4gh/tes/test_backends.py
tests/test_security.py
tests/test_celery_worker.py
tests/test_config_examples.py
tests/smoke/config.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#332 Replace custom.tes.service_list and custom.tes.discovery with an ordered, typed custom.tes.backends list, and fail with a migration hint when the old keys are used. ✅
#332 Use FOCA for backend expansion, registry discovery, backend lookup, and public-address checks; integrate entry-specific credentials, require server.public_url when registries are configured, and expose backend descriptions in service info. ✅
#332 Update the chart, smoke configuration, and documentation for the new backend list and breaking-change migration, while removing proTES-owned discovery and address-checking code. ✅

Possibly linked issues

  • refactor!: list TES backends with FOCA #332: The PR implements the issue’s acceptance criteria: custom.tes.backends, legacy-key migration errors, FOCA discovery, public URL checks, and related chart and documentation updates.

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 29, 2026 •

Copy link
Copy Markdown

@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 (183dd5b) to head (96490ca).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #340    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           28        27     -1     
  Lines         2420      2195   -225     
==========================================
- Hits          2420      2195   -225     

☔ 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 03:30

@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="pro_tes/config.yaml" line_range="181" />
<code_context>
 service_info:
   package: pro-tes
-  runtime_fields: pro_tes.ga4gh.tes.discovery.service_info_fields
+  runtime_fields: pro_tes.ga4gh.tes.backends.service_info_fields
   service:
     id: org.example.protes
</code_context>
<issue_to_address>
**Service info leaks backend metadata**

When a deployment configures TES backends with internal hostnames or sensitive labels, `pro_tes/config.yaml` routes service-info fields to `pro_tes.ga4gh.tes.backends.service_info_fields()`, which returns backend objects rather than the documented URL shape. An anonymous GET to `/service-info` exposes backend URLs and labels, including internal hostnames and deployment metadata.

Restore the `runtime_fields` target to `pro_tes.ga4gh.tes.discovery.service_info_fields`.

Also at `pro_tes/ga4gh/tes/backends.py:405`.
</issue_to_address>

### Comment 2
<location path="pro_tes/ga4gh/tes/backends.py" line_range="368-391" />
<code_context>
+def get_backend(url: str) -> tuple[Backend, ServiceEntry | RegistryEntry]:
</code_context>
<issue_to_address>
**Backend lookup returns a tuple**

When a downstream plugin or integration calls `pro_tes.ga4gh.tes.backends.get_backend()` and expects the previous backend object, existing callers that use `get_backend(url)` as a backend object now receive `(backend, entry)`, so accesses such as `.url` or `.auth` fail with `AttributeError` instead of using the backend.

Preserve the old return contract under `get_backend()` and expose the backend-plus-entry lookup under a new name, or document this Python API break and migration explicitly.
</issue_to_address>

### Comment 3
<location path="tests/test_chart.py" line_range="890" />
<code_context>
+        ({"type": "ga4gh-tes"}, "missing property 'url'"),
+        ({"type": "ga4gh-wes", "url": "https://wes.example.org"}, "/tes/backends/0"),
+        (
+            {"type": "ga4gh-tes", "url": "https://tes.example.org", "url_schemes": []},
+            "/tes/backends/0",
+        ),
</code_context>
<issue_to_address>
**Empty scheme lists escape validation**

When the chart schema stops rejecting an empty camelCase `urlSchemes` list, the `url_schemes` key is rejected as unknown, so `test_tes_backends_invalid` passes when it sees an error at `/tes/backends/0`, even if the schema accepts an empty camelCase `urlSchemes` list and renders that invalid configuration.

Use `urlSchemes: []` in the test input so the rejection exercises the non-empty-list constraint.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the backend list now expands registry entries into TES destinations and carries each entry’s authentication settings into requests, so a mistake in discovery filtering or credential association could send task data or proTES credentials to an unintended service. Reverting would stop future requests, but it could not retract data or credentials already sent.

Blocking findings: pro_tes/config.yaml:181, pro_tes/ga4gh/tes/backends.py:391, tests/test_chart.py:890


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

Comment thread pro_tes/config.yaml Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread tests/test_chart.py Resolved

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="pro_tes/config.yaml" line_range="181" />
<code_context>
 service_info:
   package: pro-tes
-  runtime_fields: pro_tes.ga4gh.tes.discovery.service_info_fields
+  runtime_fields: pro_tes.ga4gh.tes.backends.service_info_fields
   service:
     id: org.example.protes
</code_context>
<issue_to_address>
**Service info docs promise URL strings**

Clients following the service-info description expect `backends` to contain URL strings, but `service_info_fields()` now supplies objects with `id`, `url`, `source`, `group`, and `labels`. Such clients reject the response or fail when treating each object as a URL.

Update the remaining service-info description to say that `backends` contains objects and summarize their fields.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if registry expansion or its association with authentication settings is wrong, proTES could send its bearer token or Basic credentials to an unintended TES endpoint. Reverting stops future requests, but cannot retract credentials already disclosed.

Blocking findings: pro_tes/config.yaml:181


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

Comment thread pro_tes/config.yaml Resolved
Address Sourcery review: test the camelCase urlSchemes constraint and
the unknown snake_case key separately, and document the new return
value of get_backend() in Upgrading.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 8bc81f2 into dev Oct 29, 2026
19 checks passed
@uniqueg
uniqueg deleted the refactor/backend-list branch October 29, 2026 03:41
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!: list TES backends with FOCA

1 participant