Skip to content

feat(auth)!: require tokens for task operations - #240

Merged
uniqueg merged 6 commits into
devfrom
feat/require-tokens
Oct 23, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/require-tokens

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Requires access tokens and roles for all operations on tasks, with FOCA's authentication and access control, as in cloud-registry.

Closes #212

Was stacked on #239 (#159, 100% coverage), which is merged; dev is merged into this branch.

  • Authentication:
    • all TES endpoints except GET /service-info, the specification and the Swagger UI require a bearer token of a trusted issuer (security.auth.issuers), for a configured audience (security.auth.audience);
    • 401 responses carry a WWW-Authenticate: Bearer challenge (error="invalid_token" if a token was sent). This is a shim in pro_tes/security.py until FOCA 0.16 adds the challenge (build!: require FOCA 0.17 and Python 3.13 #214).
  • Access control (FOCA/casbin, pro_tes/access_control/model.conf):
    • the role user may create, list, read and cancel tasks (GET, HEAD, POST on /tasks and /tasks/:id);
    • the role admin may do everything, including FOCA's permissions API at /admin/access-control/permissions;
    • groups of the identity provider get roles via claim_groups and group_mapping.
  • Generic config, no defaults (decision on the issue, 2026-10-22):
    • the base config has no issuers, audience or groups;
    • FOCA refuses access control without issuers, and issuers without an audience;
    • proTES refuses to start without a group of the role admin, unless custom.access_control.require_admin is false;
    • it warns if no group has the role user, or if group_mapping is set without claim_groups.
  • Deployment:
    • Docker Compose applies config.dev.yaml (a placeholder issuer, any audience, no admins required);
    • the smoke test has its own overlay and a fake identity provider in its fake TES, and checks 401, 403 and the admin role;
    • the Helm chart gets a config value for the overlay (ConfigMap, FOCA_CONFIG_OVERLAY, and a checksum annotation in both deployments).
  • Tests:
    • a mock identity provider in tests/conftest.py, so the clients send user tokens by default;
    • the helpers of the TES API move to tests/ga4gh/tes/conftest.py;
    • new tests/ga4gh/tes/test_access_control.py and tests/test_security.py.
  • Docs: access-control.md rewritten (authentication, roles, permissions API, deployment settings). api.md, configuration.md, getting-started.md, upgrading.md, development.md and the README are updated.

Breaking:

Verification

  • coverage run -m pytest and coverage report: 189 tests pass, 100% coverage.
  • With MongoDB 7 (MONGODB_TEST_URI): 189 tests pass.
  • ruff check, ruff format --check, mypy pro_tes tests, ast-grep scan, semgrep --config=.semgrep, actionlint, helm lint and mkdocs build --strict are clean.
  • The wheel contains access_control/model.conf.
  • Reviews: Sourcery (one thread, answered); two rounds of adversarial review and one quality review before pushing; findings fixed except as listed below.
  • CI: all checks pass (also after the test commit 01775fa) on Python 3.10 and 3.12, with MongoDB 7.0, and for the Compose smoke test (with the fake identity provider: 401, 403 and the admin role), docs, static analysis and CodeQL.

Declined review findings

  • Removing the Basic-auth plumbing of task creation: feat!: call TES backends with service tokens #213 replaces it with credentials of proTES for TES instances. The test now asserts that no Basic credentials are forwarded (test_create_task_no_basic_auth).

  • A test of the Helm chart: the chart is replaced in build(chart)!: use the FOCA library chart #216. I rendered and linted it manually.

  • IdP outages marked as invalid_token by the challenge shim: FOCA 0.15 doesn't tell the shim why a token was rejected. This goes away with FOCA 0.16 (build!: require FOCA 0.17 and Python 3.13 #214).

  • Sourcery: deleting all rules locks out admins: with no policy rows, casbin still evaluates the matcher once (with empty p values), so the admin bypass holds. The configured rules also can't be deleted through the permissions API (409). A test covers this.

  • Sourcery assessment: users may list, read and cancel all tasks: this is how proTES behaved before (without any authentication), and the docs say so. Restricting users to their own tasks is a separate design decision, not part of feat(auth)!: require tokens for task operations #212.

Follow-ups

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 23, 2026 00:59
The relay caught database errors where none can occur, and kept logs of
incoming tasks, which the API rejects (they are read-only). proTES now
always creates the logs itself: logs that a middleware adds are neither
stored nor relayed. convert_time() loses its unused allow_none
parameter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test the error branches of task creation, listing and the database
connector, the model conversion, the middlewares without JSON bodies,
run_app(), and that clients can't set logs. Fix the backend order in
test_create_task_next_backend, so that it always tries the unusable
backend first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measure coverage in the test job, fail below 100% (fail_under), upload
it to Codecov (failing only on pushes) and require 100% of the project
and of the changes of pull requests there (codecov.yml). Document the
requirement.

Closes #159

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Enable FOCA's authentication and access control for the TES API: all
operations on tasks require access tokens of trusted issuers, for the
configured audiences, and the role user or admin, which groups of the
identity provider get via group_mapping. GET /service-info and the
Swagger UI stay public. 401 responses get a Bearer challenge (until
FOCA 0.16 adds it).

The issuers, the audience and the groups are deployment settings
without defaults: FOCA refuses access control without issuers and
issuers without audience, and the app refuses to start without a group
of the role admin (unless custom.access_control.require_admin is
false). Docker Compose uses config.dev.yaml, the smoke test a fake
identity provider in its fake TES backend, and the Helm chart gets a
config value for the overlay. The test helpers of the TES API move to
tests/ga4gh/tes/conftest.py.

BREAKING CHANGE: clients must send access tokens, and deployments must
set the trusted issuers, the audience and the groups of the roles. HTTP
Basic credentials can no longer be passed through to TES instances.

Closes #212

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

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR makes FOCA-issued bearer tokens and mapped roles mandatory for task and permissions operations, wires the required security configuration through Compose and Helm deployments, adds startup validation and unauthorized challenges, updates task forwarding semantics, and provides mocked-IdP, smoke, and 100%-coverage validation.

Sequence diagram for authenticated task access

sequenceDiagram
    actor Client
    participant FOCA as FOCA Auth and Access Control
    participant API as TES API
    participant Store as Task Store

    Client->>FOCA: HTTP request with Bearer token
    FOCA->>FOCA: validate_token
    alt token missing or invalid
        FOCA-->>Client: 401 Unauthorized with WWW-Authenticate
    else token valid but role insufficient
        FOCA-->>Client: 403 Forbidden
    else user role
        FOCA->>API: authorize task operation
        API->>Store: create, read, list, or cancel task
        Store-->>API: task result
        API-->>Client: TES response
    else admin role
        FOCA->>API: authorize any operation
        API-->>Client: operation response
    end
Loading

Flow diagram for proTES security startup validation

flowchart TD
    Start["Initialize proTES"] --> Load["Load base config and overlay"]
    Load --> FOCA["Create FOCA application"]
    FOCA --> Auth{"Trusted issuers and audience valid?"}
    Auth -- No --> Fail["Refuse to start"]
    Auth -- Yes --> Roles["check_role_groups"]
    Roles --> Admin{"Admin group mapped?"}
    Admin -- No and required --> Fail
    Admin -- Yes or optional --> Ready["Start TES API with access control"]
Loading

File-Level Changes

Change Details Files
Enforce bearer-token authentication and role-based authorization across the TES and FOCA permissions APIs, with startup validation for deployment security configuration and RFC 6750 challenges for unauthorized responses.
  • Enabled FOCA authentication for protected endpoints while keeping service info, OpenAPI, and Swagger UI public.
  • Added Casbin/FOCA policies for user task operations and unrestricted admin access, including the permissions API.
  • Added issuer, audience, group-claim, role-mapping, and required-admin validation with startup warnings/errors.
  • Added a Flask response hook that supplies Bearer challenges, including invalid_token for rejected bearer tokens.
pro_tes/config.yaml
pro_tes/access_control/model.conf
pro_tes/security.py
pro_tes/app.py
pro_tes/config_models.py
pro_tes/api/additions.openapi.yaml
Adapt deployment configuration and operational documentation to the new authentication and access-control requirements.
  • Added development and smoke-test config overlays defining identity-provider and role settings.
  • Mounted Helm config overlays into both web and worker deployments, propagated FOCA_CONFIG_OVERLAY, and added config checksums for rollout updates.
  • Updated Compose, Helm, README, API, access-control, configuration, development, getting-started, and upgrade guidance for tokens, roles, permissions, and breaking credential-forwarding behavior.
config.dev.yaml
docker-compose.yaml
deployment/values.yaml
deployment/templates/protes/protes-config.yaml
deployment/templates/protes/protes-deployment.yaml
deployment/templates/protes/celery-deployment.yaml
deployment/README.md
README.md
docs/access-control.md
docs/api.md
docs/configuration.md
docs/development.md
docs/getting-started.md
docs/index.md
docs/upgrading.md
Revise task forwarding and task-log handling so client authorization headers are not treated as TES Basic credentials and client-supplied server-managed fields are excluded.
  • Stopped forwarding HTTP Basic credentials from task creation and added validation coverage for the new behavior.
  • Always initialize proTES-managed logs and strip creation_time and logs before forwarding tasks.
  • Simplified task update and time-conversion helpers while preserving backend task conversion and forwarding metadata behavior.
pro_tes/ga4gh/tes/task_runs.py
pro_tes/utils/models.py
Add comprehensive authentication, authorization, configuration, deployment, and smoke-test coverage, while enforcing complete unit-test coverage in CI.
  • Added mocked OIDC discovery, JWKS, user-info, token generation, and role-aware client fixtures.
  • Added tests for allowed, forbidden, unauthorized, public, HEAD, and permissions-API requests plus security startup validation.
  • Extended the smoke test with a fake identity provider and checks for 401, 403, and admin access.
  • Enabled coverage reporting with a 100% threshold and Codecov project/patch targets.
tests/conftest.py
tests/config_overlay.yaml
tests/ga4gh/tes/conftest.py
tests/ga4gh/tes/test_access_control.py
tests/test_security.py
tests/smoke/check.sh
tests/smoke/config.yaml
tests/smoke/fake_tes.py
.github/workflows/checks.yaml
codecov.yml
pyproject.toml
Refactor and expand existing test fixtures and edge-case coverage to support the secured application and preserve task-processing behavior.
  • Moved shared TES fixtures into the TES test package and updated endpoint tests to use authenticated clients.
  • Added coverage for task payload rejection, missing JSON, resource forwarding, duplicate IDs, invalid database documents, and middleware edge cases.
  • Packaged the Casbin model file in the wheel and updated contributor guidance for mandatory tests and coverage.
tests/ga4gh/tes/test_server.py
tests/ga4gh/tes/test_models.py
tests/plugins/middlewares/task_distribution/test_distance.py
tests/plugins/middlewares/task_distribution/test_random.py
tests/utils/test_db.py
CONTRIBUTING.md

Assessment against linked issues

Issue Objective Addressed Explanation
#212 Require valid access tokens for task operations, enforce the default user/admin roles, and keep the service-info endpoint, specification, and Swagger UI public. ✅
#212 Keep identity-provider, audience, and group mappings generic and deployment-configured, with startup checks for required settings and an admin mapping. ✅
#212 Document how operators configure access control, including how to make individual read operations public or require login using FOCA spec patches. ❌ The PR documents changing access-control policies through a config overlay, but does not document or demonstrate FOCA spec patches for changing per-operation authentication requirements, such as making reads public.

Possibly linked issues


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

@uniqueg
uniqueg marked this pull request as ready for review October 23, 2026 00:07

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="pro_tes/access_control/model.conf" line_range="27" />
<code_context>
+
+[matchers]
+# admins may do everything
+m = g(r.sub, "admin") || ((p.sub == "*" || g(r.sub, p.sub)) && keyMatch2(r.obj, p.obj) && regexMatch(r.act, "^(" + p.act + ")$"))
</code_context>
<issue_to_address>
**Removing all rules locks out admins**

When an admin deletes every policy rule through the runtime permissions API, casbin evaluates this matcher against policy rows; after the last row is deleted, the `g(r.sub, "admin")` bypass is never evaluated, so admins lose access to the permissions API and all protected endpoints until restart restores configured policies.

Keep an undeletable policy row or otherwise ensure the admin bypass remains enforceable when the policy set is empty.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the configured user role can list, read, and cancel every task, while admin can do everything; if the group mapping or these permissions are too broad, task data can be exposed or tasks canceled, and reverting cannot undo those effects. This is a system-wide access policy decision whose mistake may not produce an obvious failure signal.

Blocking findings: pro_tes/access_control/model.conf:27


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

Comment thread pro_tes/access_control/model.conf Resolved
uniqueg and others added 2 commits October 23, 2026 02:15
Admins can't delete the configured policies through the permissions
API (409), so the policy set never becomes empty and admins keep
access.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	tests/ga4gh/tes/test_server.py
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bada721) to head (3fc3fa4).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #240   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        19    +1     
  Lines          860       900   +40     
=========================================
+ Hits           860       900   +40     

☔ 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 merged commit 46d3bc9 into dev Oct 23, 2026
14 checks passed
@uniqueg
uniqueg deleted the feat/require-tokens branch October 23, 2026 00:38
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(auth)!: require tokens for task operations

1 participant