Repository navigation
feat!: configure WES backends - #173
Conversation
Runs go to the WES instances of `custom.wes.backends`, a typed backend list of FOCA (`foca.plugins.backends`): WES instances (`type: ga4gh-wes`, with an optional `api_path`) and service registries whose verified WES instances are used (`type: ga4gh-service-registry`). New runs go to the first backend; without any, `POST /runs` is refused with `503 Service Unavailable` before anything is stored. The hard-coded WES is gone, and the app refuses to start with a configured WES instance at or below its public URL. FOCA 0.22 knows the backends of TES gateways only: the API type of WES is registered in `API_TYPES` (unless FOCA has one), and the entries of proWES subclass FOCA's, with `auth: none` only until #120. BREAKING CHANGE: deployments must configure their WES instances. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fake WES is the WES instance of the smoke test's config overlay, at its Compose service name, instead of taking the host name of the former hard-coded WES. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Configuration, deployment (chart values `config.custom.wes.backends`), upgrade note, getting started, API and reference; a chart test checks that the backends reach the config overlay as the app reads them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: `server.public_url` is the root URL (docs said with the API path, which disabled the check); backend lists with registry entries need it; the startup check also covers `url` with `api_path`; the client's token is never passed on to WES instances (`auth: none`). Tests assert the reason of each invalid config; comments explain the reliance on FOCA 0.22 internals. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review fixes: a regression test that no WES instance gets the client's token (runs, cancellations, tracking); the upgrade note says so; the docs explain public URLs of WES instances on the same host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The response for runs without a WES instance, as the problem details of the other error responses (#170), with a test and the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideSchema and migrationsPersist the selected WES endpoint with each run so later tracking and cancellation continue using that instance.
Data structuresDefine and validate the ordered WES backend configuration, including instance and registry entry types, API paths, authentication constraints, and unique identifiers.
APIDeclare the 503 problem-details response for POST /runs when no WES backend is available.
Expose backend selection failures as a service-unavailable exception and register its response mapping.
Uses of the APIChoose an available backend before storing a run, persist its endpoint, and stop forwarding the client's token to WES instances for submission, tracking, and cancellation.
ImplementationRegister the WES backend API type and adapt FOCA's backend list to expand configured or discovered instances, filter self-references, and select the first available endpoint.
Run the backend self-forwarding and registry-public-URL checks during application startup.
Build valid WES API URLs for empty base paths and reject redirects from WES instances.
ConfigurationProvide Helm values examples and deployment instructions for setting backend lists and the public URL.
Configure the smoke-test fake WES as a backend and remove the alias for the former hard-coded destination.
DocumentationDocument backend configuration, registry discovery, the 503 behavior, deployment setup, upgrading, and the updated development and reference guidance.
TestsExercise backend configuration, discovery, selection, startup safeguards, no-backend errors, persisted endpoints, and token handling.
Update smoke-test fixture documentation and certificates to match the configured fake WES hostname.
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 #173 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 19 +1
Lines 861 942 +81
=========================================
+ Hits 861 942 +81 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 9184ffa #118 feat: configure WES backends · 3 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_wes/ga4gh/wes/backends.py" line_range="107-113" />
<code_context>
+ """
+ backend_list = get_backend_list()
+ public_url = backend_list.public_url
+ if public_url is None:
+ if backend_list.has_registries():
+ raise ValueError(
+ "Backend lists with registry entries need the public URL of"
+ " proWES (`server.public_url`)"
+ )
+ return
+ for entry in backend_list.entries:
+ if not isinstance(entry, WesServiceEntry):
</code_context>
<issue_to_address>
**Runs recursively target proWES**
When `server.public_url` is unset and a configured WES URL points to this proWES deployment, `check_backends` returns before checking the configured WES instance, so `select_backend` can select proWES itself; forwarded `POST /runs` requests create more runs and forward them again, exhausting app resources.
Check configured WES instances even when `server.public_url` is unset, and reject endpoints that point back to this deployment.
</issue_to_address>
### Comment 2
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="234" />
<code_context>
None,
{
- "jwt": kwargs.get("jwt"),
+ "jwt": None,
"remote_host": updated_document_stored.wes_endpoint.host,
"remote_base_path": updated_document_stored.wes_endpoint.base_path,
</code_context>
<issue_to_address>
**Client tokens reach remote WES**
When a progress task queued by the previous version with a nonempty client JWT is consumed by a new worker, `task__track_run_progress` passes its serialized `jwt` argument to `WesClient`, which sends it as an Authorization header to the stored WES endpoint, disclosing the client token after upgrade.
Make `task__track_run_progress` ignore the queued client JWT and never forward it to the stored WES endpoint.
</issue_to_address>
### Comment 3
<location path="pro_wes/ga4gh/wes/backends.py" line_range="169" />
<code_context>
+ "No WES instance available; configure `custom.wes.backends`"
+ )
+ backend = backends[0]
+ return backend.url, api_path(backend, backend_list)
</code_context>
<issue_to_address>
**Redirects reach private services**
When a registry-listed WES endpoint responds with a 307 or 308 redirect to an internal URL, `select_backend` returns the registry-listed endpoint, and `WesClient`'s default-following `requests.Session.post` repeats the run request after a 307/308 redirect. The remote service can therefore make proWES issue requests to private services.
Disable redirects for WES requests, or validate every redirect target with the same address and redirect protections used for registry requests.
</issue_to_address>
### Comment 4
<location path="pro_wes/ga4gh/wes/client_wes.py" line_range="48-51" />
<code_context>
) -> None:
"""Class constructor."""
- self.url = f"{host.rstrip('/')}/{base_path.strip('/')}"
+ # without the separator for an empty base path (the API at `host`)
+ self.url = "/".join(
+ part for part in (host.rstrip("/"), base_path.strip("/")) if part
+ )
self.set_token(token)
self.session = requests.Session()
</code_context>
<issue_to_address>
**WES calls bypass guarded client**
The issue asks to use FOCA's guarded HTTP client for outbound requests. Registry discovery does so, but WES API calls continue through `requests`.
</issue_to_address>
### Comment 5
<location path="pro_wes/config_models.py" line_range="54" />
<code_context>
+ # Narrower than the fields of FOCA's entry (TES instances, credentials);
+ # the type is that of the API type of `pro_wes.ga4gh.wes.backends.WES_API`
+ type: Literal["ga4gh-wes"] # type: ignore[assignment]
+ auth: Literal["none"] = "none"
+ api_path: str = DEFAULT_API_PATH
+
</code_context>
<issue_to_address>
**Credentials reference unsupported**
The issue asks for an optional credentials reference on WES backends. The change restricts `auth` to `none`, so deployments cannot configure a reference.
</issue_to_address>
### Comment 6
<location path="pro_wes/ga4gh/wes/backends.py" line_range="163-168" />
<code_context>
+ none is configured, or the registries list none (yet).
+ """
+ backend_list = get_backend_list()
+ backends = backend_list.expand()
+ if not backends:
+ raise NoBackendAvailable(
+ "No WES instance available; configure `custom.wes.backends`"
+ )
+ backend = backends[0]
+ return backend.url, api_path(backend, backend_list)
</code_context>
<issue_to_address>
**Plugin backend selection absent**
The issue asks for plugins to choose and order backends when the plugin pipeline is used. The change always selects the first expanded backend instead.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 6 findings to address first, and if a configured backend or registry resolves to an unintended WES, run requests and workflow attachments can be sent there; reverting stops future forwarding but cannot recall data already disclosed. The change also stops forwarding client tokens, which changes how authenticated requests reach WES instances.
Blocking findings: pro_wes/ga4gh/wes/backends.py:113, pro_wes/ga4gh/wes/workflow_runs.py:234, pro_wes/ga4gh/wes/backends.py:169, pro_wes/ga4gh/wes/client_wes.py:51, pro_wes/config_models.py:54, and 1 more
Sourcery review fixes: WES clients don't follow redirects (e.g., of a discovered WES instance to an internal service), and the tracking task ignores client tokens of tasks queued by earlier versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Runs go to the WES instances of
custom.wes.backendsinstead of a hard-coded WES:foca.plugins.backends, ascustom.tes.backendsin proTES): WES instances (type: ga4gh-wes:url, optionalapi_path,id,labels,location,url_schemes) and service registries whose verified WES instances are used (type: ga4gh-service-registry, read by FOCA with its guarded HTTP client: no token,https, public addresses, no redirects, timeouts, per-process cache). Invalid entries, unknown keys and duplicate ids stop the app on startup.POST /runsis refused with503 Service Unavailable(declared in the served spec as problem details) before anything is stored. The WES instance is stored with each run, so tracking and cancelling are unchanged.server.public_url(the root URL, as FOCA defines it) are never used; the app refuses to start if a configured one is (also itsurl+api_path), and refuses registry entries withoutserver.public_url(as FOCA's gateways do).authmust benonefor now; the client's token is never passed on to WES instances (with authentication off, there was none). Credentials per WES instance come with feat: authenticate clients and backends #120.API_TYPES(setdefault, so a later FOCA one wins) and subclasses FOCA's entries andBackendList, until FOCA's backend lists support WES (FOCA issue drafted for the maintainer)./:WesClientno longer buildshost//runsfor an empty base path.https://fake-wes, TLS with its own CA), not an alias of the former hard-coded host.configuration.md("WES instances", "Discovery in a service registry"),deployment.md(chart:config.custom.wes.backends, no new values key;server.public_url),upgrading.md(breaking: configure backends; how to keep the former WES; no token forwarding),getting-started.md(Compose overlay),api.md(503),index.md,development.md,reference.md, commented example indeployment/values.yaml.Not in this PR: requests to the WES instances themselves still use
requests(TLS verification on, configured timeouts); moving them to FOCA's guarded client rewritesclient_wes.pyand changes the timeout settings, so it is split into its own issue (drafted for the maintainer).Verification
coverage run -m pytest(mongomock, Helm 3.22.1 withhelm dependency build deployment): 471 passed;coverage report: 100%.pre-commit run --all-files(ruff, ruff format, mypy, semgrep and its rule tests, ast-grep and its rule tests, uv lock check, file checks): passed; gitleaks and actionlint skipped locally (Go toolchain download fails in the sandbox), run in CI.mkdocs build --strict: passed.public_urldocumented with the API path (disabled the self-check), registry entries withoutpublic_url,api_pathignored by the self-check, client token passed on, upgrade note, test assertions per invalid case, a regression test for token forwarding, comments on FOCA internals, docs wording.public_url, guarded client for WES requests (split), credentials (feat: authenticate clients and backends #120), plugin selection (feat: run new runs through FOCA plugins #121)); all resolved.Declined review findings
401/403of a WES instance to502(round 2, suggestion): changes the existing error mapping of forwarded runs; belongs with authentication (feat: authenticate clients and backends #120).jwtargument of the tracking task (pro_wes/tasks/track_run_progress.py) stays (low): it is alwaysNonenow; feat: authenticate clients and backends #120 replaces it with credentials per WES instance, and the module was being changed by another PR.Open questions
None.
Closes #118
🤖 Generated with Claude Code