Skip to content

feat!: require access tokens from clients - #184

Merged
uniqueg merged 8 commits into
devfrom
feat/181-client-tokens
Nov 19, 2026
Merged

uniqueg merged 8 commits into
devfrom
feat/181-client-tokens

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The WES API now requires access tokens from clients, as proTES does (part of #120; backend credentials follow with #182):

  • Authentication: all operations except GET /service-info, the specification and the Swagger UI require access tokens of the trusted issuers (security.auth; the base config trusts none, so a deployment must set issuers and audience). This uses a global security: bearerAuth in api/additions.openapi.yaml and disable_auth: False. Only access tokens (typ: at+jwt, RFC 9068) are accepted. Requests without a valid token get 401 problem details with a Bearer challenge. If no issuer is trusted, a warning is logged on startup (pro_wes.security.check_auth).
  • Run ownership: each run belongs to the caller that created it, stored as user_id:
    • The owner is the token's subject namespaced by its issuer: <issuer>|<sub>, or the issuer's namespace; an empty namespace keeps the subject bare. Issuer namespacing is the default even with a single issuer, as in FOCA 0.23 (foca#773), so owners stay the same after that upgrade (pro_wes.security.owner_of, current_owner).
    • The controllers set the owner and drop any user_id sent with the request, so the existing owner checks of the run store apply: callers list, read and cancel only their own runs, and requests for runs of others get 403.
    • Tokens whose subject can't be namespaced get 403.
  • Tests:
    • The test overlay trusts FOCA's local identity provider (foca.testing.issuer).
    • foca_client and the new TokenClient send a token of alice by default, and seeded runs carry her owner.
    • New tests/test_security.py (owner and startup checks) and tests/ga4gh/wes/endpoints/test_auth.py cover: 401 without a token and with expired, other-audience, non-access, foreign-issuer and malformed tokens; the public endpoints; ownership across users; and user_id in requests.
  • Smoke test:
    • The fake WES is also the identity provider: discovery, JWKS and a token endpoint below /oidc/, over HTTPS like the WES API.
    • check.sh sends tokens with every request and checks 401 without a token and with an invalid one.
    • It also checks that a second user can't list, read or cancel the first user's runs.
  • Docs: docs/access-control.md (rewritten: authentication and run ownership), configuration.md, api.md (deviation: security scheme; 401/403), upgrading.md (breaking: authentication, runs stored without an owner), deployment.md ("Authentication"), getting-started.md, development.md, index.md and deployment/values.yaml (commented example). Client authentication needs no Secrets in the chart; its notes (and README) now warn while no token issuer is set (instead of warning about missing authentication).

Breaking: clients must send access tokens, and deployments must configure issuers. Runs stored before the upgrade have no owner and can't be read anymore (see the upgrade notes).

Closes #181

Verification

Local, on the branch merged with origin/dev (incl. #183):

  • coverage run -m pytest -W ignore::DeprecationWarning (with Helm 3.18.6 and the library chart built): 665 passed, coverage 100%.
  • pre-commit run --all-files (ruff, ruff format, mypy, semgrep, semgrep rule tests, ast-grep, ast-grep rule tests, uv lock check, file checks): passed. gitleaks and actionlint did not run locally (no Go toolchain/actionlint version in the sandbox; no workflow changed); CI runs them.
  • helm lint deployment --strict with the three value sets of CI: passed.
  • mkdocs build --strict: passed.
  • Smoke test (tests/smoke/check.sh) not run locally (no Docker in the sandbox): CI runs it. The fake identity provider's tokens were checked against FOCA's validation in review (PyJWT, RS256, audience, issuer).
  • Reviews: adversarial-reviewer and quality-reviewer, 2 rounds; all medium and the behavioural low findings fixed.

CI: all checks passed on the first push (Lint, Docs, Test, Chart, Chart install, Smoke test with authentication on, codecov patch/project).

Sourcery (5 threads, all answered and resolved):

  • Fixed: issuers whose URL (the default namespace) contains | own no runs (e9c2f8b). FOCA 0.22 refuses | only in explicit namespaces. Also added a regression test that tokens without a subject get 401.
  • Fixed (docs, 58162fa): the migration owner is given per configured namespace (also bare); the docs say to scale proWES down before upgrading, so that old pods create no ownerless runs, and that namespaces must differ and must not contain |.
  • Not reachable: issuers sharing a namespace (FOCA refuses that on startup); missing identity claim gets 401 from FOCA, not 403.
  • After the fixes, locally: 667 passed, coverage 100%; pre-commit on the changed files and mkdocs build --strict passed.

Declined review findings

  • requireAudience: true in the chart (low): foca-common 0.4.0's checkAudience refuses to render without an audience even when no issuer is set (checked with helm template), while FOCA requires an audience only for configured issuers. Turning it on would make every install fail until auth is configured. Instead the app refuses to start with issuers but no audience (FOCA), and the chart's notes warn while no issuer is set.
  • Bare | subjects with a single empty-namespace issuer (low): proWES refuses them (403), FOCA 0.23 would accept them bare. The stricter behaviour is safe; the docs say FOCA 0.23 namespaces the same way by default.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 6 commits November 19, 2026 01:32
The WES API now requires access tokens of the trusted issuers
(`security.auth`, none by default), as in proTES; `GET /service-info`,
the specification and the Swagger UI stay public. Requests without a
valid token get `401` with a Bearer challenge.

Each run belongs to the caller that created it: the subject of its
token, namespaced by its issuer (`<issuer>|<subject>`, or the issuer's
`namespace`), as FOCA 0.23 does, so that owners survive that upgrade.
The controllers set it as `user_id`, replacing any value of the
request, so that the existing owner checks of the run store apply.

A warning is logged on startup if no issuer is trusted. The tests trust
FOCA's local identity provider and send its tokens by default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fake WES is also the identity provider of the smoke test: it serves
its discovery document and keys over HTTPS below `/oidc/`, and tokens of
any user at `GET /oidc/token` (`fake_wes.py token <user>`). The test
sends them with every request but the service info, and checks `401`
without and with an invalid token, and that another user can't list,
read or cancel the runs of the first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The runs that the tests of #183 store get the owner of the test user,
as the run store now checks owners. Also from the review: tests of
`_set_owner`, of `user_id` in requests and of the startup check; no
private FOCA helper in `TokenClient`; uniform `Raises` of the
controllers; clearer comments and docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chart's notes, README, deployment and development docs no longer say
that the WES API is served without authentication; the notes warn while
`config.security.auth.issuers` is unset instead. The fake WES of the
smoke test gets a key ID per start, so that proWES fetches its new key
after a restart, and tokens that last an hour.

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

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Declare bearer-token security for WES operations while keeping service info public.

  • pro_wes/api/additions.openapi.yaml L25-29, L37-38, L152-156

Uses of the API

Set the authenticated caller as the run owner before invoking run operations, replacing any request-supplied owner.

  • pro_wes/ga4gh/wes/controllers.py L24-43, L57-63, L84-90 (+8 small edits)

Implementation

Resolve issuer-namespaced run owners from validated token claims and warn when no issuer is trusted.

  • pro_wes/app.py L18, L27-28, L78-79
  • pro_wes/security.py L1-96

Extend the smoke-test fake WES with an HTTPS OpenID Connect provider and access-token generator.

  • tests/smoke/fake_wes.py L70-82, L218-260, L505-515 (+5 small edits)

Configuration

Require authentication in the base app configuration and document its issuer, audience, and token-type settings.

  • pro_wes/config.yaml L28-41 (+3 small edits)

Add deployment examples and update Helm settings and notes to guide issuer and audience configuration.

  • deployment/templates/NOTES.txt L16-21
  • deployment/templates/_helpers.tpl L7-14
  • deployment/values.yaml L29-38
  • tests/smoke/config.yaml L6-15

Documentation

Explain token validation, public endpoints, run ownership, deployment setup, and the breaking upgrade impact.

  • deployment/README.md L22-25
  • docs/access-control.md L3 (removed lines), L5-89
  • docs/api.md L22, L173-177
  • docs/configuration.md L172-176, L270
  • docs/deployment.md L22 (removed lines), L135-156
  • docs/development.md L115-116, L225-229
  • docs/getting-started.md L55-70
  • docs/index.md L48
  • docs/upgrading.md L11-32

Tests

Configure authenticated test clients and identity-provider fixtures, then test token validation, public routes, ownership, and startup behavior.

  • tests/conftest.py L5-15, L59-120, L228-257 (+4 small edits)
  • tests/ga4gh/wes/endpoints/test_auth.py L1-182
  • tests/test_security.py L1-140

Adapt existing endpoint and workflow tests to authenticate requests and seed runs with their owner's identity.

  • tests/ga4gh/wes/test_backends.py L12-421 (6 small edits)
  • tests/ga4gh/wes/test_error_responses.py L22-276 (5 small edits)
  • tests/ga4gh/wes/test_run_request_limits.py L25-120 (4 small edits)
  • tests/ga4gh/wes/test_workflow_runs.py L869-873, L949-953 (+9 small edits)

Exercise the authenticated smoke flow, including missing and invalid tokens and isolation between users.

  • tests/smoke/check.sh L53-59, L117-123, L146-151 (+6 small edits)

Update specification comparisons and chart tests for bearer security and the no-issuer warning.

  • tests/ga4gh/wes/test_spec.py L137-140
  • tests/test_chart.py L538-540, L548-562

Adjust the app startup test documentation for the now-authenticated API.

  • tests/test_app.py L139

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 Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (94c8b82) to head (58162fa).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #184   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        20    +1     
  Lines          993      1039   +46     
=========================================
+ Hits           993      1039   +46     

☔ 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 November 19, 2026 02:02
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 015863c

#181 feat: require access tokens from clients · 7 of 7 met

# Requirement Status Notes
1 Require access tokens from configured issuers for run operations; keep service info, the specification and Swagger UI public. ✅ Met The API declares global bearer security, disables disable_auth, and exempts GET /service-info; endpoint tests cover all three public endpoints.
2 Reject requests without a valid token with 401, a Bearer challenge and problem details. ✅ Met Authentication tests check the 401 response and Bearer challenge for missing, malformed, expired, wrong-audience, wrong-issuer and non-access tokens.
3 Store each run's owner's FOCA-style namespaced subject in user_id and restrict listing, reading, status and cancellation to that owner. ✅ Met Controllers set the token-derived owner, and tests check stored ownership and that another user cannot list, read, or cancel the run.
4 Keep the default config safe without trusted issuers and log a startup warning when none are set. ✅ Met The base config trusts no issuers, and check_auth logs the warning during app startup.
5 Run the smoke test with authentication enabled using a mock issuer, checking missing and invalid tokens and the authenticated smoke flow. ✅ Met The fake WES serves discovery, JWKS and tokens; the smoke script sends tokens and checks unauthenticated requests and cross-user run access. The PR description reports the CI smoke test passed.
6 Add unit tests for authentication and ownership, including expired, wrong-issuer, wrong-audience and ID tokens. ✅ Met test_auth.py and test_security.py cover the requested token cases, public endpoints, ownership, request-supplied user_id, and startup checks.
7 Document authentication, its configuration, 401 responses, and the upgrade impact; describe the settings in the chart docs and values. ✅ Met The change updates the access-control, configuration, API, upgrading, deployment and getting-started docs, and adds a commented issuer/audience example to chart values.

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pro_wes/security.py" line_range="51" />
<code_context>
+    namespace = issuer if settings.namespace is None else settings.namespace
+    if not namespace:
+        return None if NAMESPACE_SEPARATOR in subject else subject
+    return f"{namespace}{NAMESPACE_SEPARATOR}{subject}"
+
+
</code_context>
<issue_to_address>
**Different issuers share run access**

When two trusted issuers use the same configured namespace and issue the same subject, `owner_of` uses the configured namespace instead of distinguishing the issuers, so `current_owner` returns the same owner for both identities and run access checks let either caller read or cancel the other's runs.

Include the issuer in the serialized owner identity so different issuers cannot produce the same owner.
</issue_to_address>

### Comment 2
<location path="pro_wes/security.py" line_range="51" />
<code_context>
+    namespace = issuer if settings.namespace is None else settings.namespace
+    if not namespace:
+        return None if NAMESPACE_SEPARATOR in subject else subject
+    return f"{namespace}{NAMESPACE_SEPARATOR}{subject}"
+
+
</code_context>
<issue_to_address>
**Different callers share run access**

When trusted identities use namespaces or subjects containing the separator and those values serialize to the same string, `owner_of` concatenates the namespace and subject without escaping the separator, so `current_owner` returns the same owner for distinct identities and run access checks let either caller list, read, or cancel the other's runs.

Serialize the namespace and subject unambiguously so distinct pairs always produce distinct owners.
</issue_to_address>

### Comment 3
<location path="pro_wes/config.yaml" line_range="95" />
<code_context>
-      disable_auth: True
+      # Access tokens required (cf. `security.auth`); disabling it serves the
+      # WES API to anyone, and runs have no owner
+      disable_auth: False
       connexion:
         strict_validation: True
</code_context>
<issue_to_address>
**Old pods create ownerless runs**

When a rolling upgrade leaves old and new replicas serving requests against shared storage, old replicas still accept run requests without authentication and store runs without an owner; after they are replaced, the new access checks reject those runs, leaving them inaccessible to their callers.

Prevent old replicas from accepting run requests during the transition before enabling the new owner checks.

Also at `pro_wes/ga4gh/wes/controllers.py:63`.
</issue_to_address>

### Comment 4
<location path="pro_wes/security.py" line_range="77-79" />
<code_context>
+    owner = None
+    if isinstance(subject, str) and subject and isinstance(issuer, str):
+        owner = owner_of(subject=subject, issuer=issuer, conf=conf)
+    if owner is None:
+        logger.warning("Request refused: no owner for the subject of its token")
+        raise Forbidden
+    return owner
+
</code_context>
<issue_to_address>
**Missing claims return wrong status**

When a token passes issuer validation but omits the configured identity claim, `current_owner` raises `Forbidden`, so run handlers return `403` even though the access-control documentation says tokens without a subject claim are invalid and receive `401`.

Reject tokens missing the configured identity claim as invalid during token validation so they receive `401`.

Also at `docs/access-control.md:82-83`.
</issue_to_address>

### Comment 5
<location path="docs/upgrading.md" line_range="24" />
<code_context>
+token namespaced by its issuer, and only that caller lists, reads and
+cancels it. Runs stored before have no owner and can't be read anymore:
+let them finish (or cancel them) before upgrading, or set their `user_id`
+in the database to the owner (`<issuer>|<subject>`, see [Run
+ownership](access-control.md#run-ownership)).
+
</code_context>
<issue_to_address>
**Migration assigns wrong owners**

When a deployment uses a custom or empty issuer namespace while migrating runs stored before the upgrade, operators following the `<issuer>|<subject>` migration instruction assign the wrong `user_id` when an issuer has a custom or empty namespace; `current_owner()` then derives a different owner, so the migrated runs remain inaccessible to their callers.

Make the upgrade instructions specify the effective configured namespace, including the bare-subject case for an empty namespace.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and a flaw in token validation or run-owner mapping could let one caller list, read, or cancel another caller’s runs; any run data exposed or cancellation already performed would not be undone by reverting. The change also makes access depend on each deployment’s trusted issuer and audience configuration.

Blocking findings: pro_wes/security.py:51, pro_wes/security.py:51, pro_wes/config.yaml:95, pro_wes/security.py:79, docs/upgrading.md:24


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

Comment thread pro_wes/security.py Resolved
Comment thread pro_wes/security.py Resolved
Comment thread pro_wes/config.yaml Resolved
Comment thread pro_wes/security.py Resolved
Comment thread docs/upgrading.md Resolved
uniqueg and others added 2 commits November 19, 2026 03:19
Issuers are the namespace of their subjects by default, and FOCA 0.22
refuses `|` in explicit namespaces only, so an issuer URL with `|` could
yield the same owner as another issuer's subject with `|`. Such issuers
own no runs now. Also test that tokens without a subject get `401`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Give the owner for migrated runs per configured namespace (also bare),
say to scale proWES down before upgrading so that old pods create no
ownerless runs, and that namespaces must differ and lack `|`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 168d848 into dev Nov 19, 2026
30 checks passed
@uniqueg
uniqueg deleted the feat/181-client-tokens branch November 19, 2026 02:33
uniqueg added a commit that referenced this pull request Nov 19, 2026
Conflict in the docstring of `init_app` (pro_wes/app.py): both notes
kept.

With tokens required, the check of run request bodies answered
unauthenticated run requests with 415 or 400 instead of 401
(`test_no_token[post-/runs]`). It now refuses a body only if the
request has a valid token (or auth is disabled), and leaves the others
to Connexion, which answers 401 before it reads the body; tokens are
validated a second time only for refused bodies. Tests:
`test_run_request_body_after_token`, `test_run_request_body_auth_disabled`;
the run of `test_other_requests_not_checked` gets the caller as owner.
Docs: the order of 401 and body errors in docs/api.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: require access tokens from clients

1 participant