Repository navigation
feat!: require access tokens from clients - #184
Conversation
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]>
Reviewer's GuideAPIDeclare bearer-token security for WES operations while keeping service info public.
Uses of the APISet the authenticated caller as the run owner before invoking run operations, replacing any request-supplied owner.
ImplementationResolve issuer-namespaced run owners from validated token claims and warn when no issuer is trusted.
Extend the smoke-test fake WES with an HTTPS OpenID Connect provider and access-token generator.
ConfigurationRequire authentication in the base app configuration and document its issuer, audience, and token-type settings.
Add deployment examples and update Helm settings and notes to guide issuer and audience configuration.
DocumentationExplain token validation, public endpoints, run ownership, deployment setup, and the breaking upgrade impact.
TestsConfigure authenticated test clients and identity-provider fixtures, then test token validation, public routes, ownership, and startup behavior.
Adapt existing endpoint and workflow tests to authenticate requests and seed runs with their owner's identity.
Exercise the authenticated smoke flow, including missing and invalid tokens and isolation between users.
Update specification comparisons and chart tests for bearer security and the no-issuer warning.
Adjust the app startup test documentation for the now-authenticated API.
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 #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. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 015863c #181 feat: require access tokens from clients · 7 of 7 met
|
There was a problem hiding this comment.
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
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]>
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]>
Summary
The WES API now requires access tokens from clients, as proTES does (part of #120; backend credentials follow with #182):
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 setissuersandaudience). This uses a globalsecurity: bearerAuthinapi/additions.openapi.yamlanddisable_auth: False. Only access tokens (typ: at+jwt, RFC 9068) are accepted. Requests without a valid token get401problem details with a Bearer challenge. If no issuer is trusted, a warning is logged on startup (pro_wes.security.check_auth).user_id:<issuer>|<sub>, or the issuer'snamespace; 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).user_idsent 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 get403.403.foca.testing.issuer).foca_clientand the newTokenClientsend a token ofaliceby default, and seeded runs carry her owner.tests/test_security.py(owner and startup checks) andtests/ga4gh/wes/endpoints/test_auth.pycover:401without a token and with expired, other-audience, non-access, foreign-issuer and malformed tokens; the public endpoints; ownership across users; anduser_idin requests./oidc/, over HTTPS like the WES API.check.shsends tokens with every request and checks401without a token and with an invalid one.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.mdanddeployment/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 --strictwith the three value sets of CI: passed.mkdocs build --strict: passed.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).adversarial-reviewerandquality-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):
|own no runs (e9c2f8b). FOCA 0.22 refuses|only in explicit namespaces. Also added a regression test that tokens without a subject get401.|.401from FOCA, not403.mkdocs build --strictpassed.Declined review findings
requireAudience: truein the chart (low): foca-common 0.4.0'scheckAudiencerefuses to render without an audience even when no issuer is set (checked withhelm 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.|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