Skip to content

feat: discover TES backends from the registry - #260

Merged
uniqueg merged 6 commits into
devfrom
feat/registry-discovery
Oct 23, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/registry-discovery

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

proTES can now take TES backends from a service registry that implements the GA4GH Service Registry API with verified services, such as the Cloud Registry. This follows section 4a of the ELIXIR On-Cloud auth policy. The new setting is custom.tes.discovery. It is off by default, and there is no default registry, so the config stays generic.

  • Registry. The deployment configures the registry URL, which is the trust anchor. Its scheme must be in url_schemes (default https). Reads use GET /verifications and GET /services, without access token. Redirects are not followed, and responses are capped at 16 MiB.
  • Verified entries only. A service is used only if /verifications lists it with the same identifier, the exact URL as registered, and the same type.group/type.artifact (compared case-insensitively). These are the semantics the Cloud Registry documents.
  • Client-side filters.
    • Type org.ga4gh tes.
    • versions as prefixes (default 1.0 and 1.1).
    • environments (any if empty).
  • Endpoints.
    • Only valid https URLs without user info are accepted.
    • URLs are normalized with foca.utils.urls, and the API path /ga4gh/tes/v1 is removed.
    • Hosts must have public addresses only. Private, loopback, link-local, multicast and other special-purpose addresses are rejected, including IPv4 addresses embedded in IPv6 ones.
    • The host is checked on discovery and before each request.
    • Requests to discovered backends don't follow redirects.
    • allow_private_addresses turns the address check off for local setups, and the app logs a warning when it is set.
  • Cache.
    • Each process reads the registry every refresh_interval seconds.
    • It keeps the last good list while the registry is unreachable or invalid, and retries after at most 30 seconds.
    • Backends whose hosts can't be resolved for the moment are kept for one more read.
    • If a backend is not in a process's cache, that process reads the registry again, at most every 10 seconds. This happens, for example, when the Celery worker tracks a task on a backend that the app discovered first. The worker also retries tracking such a task 3 times, 10 seconds apart, before it sets SYSTEM_ERROR.
    • Changes and rejected verified services are logged.
  • Static list. service_list is still used, comes first, and wins over discovered backends with the same URL.
  • Auth (feat!: call TES backends with service tokens #213). Discovered backends get discovery.auth: client_credentials by default, or none. Startup requires the IdP settings and PROTES_CLIENT_ID/PROTES_CLIENT_SECRET when discovered backends use tokens.
  • Visibility. Active backends are logged, and listed in service info as backends, through FOCA's service_info.runtime_fields. Deployments can set that to null to hide them.

Docs: docs/configuration.md has a new section, "Discovery in a service registry". access-control.md, operations.md, middlewares.md and the comments in config.yaml are updated.

Known limitation (documented): the host check doesn't protect against DNS rebinding between the check and the connection. py-tes calls the module-level requests functions, so the client can't pin the resolved address without monkeypatching. The docs recommend restricting egress with a NetworkPolicy.

Verification

  • coverage run -m pytest -W ignore::DeprecationWarning: 650 passed, 76 skipped (Helm tests; Helm is not installed locally), coverage 100%.
  • mypy: no issues.
  • pre-commit run --all-files (ruff, semgrep, gitleaks, ast-grep, …): passed.
  • mkdocs build --strict: passed.
  • Review: adversarial-reviewer and quality-reviewer, 2 rounds (see below).
  • CI: all checks passed (tests with mongomock and MongoDB 7.0, static analysis, Helm chart, docs, Docker Compose smoke test, image scan, CodeQL).

Declined review findings

  • Pinning resolved addresses at connection time (DNS rebinding): py-tes uses the module-level requests functions, so this would need monkeypatching of urllib3. I declined it, documented the limitation, and recommend restricting egress.

Open questions

None blocking. The remaining issue dependencies (#201, generic-issues#20/#21/#29, TESK#214) concern deployments: backends accepting proTES' token, and a populated registry. They don't block the code.

Closes #202

🤖 Generated with Claude Code

Summary by Sourcery

Enable secure, cached discovery of verified TES backends from a configurable GA4GH service registry while preserving static backend configuration precedence.

New Features:

  • Discover TES backends from a configurable GA4GH service registry using verified service entries, type/version/environment filters, and configurable authentication.
  • Expose configured and discovered backend URLs through service information and use discovered backends in task distribution and tracking.

Bug Fixes:

  • Prevent untrusted or unsafe discovered endpoints from being used by enforcing verification matching, HTTPS URLs, public-host checks, redirect blocking, and response limits.
  • Handle registry outages and cross-process discovery delays by retaining the last valid backend list, retrying refreshes, and retrying unknown-backend task tracking.

Enhancements:

  • Preserve static service-list backends as the preferred sources while adding cached, logged discovery with validation and runtime visibility controls.

Documentation:

  • Document service-registry discovery, security requirements, configuration, operations, access control, and middleware behavior.

Tests:

  • Add comprehensive coverage for registry parsing, verification, endpoint safety, caching, authentication, task forwarding, configuration, and retry behavior.

uniqueg and others added 4 commits October 23, 2026 17:12
Add `custom.tes.discovery`: proTES reads a configured service registry
(GA4GH Service Registry API with the Cloud Registry's verified services,
`GET /services` and `GET /verifications`) without access token, and
forwards tasks to the TES services that are verified with their current
URL and API type, of an accepted version and environment, with valid
`https` URLs and public host addresses (checked on discovery and before
each request, unless private addresses are allowed). Discovery is off by
default; there is no default registry.

Each process caches the discovered backends, refreshes them every
`refresh_interval` seconds and keeps the last good list while the
registry is unavailable or invalid. Changes and rejected services are
logged. Configured backends come first and take precedence. Discovered
backends get `auth` (`client_credentials` by default, or `none`), and
the app checks proTES' client credentials on startup for them. The
service info lists the URLs of all backends (`backends`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Requests to discovered backends don't follow redirects, which could
  lead to private addresses.
- A backend that isn't cached (e.g., one that another process
  discovered) triggers a rate-limited read of the registry, so that the
  Celery worker can track its tasks.
- Hosts that can't be resolved for now keep their earlier backend until
  the next read; failed reads are retried after 30 seconds at most.
- Deeply nested responses and unexpected errors never fail requests.
- IPv4-compatible IPv6 addresses are checked like other embedded IPv4
  addresses.
- Compare backend URLs normalized; add `Discovery.enabled` and
  `uses_tokens`; move the exceptions to `pro_tes.exceptions`; split the
  selection into helpers; fix the docs on `url_schemes` and DNS
  timeouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Celery worker may not have read the registry since another process
discovered a task's backend, and forced reads are rate-limited. With
discovery on, tracking tasks of unknown backends is retried three times,
`MIN_REFRESH_INTERVAL` seconds apart, before the task fails.

Backends whose hosts can't be resolved are kept for one read only, not
for as long as resolution fails.

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

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces opt-in GA4GH Service Registry discovery for verified TES backends, with strict verification and network-safety checks, resilient per-process caching, authentication and worker integration, static-backend precedence, service-info exposure, documentation, and extensive tests.

Sequence diagram for verified TES backend discovery

sequenceDiagram
    participant Process as proTES process
    participant Registry as GA4GH Service Registry
    participant Resolver as DNS resolver
    participant Cache as BackendDiscovery cache

    Process->>Cache: get_backends()
    Cache->>Registry: fetch_json(/verifications)
    Registry-->>Cache: verified services
    Cache->>Registry: fetch_json(/services)
    Registry-->>Cache: registered services
    Cache->>Cache: select_backends()
    Cache->>Resolver: check_public_host()
    Resolver-->>Cache: public addresses
    Cache-->>Process: static backends first, discovered backends after

    alt registry unavailable or invalid
        Cache-->>Process: last good backend list
    end
Loading

Sequence diagram for requests to discovered TES backends

sequenceDiagram
    participant Caller as proTES caller
    participant Client as TES client
    participant Resolver as DNS resolver
    participant Backend as Discovered TES backend
    participant IdP as Identity provider

    Caller->>Client: create_client()
    Client->>Resolver: check_public_host()
    Resolver-->>Client: public address
    alt auth client_credentials
        Client->>IdP: get_token()
        IdP-->>Client: access token
        Client->>Backend: TES request with Bearer token
    else auth none
        Client->>Backend: TES request without credentials
    end
    Backend-->>Client: TES response
    Note over Client,Backend: Redirects are not followed
Loading

Flow diagram for selecting verified TES backends

flowchart TD
    A[Registered service] --> B{TES type org.ga4gh / tes?}
    B -- No --> X[Reject]
    B -- Yes --> C{Version and environment accepted?}
    C -- No --> X
    C -- Yes --> D{Matching verification exists?}
    D -- No --> X
    D -- Yes --> E{Identifier, URL, and API type match verification?}
    E -- No --> X
    E -- Yes --> F[Normalize URL and remove /ga4gh/tes/v1]
    F --> G{Valid https URL and public host?}
    G -- No --> X
    G -- Yes --> H[Create DiscoveredBackend]
    H --> I[Merge with service_list precedence]
Loading

File-Level Changes

Change Details Files
Adds a registry-backed discovery pipeline that validates, filters, verifies, normalizes, and caches TES services before exposing them as usable backends.
  • Introduces discovery configuration, defaults, validation, authentication modes, and startup checks.
  • Fetches registry services and verifications without credentials, with bounded responses and no redirects.
  • Accepts only verified TES services matching URL/type identity, version, environment, HTTPS, and public-host requirements.
  • Adds DNS/IP safety checks, redirect protection, private-address override warnings, and per-request revalidation.
  • Implements per-process caching, retry/last-good behavior, unresolved-host retention, change/rejection logging, and fork-safe synchronization.
pro_tes/config_models.py
pro_tes/exceptions.py
pro_tes/ga4gh/tes/discovery.py
pro_tes/security.py
pro_tes/ga4gh/tes/backends.py
Integrates discovered backends into task routing, backend lookup, authentication, service metadata, and worker tracking while preserving static backend precedence.
  • Combines configured and discovered backends with static URLs first and static configuration winning on collisions.
  • Updates middleware selection and backend lookup to use discovery, including rate-limited refreshes for cross-process visibility.
  • Retries Celery tracking when a discovered backend is temporarily unknown, then records SYSTEM_ERROR after the retry limit.
  • Publishes active backend URLs through service-info runtime fields, with deployment-configurable visibility.
  • Applies discovered-backend authentication settings and requires proTES client credentials when token auth is enabled.
pro_tes/plugins/middlewares/task_distribution/base.py
pro_tes/tasks/track_task_progress.py
pro_tes/ga4gh/tes/backends.py
pro_tes/config.yaml
Documents discovery configuration, trust and security semantics, operational behavior, middleware integration, and backend visibility.
  • Adds configuration reference covering registry verification, filtering, URL normalization, host safety, caching, authentication, and DNS-rebinding limitations.
  • Updates access-control, middleware, operations, and default configuration guidance.
docs/configuration.md
docs/access-control.md
docs/middlewares.md
docs/operations.md
pro_tes/config.yaml
Adds comprehensive coverage for service selection, network safety, registry handling, caching, integration, configuration, security, and worker retry behavior.
  • Tests verification matching, TES type/version/environment filters, URL handling, public and embedded IP address checks, response limits, and redirect/auth behavior.
  • Tests cache refresh and failure semantics, unresolved-host retention, precedence, service-info exposure, client request safeguards, and task retries.
  • Extends fixtures to isolate discovery DNS and cache state.
tests/ga4gh/tes/test_discovery.py
tests/tasks/test_track_task_progress.py
tests/conftest.py
tests/test_fixtures.py
tests/test_security.py

Assessment against linked issues

Issue Objective Addressed Explanation
#202 Discover TES backends from a configurable registry, using only verified services that match the configured TES type, version, and environment filters, and refresh the list while retaining the last good list on registry failures. ✅
#202 Protect registry-discovered backends by requiring HTTPS and rejecting hosts with non-public addresses by default; preserve static backends as an option and prioritize them over discovered entries. ✅
#202 Route tasks to discovered backends using the configured proTES authentication, expose active backends in logs and service info, and cover the discovery behavior with tests. ✅

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

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (005ca9e) to head (5419517).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #260    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           26        27     +1     
  Lines         1570      1848   +278     
==========================================
+ Hits          1570      1848   +278     

☔ 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 23, 2026 17:18

@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/ga4gh/tes/discovery.py" line_range="89-90" />
<code_context>
+    if isinstance(address, ipaddress.IPv6Address):
+        if address.ipv4_mapped is not None:
+            address = address.ipv4_mapped
+        elif any(address in prefix for prefix in _EMBEDDING_PREFIXES):
+            address = ipaddress.IPv4Address(int(address) & 0xFFFFFFFF)
+    return address.is_global and not address.is_multicast
+
</code_context>
<issue_to_address>
**Embedded private addresses pass validation**

When a verified service uses a 6to4 IPv6 address embedding a private or other special-purpose IPv4 address, `is_public_address` decodes only IPv4-mapped, NAT64, and IPv4-compatible addresses; a globally classified 6to4 address embedding a special-purpose IPv4 address is therefore accepted, so a discovered backend can bypass the public-address restriction.

Decode embedded IPv4 addresses for other transition formats such as 6to4, or reject those IPv6 ranges outright.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and a discovered backend can receive forwarded task details, input locations, and—by default—a proTES access token; if the registry or its verification data admits an unintended endpoint, those disclosures cannot be undone. Reverting stops future forwarding, but cannot recall data or tokens already sent.

Blocking findings: pro_tes/ga4gh/tes/discovery.py:90


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

Comment thread pro_tes/ga4gh/tes/discovery.py Resolved
@read-the-docs-community

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

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35360913 | 📁 Comparing 5419517 against latest (e38b4de)

  🔍 Preview build  

7 files changed · ± 7 modified

± Modified

@uniqueg
uniqueg merged commit 30a5025 into dev Oct 23, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/registry-discovery branch October 23, 2026 17:31
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.

feat: discover TES backends from the registry

1 participant