Repository navigation
feat(auth)!: require tokens for task operations - #240
Conversation
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]>
Reviewer's GuideThis 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 accesssequenceDiagram
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
Flow diagram for proTES security startup validationflowchart 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"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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;
devis merged into this branch.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);WWW-Authenticate: Bearerchallenge (error="invalid_token"if a token was sent). This is a shim inpro_tes/security.pyuntil FOCA 0.16 adds the challenge (build!: require FOCA 0.17 and Python 3.13 #214).pro_tes/access_control/model.conf):usermay create, list, read and cancel tasks (GET,HEAD,POSTon/tasksand/tasks/:id);adminmay do everything, including FOCA's permissions API at/admin/access-control/permissions;claim_groupsandgroup_mapping.admin, unlesscustom.access_control.require_adminis false;user, or ifgroup_mappingis set withoutclaim_groups.config.dev.yaml(a placeholder issuer, any audience, no admins required);configvalue for the overlay (ConfigMap,FOCA_CONFIG_OVERLAY, and a checksum annotation in both deployments).tests/conftest.py, so the clients send user tokens by default;tests/ga4gh/tes/conftest.py;tests/ga4gh/tes/test_access_control.pyandtests/test_security.py.access-control.mdrewritten (authentication, roles, permissions API, deployment settings).api.md,configuration.md,getting-started.md,upgrading.md,development.mdand the README are updated.Breaking:
Verification
coverage run -m pytestandcoverage report: 189 tests pass, 100% coverage.MONGODB_TEST_URI): 189 tests pass.ruff check,ruff format --check,mypy pro_tes tests,ast-grep scan,semgrep --config=.semgrep,actionlint,helm lintandmkdocs build --strictare clean.access_control/model.conf.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_tokenby 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
pvalues), 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
config.🤖 Generated with Claude Code