Repository navigation
refactor!: list TES backends with FOCA - #340
Conversation
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]>
Reviewer's GuideThis breaking refactor centralizes configured and discovered TES backends in FOCA's typed Sequence diagram for registry-backed TES request authenticationsequenceDiagram
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
Entity relationship diagram for backend entry sourceserDiagram
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
}
Flow diagram for backend safety validationflowchart 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]
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 #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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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/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
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]>
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 ofcustom.tes.service_listplus one registry incustom.tes.discovery. proTES no longer has registry discovery or address checks of its own.type: ga4gh-tes:url,url_schemes,id,auth,basic,labels,location) and service registries (type: ga4gh-service-registry), in order.custom.tes.service_listandcustom.tes.discoverystop the app with a hint that gives the mapping: theservice_listentries becomega4gh-tesentries, in order, followed by the registry as onega4gh-service-registryentry.pro_tes.ga4gh.tes.backends.get_backends()returnsBackendList(...).expand(), and the middlewares get it as before.get_backend(url)usesfind()and returns the backend together with its entry (entry_for()). The entry supplies the credentials (auth,basic), which proTES still adds itself.check_public_host()checks the host, unless the registry entry setsallow_private_addresses. Failures map toBackendAddressNotAllowed. Redirects are not followed.server.public_urlis not set. This keeps proTES from discovering itself.check_backends()also runs in the Celery worker, with the worker's config.backendsnow comes fromdescribe(). Each backend is an object withid,url,source,groupandlabels; before, it was a URL.custom.tes.client_credentialsandcustom.tes.timeout.custom.tes.url_schemesnow applies to the identity provider only; backends and registries seturl_schemesper entry.pro_tes/ga4gh/tes/discovery.py(discovery,check_public_host,is_public_address), its 982-line test module, and the exceptionsHostNotResolvedandRegistryError. A smallertests/ga4gh/tes/test_backend_list.pytests how proTES uses FOCA's list, with a fake registry and fake DNS.tes.backends, with camelCase keys (urlSchemes,refreshInterval,maxStale,allowPrivateAddresses,registryAllowPrivateAddresses,basic.usernameEnv/passwordEnv; the keys oflabelsare kept as given), rendered intocustom.tes.backends.values.schema.jsonchecks it with one strict schema per entry type.config.custom.tes.service_listanddiscovery, on backends set both intes.backendsand inconfig.custom.tes.backends, and on registries when the app has no public URL.publicUrl.server.public_urlis set topublicUrl, or else tohttps://<hostName>/, the same way Cloud Registry's chart does it. Unlike Cloud Registry's chart, it is left unset whenhostNameis empty, since proTES does not requirehostName.hostNameis shared with other apps.deployment/ci/optional-values.yamlnow lists backends, sohelm lintcovers them.tests/smoke/config.yamluses the new list, withurl_schemes: [http]on the entry.docker-compose.yamlneeded no change (it mountsconfig.dev.yaml, whose commented example is updated).url_schemesper 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_listandcustom.tes.discoveryare replaced bycustom.tes.backends; the old keys stop the app with the mapping. In the chart, usetes.backends(camelCase keys) instead ofconfig.custom.tes.service_list/discovery.server.public_url(the chart sets it fromhostNameorpublicUrl).custom.tes.url_schemesapplies to the identity provider only; entries withhttpURLs needurl_schemes: [https, http].max_staleseconds (default 3600) yields no backends. Earlier versions kept the last list indefinitely.backendsas objects instead of URLs.Verification
coverage run -m pytest: 1079 passed, 1 skipped, 100% coverage (mongomock).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 passed).Declined review findings
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'sGuardedClient, which belongs with refactor!: process tasks with FOCA plugins #333 (TesClientsending the forward phase's requests). Tracked in fix: check connections to discovered backends #339.authbranch inTesClient._request_params. Kept deliberately: unknown credential names fail closed instead of being sent without credentials (tested intest_client_auth_unknown). In refactor!: process tasks with FOCA plugins #333, plugins choose credentials by name, so the branch becomes reachable.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 explicitidfor internal registries, andruntime_fields: nullhides the field.BackendListis 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