Repository navigation
feat: discover TES backends from the registry - #260
Conversation
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]>
# Conflicts: # docs/operations.md
Reviewer's GuideIntroduces 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 discoverysequenceDiagram
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
Sequence diagram for requests to discovered TES backendssequenceDiagram
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
Flow diagram for selecting verified TES backendsflowchart 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]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.url_schemes(defaulthttps). Reads useGET /verificationsandGET /services, without access token. Redirects are not followed, and responses are capped at 16 MiB./verificationslists it with the same identifier, the exact URL as registered, and the sametype.group/type.artifact(compared case-insensitively). These are the semantics the Cloud Registry documents.org.ga4ghtes.versionsas prefixes (default1.0and1.1).environments(any if empty).httpsURLs without user info are accepted.foca.utils.urls, and the API path/ga4gh/tes/v1is removed.allow_private_addressesturns the address check off for local setups, and the app logs a warning when it is set.refresh_intervalseconds.SYSTEM_ERROR.service_listis still used, comes first, and wins over discovered backends with the same URL.discovery.auth:client_credentialsby default, ornone. Startup requires the IdP settings andPROTES_CLIENT_ID/PROTES_CLIENT_SECRETwhen discovered backends use tokens.backends, through FOCA'sservice_info.runtime_fields. Deployments can set that tonullto hide them.Docs:
docs/configuration.mdhas a new section, "Discovery in a service registry".access-control.md,operations.md,middlewares.mdand the comments inconfig.yamlare 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
requestsfunctions, 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.adversarial-reviewerandquality-reviewer, 2 rounds (see below).Declined review findings
requestsfunctions, 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:
Bug Fixes:
Enhancements:
Documentation:
Tests: