Skip to content

feat!: authenticate at WES backends - #213

Merged
uniqueg merged 12 commits into
devfrom
issue-182-backend-credentials
Dec 4, 2026
Merged

uniqueg merged 12 commits into
devfrom
issue-182-backend-credentials

Conversation

@uniqueg

@uniqueg uniqueg commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

proWES authenticates at the WES instances it forwards runs to with credentials of its own, never with those of its clients, as the auth of their entries in custom.wes.backends says (FOCA's backend credentials):

  • client_credentials (the default): a token of proWES's client at the identity provider of the new custom.wes.client_credentials (issuer or token_endpoint, optional audience_parameter for a token per WES instance, with the entry's audience or its URL); client ID and secret in PROWES_CLIENT_ID and PROWES_CLIENT_SECRET.
  • basic: HTTP Basic credentials from the environment variables that the entry's basic names (transitional).
  • none: no credentials.

Discovered WES instances get the credentials of their registry entry. Credentials are looked up for each request in the current backend list: WES instances that the list no longer yields get no request (no_credentials, not retried), and tracking their runs fails (SYSTEM_ERROR). Service infos, read to choose WES instances, are read without credentials. The worker task ignores its jwt argument (kept for tasks queued by earlier versions). The startup check is FOCA's check_backends: it refuses missing environment variables and warns about auth: basic, auth: none and http.

Breaking: the default auth was none (the only value accepted); deployments set the client, or auth: none on entries of WES instances that require no credentials (upgrade notes in docs/upgrading.md).

Tests and docs:

  • Unit tests of each mode, configured and discovered, audiences, unavailable credentials, unlisted WES instances (client and worker), service infos without credentials, startup errors and warnings (tests/ga4gh/wes/test_credentials.py), and an end-to-end test of a real token fetch from the smoke test's fake WES over HTTPS (test_tls_with_client_token).
  • Smoke test: the fake WES now issues tokens of proWES's client (client credentials grant) and requires them on its WES API over HTTPS, one per audience; the Compose smoke test sets the client.
  • Integration tests (Sapporo, WESkit) set auth: none.
  • Docs: new section "Credentials of WES instances" in docs/access-control.md; configuration, deployment (Secret via prowes.extraEnv), getting started, API errors, upgrade notes, chart README, chart values and base config comments.
  • Chart: prowes.extraEnv must set PROWES_CLIENT_SECRET and the variables that basic of entries names from a Secret (valueFrom.secretKeyRef); rendering fails otherwise (chart tests). Docker Compose passes PROWES_CLIENT_ID and PROWES_CLIENT_SECRET from the host to the app and the worker.

Deviations from the issue text (goal holds):

  • The worker finds the backend of a run by its stored URL with FOCA's BackendList.find, instead of storing a backend id with each run; runs stored before the upgrade work the same way.
  • The tracking task keeps its jwt argument but ignores it, instead of dropping it, so that tasks queued by earlier versions still run during an upgrade; no token is passed on.

Closes #182

Verification

  • coverage run -m pytest --deselect tests/test_chart.py and coverage report: 978 passed, 100% coverage.
  • pytest tests/test_chart.py: 96 passed; helm lint deployment --strict: clean.
  • ruff check, ruff format --check (0.17.5), mypy: clean.
  • mkdocs build --strict: clean.
  • semgrep scan --config=.semgrep --error, ast-grep scan: clean.
  • Not run locally: the Compose smoke and integration tests (CI).

CI: all checks passed on 43d46f4 (run 47246659145): Test, Lint, Docs, Chart, Chart install, Smoke test, Integration (Sapporo, WESkit, Conquest), Scan image, Trivy, codecov. Run 47241368669 on 7920b6c had failed Integration (Conquest): its config from #211 (merged into dev meanwhile) lacked auth: none; fixed, with a unit test validating every smoke and integration overlay (tests/test_overlays.py).

Follow-ups

  • A 401 or 403 of a WES instance is still answered with the same status (as before, documented in docs/api.md); now it means that the WES instance refused proWES's credentials, not the client's. Whether to map it to 500 instead is a separate change.

Declined review findings

Reviewed with the adversarial and quality reviewers in two rounds, and the contract reviewer. Contract review fixed: breaking-change mark in the title, auth: none in the upgrade snippet, Compose passes the client, stored runs tracked only while listed, chart guard requires secretKeyRef, chart README. An adversarial review of these fixes found no high or medium findings; its two low ones are fixed (the guard renders with empty config.custom/wes sections; helper comment). Round 2 fixed: the worker looks a WES instance that the list doesn't yield up again (up to polling_attempts times, polling_wait apart) before setting SYSTEM_ERROR, e.g., while a registry can't be read; docstring and wording of the shared-token warning. Round 1 fixed: the worker task keeps an ignored jwt argument and the app keeps sending jwt: None (tasks queued across a rolling update), one check of listed WES instances (WesClient.require_listed), a startup warning (and docs) when registry entries would share proWES's token without audience_parameter, docs on the worker (not checked on startup), no_credentials in operations, init_app exceptions, test layout.

  • Retrying failed token fetches (adversarial, low): FOCA blocks new fetches for 5 seconds after a failure, longer than the default retry backoff (1 and 2 seconds), so retries would mostly fail the same way; the worker already counts such a failure as a failed poll and keeps polling. Documented in docs/access-control.md instead.
  • Refusing registry entries with auth: client_credentials without audience_parameter (adversarial, medium, alternative fix): not all identity providers support audiences; a warning plus docs (as D-267 did for proTES's shared token) keeps such setups possible.
  • Moving FakeHttp and _registry into a shared test helper module (quality, low): the new test module imports them from test_client_wes.py; a move touches many tests unrelated to this issue.
  • docs/getting-started.md explaining auth: none (quality, low): the sentence before the example already does.
  • Sourcery: fixed the per-request lookup of the backend entry (removed WES instances get no further requests from long-lived clients), the upgrade note on workers of earlier versions, and a test of discovered auth: none. Answered: no credentials in task payloads for old workers (upgrade workers with the app), WesClient token API is internal, the initial run-log fetch already counts towards polling_attempts, backend lookup by stored URL instead of a stored id (deviation above), jwt kept as an ignored argument for queued tasks.
  • Rewrapping some edited Markdown paragraphs (quality round 2, low): rendering is unaffected.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 6 commits December 3, 2026 17:38
proWES authenticates at WES instances with credentials of its own, as
the auth of their entries says: a token of its client at the identity
provider of custom.wes.client_credentials (the default; client ID and
secret in PROWES_CLIENT_ID and PROWES_CLIENT_SECRET), HTTP Basic
credentials from named environment variables, or none. Discovered
WES instances get the credentials of their registry entry.

Credentials are looked up for each request from the current backend
list, with FOCA's backend credentials; WES instances the list no
longer yields get no request (no_credentials, not retried), and
tracking their runs fails. Service infos are read without
credentials. The worker task no longer takes a jwt argument. The
startup check is FOCA's check_backends, which refuses missing
environment variables and warns about basic, none and http.

The smoke test's fake WES now issues tokens of proWES's client and
requires them on its WES API over HTTPS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Access control gets a section on proWES's credentials at WES
instances; configuration, deployment (Secret via prowes.extraEnv),
getting started, API errors and the upgrade notes follow the new
default auth: client_credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The WESkit integration test (#209) lists WESkit without auth, which
now defaults to client_credentials: set auth: none, as for Sapporo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tasks of earlier versions still pass jwt to the tracking task: keep it
as an ignored argument, so that they run after an upgrade. One check
of listed WES instances (WesClient.require_listed) serves the client
and the worker. Docs: only the app checks credentials on startup
(the worker fails to track runs), failed requests name the
no_credentials cause, and init_app documents RuntimeError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Registry entries default to auth: client_credentials, so without
audience_parameter every discovered WES instance gets the token that
the configured ones accept: warn on startup, and document the replay
risk. The app keeps sending jwt: None to the tracking task, which
workers of earlier versions require during a rolling update. Docs
say how failed token fetches affect forwarding and tracking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker set runs to SYSTEM_ERROR after one lookup of their WES
instance, e.g., when a registry couldn't be read when tracking
started. It now looks the instance up again, up to polling_attempts
times, polling_wait seconds apart, before giving up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Extend the WES configuration model to support FOCA credentials, a client-credentials provider, and validation that backend entries fit that provider.

  • pro_wes/config_models.py L6-13, L47-51, L185-191 (+6 small edits)

API

Keep the tracking-task argument compatible with queued work from earlier versions while making clear that the client token is ignored.

  • pro_wes/tasks/track_run_progress.py L14-19, L84-87 (+2 small edits)

Keep sending the legacy task argument during rolling upgrades so workers from earlier versions can accept the task payload.

  • pro_wes/ga4gh/wes/workflow_runs.py L493 (removed lines), L496-498

Uses of the API

Use the current backend entry to authenticate each outbound WES request, refuse requests when the instance is no longer listed, and leave service-info reads unauthenticated.

  • pro_wes/ga4gh/wes/client_wes.py L114-125, L493-516, L546-569 (+13 small edits)
  • pro_wes/ga4gh/wes/routing.py L243-245

Use backend credentials when forwarding and canceling runs, and have the worker retry backend lookups before failing tracking for an unlisted WES instance.

  • pro_wes/ga4gh/wes/workflow_runs.py L555-556, L918, L922 (removed lines)
  • pro_wes/tasks/track_run_progress.py L118-126, L198-253

Implementation

Check configured backends and credential availability at startup, warn about shared registry tokens, and resolve credentials from the current backend list for each request.

  • pro_wes/ga4gh/wes/backends.py L13-39, L48-61, L80-190

Configuration

Require chart-provided WES credential environment variables to come from Kubernetes Secrets, and account for missing or non-map config sections.

  • deployment/templates/_helpers.tpl L162-196, L205, L218-220
  • deployment/values.yaml L40-47, L107-113

Pass proWES's client ID and secret to both Compose services and configure the smoke environment to exercise authenticated WES requests.

  • docker-compose.yaml L55-58, L66-67
  • tests/smoke/compose.yaml L18-21, L27-28
  • tests/smoke/config.yaml L11-14, L25-27

Update the base WES configuration comments to describe the default client-credentials mode and alternatives.

  • pro_wes/config.yaml L238-250

Set integration backends that need no authentication to auth: none under the new default.

  • tests/integration/config.yaml L10-11, L26
  • tests/integration/conquest/config.yaml L11, L36
  • tests/integration/weskit/config.yaml L9-10, L35

Documentation

Explain the credential modes, audience and registry-token behavior, failure cases, and client-token separation for outbound WES requests.

  • docs/access-control.md L53-54, L61-113

Document the new WES configuration fields, client setup, and behavior for runs whose backend is no longer yielded.

  • docs/configuration.md L86-128, L156-160, L175-177

Describe supplying WES credentials from Kubernetes Secrets and the required pod restart after Secret changes.

  • docs/deployment.md L181-224

Clarify that the getting-started example uses an unauthenticated WES backend.

  • docs/getting-started.md L30-32, L40

Explain that requests without available WES credentials are not sent and how the worker reports those failures.

  • docs/operations.md L53-60

Document the breaking default change, worker upgrade requirements, and the loss of tracking for backends no longer in the list.

  • docs/upgrading.md L77-100, L129-130, L542-546

Update the chart README with how to configure proWES's client and opt out for backends that need no credentials.

  • deployment/README.md L27-32

Clarify how WES credential refusals are represented in the API response.

  • docs/api.md L250

Tests

Cover credential modes, audiences, discovered and removed backends, unavailable credentials, unauthenticated service-info reads, and startup validation and warnings.

  • tests/ga4gh/wes/test_credentials.py L1-443

Exercise a real client-credentials token exchange and authenticated WES request over HTTPS in the fake WES used by the smoke test.

  • tests/smoke/fake_wes.py L175-229, L342-400, L485-500 (+5 small edits)

Update backend and client tests for the new default, request authentication, and refusal to send requests for unlisted instances.

  • tests/conftest.py L169
  • tests/ga4gh/wes/test_backends.py L179-196, L468-501, L509-518 (+12 small edits)
  • tests/ga4gh/wes/test_client_wes.py L297-308, L1038-1080, L1163-1199 (+20 small edits)

Adjust retry, routing, workflow, and tracking tests for explicit no-auth fixtures and the worker's handling of legacy tasks and unlisted backends.

  • tests/ga4gh/wes/test_retries.py L634-638
  • tests/ga4gh/wes/test_routing.py L177, L630-637, L644-651
  • tests/ga4gh/wes/test_workflow_runs.py L192, L392, L422-424
  • tests/tasks/test_track_run_progress.py L11-12, L32 (removed lines), L240-305
  • tests/tasks/test_track_run_endpoint.py L82 (removed lines)

Verify Helm rejects literal or ConfigMap-sourced credentials while accepting Secret-backed values and tolerating config sections without backends.

  • tests/test_chart.py L273-280, L478-562

Validate the custom configuration of smoke and integration overlays in unit tests so invalid backend authentication settings fail early.

  • tests/test_overlays.py L1-36

Other changes

Files not grouped.

  • pro_wes/app.py L40-44, L67-71

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 Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e3254d7) to head (43d46f4).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #213   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1404      1451   +47     
=========================================
+ Hits          1404      1451   +47     

☔ 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 December 3, 2026 19:04
@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 43d46f4

#182 feat: authenticate at WES backends · 8 of 10 met

# Requirement Status Notes
1 Support client_credentials, basic, and none for WES backends, with FOCA's client_credentials default and proWES client settings. ✅ Met The config models use FOCA's backend credential types and configure custom.wes.client_credentials with the client ID and secret read from the environment.
2 Send backend credentials on WES requests, never forwarding caller credentials or using credentials from .netrc or redirects. ✅ Met WesClient builds fresh headers and applies the backend's credentials for each request; service-info reads opt out of authentication.
3 Store the backend identifier and discovered entry with each run so the worker can find that backend. 🟡 Partly met The worker resolves the current backend and entry by the stored host URL, but runs do not store a backend identifier or registry entry.
4 Have the worker look up the run backend's credentials for each request, including fresh tokens for long runs. ✅ Met WesClient re-resolves the backend for each request and obtains credentials then; the worker uses the current entry.
5 Fail tracking clearly without sending requests when a run's backend is removed, and drop the tracking task's jwt argument. 🟡 Partly met Removed backends lead to SYSTEM_ERROR without a request, and jwt is ignored, but the argument remains for compatibility with queued tasks.
6 Refuse startup when required credential environment variables are missing and warn about basic, none, and http. ✅ Met The startup backend check validates required variables and emits the requested warnings.
7 Require the client secret and Basic credentials to come from Secrets in the Helm chart. ✅ Met Chart rendering rejects literal values and non-Secret valueFrom sources for these credentials.
8 Test credential modes, configured and discovered backends, worker lookup, and startup checks. ✅ Met The added credential tests cover these cases, including unavailable and unlisted backends.
9 Make the smoke-test WES require and accept only a token of proWES's client from the mock issuer. ✅ Met The fake WES issues client-credentials tokens and checks their issuer, audience, and client identity on its HTTPS WES API.
10 Document WES credentials in access control, configuration, deployment, upgrading, and chart docs. ✅ Met The change updates the requested documentation, including deployment Secret configuration and the breaking default.

@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 7 issues

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and proWES now sends its own bearer token or Basic credentials to configured WES backends; a backend that receives them could retain or replay them, and reverting stops future sends but cannot undo credentials already exposed. By default, backends share a token unless audience-specific tokens are configured.

Blocking findings: pro_wes/ga4gh/wes/client_wes.py:261, pro_wes/ga4gh/wes/workflow_runs.py:499, pro_wes/ga4gh/wes/client_wes.py:249, pro_wes/ga4gh/wes/client_wes.py:543, pro_wes/tasks/track_run_progress.py:121


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

Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/tasks/track_run_progress.py Resolved
Comment thread pro_wes/tasks/track_run_progress.py Resolved
Comment thread tests/ga4gh/wes/test_credentials.py Resolved
Long-lived clients (the worker's) kept the entry found when they were
created: a WES instance removed from the backend list kept getting
requests. require_listed() now looks it up again for each request.
Upgrade notes: upgrade workers together with the app. Test of a
discovered WES instance with auth: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

New gaps against the linked issues

Comment thread deployment/values.yaml Resolved
uniqueg and others added 2 commits December 3, 2026 22:52
Rendering fails if prowes.extraEnv sets PROWES_CLIENT_SECRET, or a
variable that the basic of a backend entry in config names, from a
value instead of a Secret (valueFrom), as #182 asks: credentials of
WES instances come from Secrets only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chart refuses WES credentials in prowes.extraEnv unless they come
from valueFrom.secretKeyRef (a ConfigMap or field ref was accepted).
Docker Compose passes PROWES_CLIENT_ID and PROWES_CLIENT_SECRET from
the host to the app and the worker, as proTES does.

Docs: the upgrade snippet for the former WES instance sets auth: none;
stored runs are tracked only while their WES instance stays listed;
access control and the chart README say where the client comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uniqueg uniqueg changed the title feat: authenticate at WES backends feat!: authenticate at WES backends Dec 4, 2026
uniqueg and others added 3 commits December 4, 2026 02:07
The chart's check of WES credentials in prowes.extraEnv failed with a
template error when config.custom or config.custom.wes was null or no
map (e.g., an empty `wes:`); such sections now count as no backends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Conquest integration test (#211, merged into dev meanwhile) lists
Conquest without `auth`, which now defaults to client_credentials, so
the app and the worker refused the config. It sets `auth: none`.

A unit test validates the app config of every smoke and integration
overlay, so that such configs fail locally, not only in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uniqueg
uniqueg merged commit e042e80 into dev Dec 4, 2026
47 checks passed
@uniqueg
uniqueg deleted the issue-182-backend-credentials branch December 4, 2026 02:06
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: authenticate at WES backends

1 participant