From d4da0583a774b39163c2af2927fb4c1c138bffa8 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 5 Dec 2026 22:40:11 +0100 Subject: [PATCH 1/4] fix!: provenance only for the task owner Admins no longer get the provenance of tasks they don't own: the rule `admins-get-provenance` is removed from the base config, so that `GET /tasks/{id}/provenance` answers only to the task's owner. Everyone else, admins included, gets `403 Forbidden`, also for unknown tasks, as for `GET /tasks/{id}`. Admins of a TES gateway must not see the details of other users' tasks. Tests cover the owner (200), other users, outsiders and admins (403 for existing and unknown tasks, GET and HEAD), no token (401), the base config's rules, and overlays that still remove the rule (startup stops with FOCA's error). Docs (API, access control, operations, OpenAPI) and the upgrade notes are updated. BREAKING CHANGE: admins get `403` for the provenance of tasks they don't own; overlays with `admins-get-provenance: null` must drop that entry. Closes #568 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FSoqPsbB5s4NvhhYYcDJk --- docs/access-control.md | 19 +++--- docs/api.md | 11 ++-- docs/operations.md | 2 +- docs/upgrading.md | 26 +++++++- pro_tes/access_control/model.conf | 4 +- pro_tes/api/additions.openapi.yaml | 8 +-- pro_tes/config.yaml | 14 ++-- pro_tes/ga4gh/tes/task_runs.py | 4 +- tests/ga4gh/tes/test_provenance_api.py | 76 +++++++++++++++------- tests/retention/test_retention_endpoint.py | 10 ++- 10 files changed, 111 insertions(+), 63 deletions(-) diff --git a/docs/access-control.md b/docs/access-control.md index fb45eeda..a22ac7bc 100644 --- a/docs/access-control.md +++ b/docs/access-control.md @@ -43,8 +43,8 @@ options](https://foca.readthedocs.io/en/latest/configuration/auth/)). | --- | --- | | `user` | create tasks (`POST /tasks`) | | any authenticated caller | list their own tasks (`GET /tasks`), also without a role | -| `owner` (of a task) | read and cancel the task (`GET /tasks/{id}`, `POST /tasks/{id}:cancel`) | -| `admin` | get the resources that tasks used per user ([Usage](api.md#usage)) and as execution reports ([Execution reports](api.md#execution-reports)), and the provenance of tasks ([Provenance](api.md#provenance)); not the tasks of others, nor the access control rules (see [Permissions API](#permissions-api)) | +| `owner` (of a task) | read and cancel the task (`GET /tasks/{id}`, `POST /tasks/{id}:cancel`) and get its provenance ([Provenance](api.md#provenance)) | +| `admin` | get the resources that tasks used per user ([Usage](api.md#usage)) and as execution reports ([Execution reports](api.md#execution-reports)); not the tasks of others nor their provenance, nor the access control rules (see [Permissions API](#permissions-api)) | Roles are given to groups of the identity provider: the values of the claim `security.access_control.claim_groups` (from the token, or from the user info @@ -58,8 +58,7 @@ The roles and their permissions are the policies of `security.access_control.policies` in the base config (see [FOCA's access control](https://foca.readthedocs.io/en/latest/access-control/)), named rules (`users-create-tasks`, `authenticated-list-tasks`, -`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-provenance`, -`admins-get-usage`, `admins-get-usage-reports`, `users-list-plugins` and +`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-usage`, `admins-get-usage-reports`, `users-list-plugins` and `users-get-plugins`): a config overlay adds, changes or removes (`null`) single rules by name, e.g., rules that let only users list their tasks, and owners only read them: @@ -97,12 +96,12 @@ claim set in `security.access_control.claim_identity`) becomes its owner: tasks, so that responses don't tell which tasks exist. The owner gets `404 Not Found` for a task that was deleted from the database. -- `GET /tasks/{id}/provenance` is allowed for the owner and for admins - (rules `owners-get-provenance` and `admins-get-provenance`); everyone else - gets `403 Forbidden`. The provenance holds no inputs or logs of the task, - only which plugins and TES instances processed it (see - [Provenance](api.md#provenance)); remove `admins-get-provenance` (`null` - in an overlay) to keep it from admins. +- `GET /tasks/{id}/provenance` is allowed for the owner only (rule + `owners-get-provenance`); everyone else gets `403 Forbidden`, also admins + and for unknown tasks, as for `GET /tasks/{id}`. The provenance holds no + inputs or logs of the task, but tells which plugins and TES instances + processed it and when, i.e., details of someone's task (see + [Provenance](api.md#provenance)). - `GET /plugins` and `GET /plugins/{plugin_id}` (what users may choose per task, see [Choices of clients](plugins.md#choices-of-clients)) are allowed diff --git a/docs/api.md b/docs/api.md index 4eb853af..adcb771f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -15,7 +15,7 @@ control](access-control.md)). | `POST /tasks` | Create a task: proTES forwards it to a TES instance (see [Tasks](#tasks)) and returns its own identifier of the task. | | `GET /tasks` | List the caller's tasks, newest first, one page at a time (`page_size`, at most `max_page_size` of the [config](configuration.md#tasks), and `max_page_size_full` tasks, of at most `max_page_bytes_full` bytes, for the view `FULL`; `page_token` from `next_page_token` of the previous page, which is empty on the last page), optionally only those whose name starts with `name_prefix` (taken literally; matched against the name of the task as submitted, before plugins may have renamed it), by `state`, or by tags (`tag_key` and `tag_value`, in pairs, taken literally: a key without a value, or with an empty one, matches any value of that tag; a task must match all pairs; more values than keys are rejected with `400 Bad Request`; needs MongoDB 5.0 or later). | | `GET /tasks/{id}` | Get a task of the caller, with its state as last tracked from the TES instance. | -| `GET /tasks/{id}/provenance` | proTES extension: get the provenance of a task, for its owner and for admins (see [Provenance](#provenance)). | +| `GET /tasks/{id}/provenance` | proTES extension: get the provenance of a task, for its owner only (see [Provenance](#provenance)). | | `GET /usage` | proTES extension: get the resources that the tasks of each user used, for admins, if accounting is enabled (see [Usage](#usage)). | | `GET /plugins` | proTES extension (FOCA's plugin listing): list the plugins and presets that the caller may choose for its tasks, and the limits, for users; the default pipeline only for callers who may choose pipelines (see [Choices of clients](plugins.md#choices-of-clients)). | | `GET /plugins/{plugin_id}` | proTES extension: describe a plugin that the caller may choose (`404 Not Found` otherwise). | @@ -179,11 +179,10 @@ resolved pipeline (`pipeline.resolved`), e.g., shortened: } ``` -The owner of the task and admins may get it; everyone else gets -`403 Forbidden`, also for unknown tasks (see [Access -control](access-control.md#task-ownership)); admins get `404 Not Found` for -unknown tasks. Tasks without provenance (e.g., -created by earlier versions) give `404 Not Found`. The record holds no +Only the owner of the task may get it; everyone else gets `403 +Forbidden`, also admins and for unknown tasks, as for `GET /tasks/{id}` +(see [Access control](access-control.md#task-ownership)). Tasks without +provenance (e.g., created by earlier versions) give `404 Not Found`. The record holds no inputs, logs, IP addresses, tokens, header values or claims: plugins' changes are recorded as paths and hashes only. diff --git a/docs/operations.md b/docs/operations.md index 67e4f12e..725efd4e 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -422,7 +422,7 @@ outcome, reason, remote identifier, times) and the final reason, if no TES instance accepted the task. The record is stored with the task (after routing), and replaced, with the attempts, once a TES instance accepted the task (or may have, `SYSTEM_ERROR`). Records hold no IP addresses, tokens, -header values or claims, and take at most 1 MiB. Owners and admins get +header values or claims, and take at most 1 MiB. Owners (only) get them with `GET /tasks/{id}/provenance` (see [Provenance](api.md#provenance)), and tasks carry a summary in their tags (`gateway.*`, see [Gateway tags](api.md#gateway-tags)). Tasks created by earlier versions have none. diff --git a/docs/upgrading.md b/docs/upgrading.md index b9c59395..8b61fc3c 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -15,6 +15,25 @@ changes](#unreleased-changes)). ## Unreleased changes +**Provenance for owners only (breaking change, rule removed):** `GET +/tasks/{id}/provenance` is now allowed for the owner of the task only: +admins get `403 Forbidden`, like everyone else who doesn't own the task, +also for unknown tasks (before, admins got the provenance of any task, and +`404 Not Found` for unknown ones). The rule `admins-get-provenance` is +removed from the base config: the provenance tells which plugins and TES +instances processed a task and when, i.e., details of someone else's +task, which admins must not see (see [Task +ownership](access-control.md#task-ownership)). The stored rule is removed +on startup, with the other configured rules. Admins keep usage and usage +reports. Scripts or dashboards that read the provenance with an admin's +token must use the owner's token instead (e.g., a service that created the +tasks on its own client). Overlays that remove the rule +(`admins-get-provenance: null`, as these docs suggested before) stop the +start, with FOCA's error naming the unknown rule: drop that entry. An +overlay that still sets the rule adds it again, as a rule of your own; drop +it. During a rolling upgrade, instances of earlier versions that start +store the rule again, until the last of them is replaced. + **Stale polls fenced (behaviour change, new field):** each run of a poll claims the tracking of its task with a token of its own, stored in `tracking.claim`, and only the run that claimed it last stores unfinished @@ -1128,7 +1147,9 @@ empty. Owners and admins get the provenance with `GET /tasks/{id}/provenance` (rules `owners-get-provenance` and `admins-get-provenance` of the base -config; custom lists of `security.access_control.policies` must add them). +config; custom lists of `security.access_control.policies` must add them; +admins no longer get it since the [unreleased +changes](#unreleased-changes)). New tasks have the gateway tags of FOCA (`gateway.pipeline_source`, `gateway.backend`, ...; see [Gateway tags](api.md#gateway-tags)), served with the task: clients that submit a fetched task again must drop the tags @@ -1260,7 +1281,8 @@ API specifications (`api.specs`) and access control rules (`security.access_control.policies`) of the base config are named entries (the spec `tes`; rules `users-create-list-tasks` (split in 0.8.0, see [To version 0.8.0](#to-version-080)), -`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-provenance`, +`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-provenance` +(removed, see [Unreleased changes](#unreleased-changes)), `users-list-plugins`, `users-get-plugins`, `admins-list-add-permissions` and `admins-manage-permissions`; the last two removed in 0.8.0, see [To version 0.8.0](#to-version-080)), which overlays change by name (see diff --git a/pro_tes/access_control/model.conf b/pro_tes/access_control/model.conf index 4ddf2661..6428cfee 100644 --- a/pro_tes/access_control/model.conf +++ b/pro_tes/access_control/model.conf @@ -4,8 +4,8 @@ # # Unlike FOCA's reference model (`resource_role_model.conf`), the role `admin` # may not do everything: admins only have the rights that rules give them -# (provenance and usage, cf. `config.yaml`), so that nobody but the owner of -# a task can read or cancel it. +# (usage, cf. `config.yaml`), so that nobody but the owner of a task can read +# or cancel it, or get its provenance. # [request_definition] # sub - accessing entity (prefixed user identifier, or role from group claims) diff --git a/pro_tes/api/additions.openapi.yaml b/pro_tes/api/additions.openapi.yaml index 1747a23f..4b104003 100644 --- a/pro_tes/api/additions.openapi.yaml +++ b/pro_tes/api/additions.openapi.yaml @@ -53,7 +53,7 @@ paths: proTES extension: get the provenance of a task, as recorded by the plugin engine of FOCA when the task was created and forwarded, with the plugin builds and the pipeline that it refers to. For the owner - of the task and for admins. + of the task only, not for admins. operationId: GetTaskProvenance parameters: - name: id @@ -71,8 +71,8 @@ paths: $ref: '#/components/schemas/TaskProvenance' 403: description: >- - The caller is neither the owner of the task nor an admin (also - for unknown tasks, which admins get as 404). + The caller is not the owner of the task (also admins, and for + unknown tasks, as for GetTask). content: application/json: schema: @@ -80,7 +80,7 @@ paths: 404: description: >- The task has no provenance (e.g., created by an earlier version - of proTES), was deleted, or (for admins) doesn't exist. + of proTES) or was deleted. content: application/json: schema: diff --git a/pro_tes/config.yaml b/pro_tes/config.yaml index db79cfc3..52ce736b 100644 --- a/pro_tes/config.yaml +++ b/pro_tes/config.yaml @@ -61,11 +61,12 @@ security: issuers: [] # Access control: users (the role `user`) may create tasks; every # authenticated caller may list their own; the user creating a task becomes - # its owner, and only owners may read and cancel a task, also after losing - # the role `user`. Admins (the role `admin`) may only read the provenance - # of tasks and the usage per user, not the tasks of others. Roles are given - # to groups of the identity provider (values of the claim `claim_groups`) - # by `group_mapping`, e.g.: + # its owner, and only owners may read and cancel a task and get its + # provenance, also after losing the role `user`. Admins (the role `admin`) + # may only read the usage per user and the execution reports, not the + # tasks of others nor their provenance. Roles are given to groups of the + # identity provider (values of the claim `claim_groups`) by + # `group_mapping`, e.g.: # claim_groups: groups # group_mapping: # compute-users: user @@ -96,9 +97,8 @@ security: authenticated-list-tasks: [p, "*", /ga4gh/tes/v1/tasks, (GET)|(HEAD)] # `POST` is cancellation (`/tasks/{id}:cancel`) owners-get-cancel-tasks: [p, owner, "/ga4gh/tes/v1/tasks/:id", (GET)|(HEAD)|(POST)] - # the provenance of a task, also for admins (no inputs or logs) + # the provenance of a task, for its owner only (not for admins either) owners-get-provenance: [p, owner, "/ga4gh/tes/v1/tasks/:id/provenance", (GET)|(HEAD)] - admins-get-provenance: [p, admin, "/ga4gh/tes/v1/tasks/:id/provenance", (GET)|(HEAD)] # the resources that tasks used, per user (`custom.accounting`) admins-get-usage: [p, admin, /ga4gh/tes/v1/usage, (GET)|(HEAD)] # the same records as execution reports, without user identifiers diff --git a/pro_tes/ga4gh/tes/task_runs.py b/pro_tes/ga4gh/tes/task_runs.py index 6cd38b8e..d719070c 100644 --- a/pro_tes/ga4gh/tes/task_runs.py +++ b/pro_tes/ga4gh/tes/task_runs.py @@ -814,8 +814,8 @@ def _update_records(self, run: PipelineRun, db_document: DbDocument) -> None: def get_task_provenance(self, id: str) -> dict[str, Any]: """Get the provenance of a task, with its references expanded. - Only owners of the task and admins may get it (enforced by the - policies). The builds of the plugins that ran and default and + Only owners of the task may get it, not admins either (enforced by + the policies). The builds of the plugins that ran and default and preset pipelines are stored once, by hash (cf. :py:class:`foca.plugins.ProvenanceStore`); they are added to the record (`builds`, `pipeline.resolved`), unless it has them diff --git a/tests/ga4gh/tes/test_provenance_api.py b/tests/ga4gh/tes/test_provenance_api.py index c231cbaa..f867a7f5 100644 --- a/tests/ga4gh/tes/test_provenance_api.py +++ b/tests/ga4gh/tes/test_provenance_api.py @@ -2,7 +2,7 @@ `GET /tasks/{id}/provenance` serves the provenance stored with a task, with the plugin builds and pipelines that it refers to expanded, to the task's -owner and to admins; tasks have the gateway tags of FOCA (`gateway.*`) that +owner only, not to admins (#568); tasks have the gateway tags of FOCA (`gateway.*`) that summarize it (and replace `forwarded_to`, removed in 0.4.0, cf. #324). """ @@ -16,6 +16,7 @@ import tes import yaml +from pro_tes import app as app_module from pro_tes.app import init_app from pro_tes.exceptions import BackendOutcomeUnknown from pro_tes.ga4gh.tes import task_runs @@ -27,6 +28,7 @@ DB, OTHER_USER, OUTSIDER, + USER, make_headers, reset_gateway, set_overlays, @@ -40,6 +42,8 @@ stored, ) +BASE_CONFIG = Path(app_module.__file__).parent / "config.yaml" + def provenance_path(task_id: str) -> str: """Get the path of the provenance of a task. @@ -53,16 +57,13 @@ def provenance_path(task_id: str) -> str: return f"{BASE_PATH}/tasks/{task_id}/provenance" -@pytest.mark.parametrize("user", [None, ADMIN, ADMIN_USER]) def test_get_provenance( client: FlaskClient, task_id: str, mongo_client: MongoClient[dict[str, Any]], - user: str | None, ) -> None: - """Owners and admins get the provenance, with its references expanded.""" - headers = make_headers(user) if user else None - response = client.get(provenance_path(task_id), headers=headers) + """Owners get the provenance, with its references expanded.""" + response = client.get(provenance_path(task_id)) assert response.status_code == 200 provenance = response.get_json() record = stored(mongo_client, task_id)["provenance"] @@ -83,18 +84,35 @@ def test_head_provenance(client: FlaskClient, task_id: str) -> None: assert client.head(provenance_path(task_id)).status_code == 200 -@pytest.mark.parametrize("user", [OTHER_USER, OUTSIDER]) -def test_get_provenance_forbidden(client: FlaskClient, task_id: str, user: str) -> None: - """Other users than owners and admins get `403`.""" - response = client.get(provenance_path(task_id), headers=make_headers(user)) +@pytest.mark.parametrize("user", [OTHER_USER, OUTSIDER, ADMIN, ADMIN_USER]) +@pytest.mark.parametrize("method", ["get", "head"]) +def test_get_provenance_forbidden( + client: FlaskClient, task_id: str, user: str, method: str +) -> None: + """Everyone but the owner gets `403`, admins included (#568). + + The same response as `GET /tasks/{id}` gives them. + """ + headers = make_headers(user) + response = getattr(client, method)(provenance_path(task_id), headers=headers) assert response.status_code == 403 + task = client.get(f"{BASE_PATH}/tasks/{task_id}", headers=headers) + assert task.status_code == 403 -def test_get_provenance_not_found(client: FlaskClient) -> None: - """Admins get `404` for unknown tasks, users `403`.""" +@pytest.mark.parametrize("user", [USER, OTHER_USER, ADMIN, ADMIN_USER]) +def test_get_provenance_unknown(client: FlaskClient, user: str) -> None: + """Unknown tasks give `403` to everyone, admins included. + + So that responses don't tell which tasks exist, as for `GET /tasks/{id}`. + """ path = provenance_path("NOTASK") - assert client.get(path, headers=make_headers(ADMIN)).status_code == 404 - assert client.get(path).status_code == 403 + assert client.get(path, headers=make_headers(user)).status_code == 403 + + +def test_get_provenance_no_token(anonymous_client: FlaskClient, task_id: str) -> None: + """Requests without an access token get `401`.""" + assert anonymous_client.get(provenance_path(task_id)).status_code == 401 def test_get_provenance_none( @@ -245,13 +263,29 @@ def test_gateway_tags_tracked( assert document["task"]["tags"] == tags -def test_admins_provenance_removed( +def test_admins_provenance_not_configured() -> None: + """The base config gives admins no rule for the provenance (#568).""" + config = yaml.safe_load(BASE_CONFIG.read_text(encoding="utf-8")) + policies = config["security"]["access_control"]["policies"] + assert "admins-get-provenance" not in policies + provenance_rules = [ + rule for rule in policies.values() if rule[2].endswith("/provenance") + ] + assert provenance_rules == [ + ["p", "owner", "/ga4gh/tes/v1/tasks/:id/provenance", "(GET)|(HEAD)"] + ] + + +def test_admins_provenance_removed_null( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, app_env: None, - backend: type[FakeBackend], ) -> None: - """Without the rule `admins-get-provenance`, admins get `403`.""" + """Overlays that remove the former rule `admins-get-provenance` stop the start. + + The rule is no longer in the base config, and FOCA refuses to remove + unknown rules (see the upgrade notes). + """ overlay = tmp_path / "policies.yaml" overlay.write_text( yaml.safe_dump( @@ -265,12 +299,8 @@ def test_admins_provenance_removed( ) set_overlays(monkeypatch, overlay) reset_gateway() - client = init_app().app.test_client() - client.environ_base["HTTP_AUTHORIZATION"] = make_headers()["Authorization"] - task_id = client.post(f"{BASE_PATH}/tasks", json=TASK).get_json()["id"] - path = provenance_path(task_id) - assert client.get(path).status_code == 200 - assert client.get(path, headers=make_headers(ADMIN)).status_code == 403 + with pytest.raises(ValueError, match="admins-get-provenance"): + init_app() def test_gateway_tags_not_built( diff --git a/tests/retention/test_retention_endpoint.py b/tests/retention/test_retention_endpoint.py index 728e9938..72eda111 100644 --- a/tests/retention/test_retention_endpoint.py +++ b/tests/retention/test_retention_endpoint.py @@ -125,12 +125,10 @@ def test_tombstone_not_found(client: FlaskClient, tombstone: str, path: str) -> def test_tombstone_provenance(client: FlaskClient, tombstone: str) -> None: - """Tombstones have no provenance, also for admins.""" - for headers in ({}, make_headers(user=ADMIN)): - response = client.get( - f"{BASE_PATH}/tasks/{tombstone}/provenance", headers=headers - ) - assert response.status_code == 404 + """Tombstones have no provenance for owners; admins get `403` (#568).""" + path = f"{BASE_PATH}/tasks/{tombstone}/provenance" + assert client.get(path).status_code == 404 + assert client.get(path, headers=make_headers(user=ADMIN)).status_code == 403 def test_tombstone_not_listed(client: FlaskClient, tombstone: str) -> None: From 1dece9fef4be6fcabdd1de91a0673290889f05ee Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 5 Dec 2026 23:04:03 +0100 Subject: [PATCH 2/4] test: cover provenance rule removal on upgrade Tests that the rule stored by earlier versions stops applying when the app starts without it, and that variants of the provenance path never give admins the provenance. The upgrade notes name custom lists of rules, which must drop the rule too; docs re-wrapped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FSoqPsbB5s4NvhhYYcDJk --- docs/access-control.md | 9 +-- docs/api.md | 6 +- docs/operations.md | 2 +- docs/upgrading.md | 9 ++- tests/ga4gh/tes/test_provenance_api.py | 86 +++++++++++++++++++++----- 5 files changed, 84 insertions(+), 28 deletions(-) diff --git a/docs/access-control.md b/docs/access-control.md index a22ac7bc..0cee8460 100644 --- a/docs/access-control.md +++ b/docs/access-control.md @@ -58,10 +58,11 @@ The roles and their permissions are the policies of `security.access_control.policies` in the base config (see [FOCA's access control](https://foca.readthedocs.io/en/latest/access-control/)), named rules (`users-create-tasks`, `authenticated-list-tasks`, -`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-usage`, `admins-get-usage-reports`, `users-list-plugins` and -`users-get-plugins`): a config overlay adds, changes or removes (`null`) -single rules by name, e.g., rules that let only users list their tasks, and -owners only read them: +`owners-get-cancel-tasks`, `owners-get-provenance`, `admins-get-usage`, +`admins-get-usage-reports`, `users-list-plugins` and `users-get-plugins`): +a config overlay adds, changes or removes (`null`) single rules by name, +e.g., rules that let only users list their tasks, and owners only read +them: ```yaml security: diff --git a/docs/api.md b/docs/api.md index adcb771f..770406e6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -182,9 +182,9 @@ resolved pipeline (`pipeline.resolved`), e.g., shortened: Only the owner of the task may get it; everyone else gets `403 Forbidden`, also admins and for unknown tasks, as for `GET /tasks/{id}` (see [Access control](access-control.md#task-ownership)). Tasks without -provenance (e.g., created by earlier versions) give `404 Not Found`. The record holds no -inputs, logs, IP addresses, tokens, header values or claims: plugins' -changes are recorded as paths and hashes only. +provenance (e.g., created by earlier versions) give `404 Not Found`. The +record holds no inputs, logs, IP addresses, tokens, header values or +claims: plugins' changes are recorded as paths and hashes only. ## Usage diff --git a/docs/operations.md b/docs/operations.md index 725efd4e..bf979203 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -422,7 +422,7 @@ outcome, reason, remote identifier, times) and the final reason, if no TES instance accepted the task. The record is stored with the task (after routing), and replaced, with the attempts, once a TES instance accepted the task (or may have, `SYSTEM_ERROR`). Records hold no IP addresses, tokens, -header values or claims, and take at most 1 MiB. Owners (only) get +header values or claims, and take at most 1 MiB. Only owners get them with `GET /tasks/{id}/provenance` (see [Provenance](api.md#provenance)), and tasks carry a summary in their tags (`gateway.*`, see [Gateway tags](api.md#gateway-tags)). Tasks created by earlier versions have none. diff --git a/docs/upgrading.md b/docs/upgrading.md index 8b61fc3c..84090069 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -31,8 +31,10 @@ tasks on its own client). Overlays that remove the rule (`admins-get-provenance: null`, as these docs suggested before) stop the start, with FOCA's error naming the unknown rule: drop that entry. An overlay that still sets the rule adds it again, as a rule of your own; drop -it. During a rolling upgrade, instances of earlier versions that start -store the rule again, until the last of them is replaced. +it. Custom lists of `security.access_control.policies` (which replace the +rules of the base config) must drop it too, or admins keep the access. +During a rolling upgrade, instances of earlier versions that start store +the rule again, until the last of them is replaced. **Stale polls fenced (behaviour change, new field):** each run of a poll claims the tracking of its task with a token of its own, stored in @@ -888,7 +890,8 @@ Check each item; the sections below have the details. 5. **Access control rules:** custom lists of `security.access_control.policies` must add the new rules `users-list-plugins`, `users-get-plugins`, `owners-get-provenance` and - `admins-get-provenance`, or users get `403` (see [Task + `admins-get-provenance` (removed again, see [Unreleased + changes](#unreleased-changes)), or users get `403` (see [Task provenance](#task-provenance)); overlays that change rules by name keep them. 6. **Database:** proTES uses new collections in the database of the tasks: diff --git a/tests/ga4gh/tes/test_provenance_api.py b/tests/ga4gh/tes/test_provenance_api.py index f867a7f5..138d5e95 100644 --- a/tests/ga4gh/tes/test_provenance_api.py +++ b/tests/ga4gh/tes/test_provenance_api.py @@ -2,8 +2,9 @@ `GET /tasks/{id}/provenance` serves the provenance stored with a task, with the plugin builds and pipelines that it refers to expanded, to the task's -owner only, not to admins (#568); tasks have the gateway tags of FOCA (`gateway.*`) that -summarize it (and replace `forwarded_to`, removed in 0.4.0, cf. #324). +owner only, not to admins (#568); tasks have the gateway tags of FOCA +(`gateway.*`) that summarize it (and replace `forwarded_to`, removed in +0.4.0, cf. #324). """ import json @@ -276,31 +277,82 @@ def test_admins_provenance_not_configured() -> None: ] +def _app_with_policies( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path, policies: dict[str, Any] +) -> FlaskClient: + """Start the app with an overlay of access control rules. + + Args: + monkeypatch: Pytest's monkeypatch fixture. + tmp_path: Directory for the overlay. + policies: Rules of the overlay, by name. + + Returns: + A test client of the app, with the token of the default user. + """ + overlay = tmp_path / "policies.yaml" + overlay.write_text( + yaml.safe_dump({"security": {"access_control": {"policies": policies}}}), + encoding="utf-8", + ) + set_overlays(monkeypatch, overlay) + reset_gateway() + client = init_app().app.test_client() + client.environ_base["HTTP_AUTHORIZATION"] = make_headers()["Authorization"] + return client + + +def test_admins_provenance_upgrade( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + app_env: None, + backend: type[FakeBackend], +) -> None: + """The stored rule of earlier versions stops applying on upgrade (#568). + + An app with the former rule `admins-get-provenance` (as stored by 0.8.0) + lets admins read the provenance; the app started next without it + replaces the stored rules, so that admins get `403`. + """ + old_rule = ["p", "admin", "/ga4gh/tes/v1/tasks/:id/provenance", "(GET)|(HEAD)"] + client = _app_with_policies( + monkeypatch, tmp_path, {"admins-get-provenance": old_rule} + ) + task_id = client.post(f"{BASE_PATH}/tasks", json=TASK).get_json()["id"] + path = provenance_path(task_id) + assert client.get(path, headers=make_headers(ADMIN)).status_code == 200 + client = _app_with_policies(monkeypatch, tmp_path, {}) + assert client.get(path).status_code == 200 + assert client.get(path, headers=make_headers(ADMIN)).status_code == 403 + + +@pytest.mark.parametrize( + "suffix", ["/provenance/", "//provenance", "%2Fprovenance", "/PROVENANCE"] +) +def test_get_provenance_path_variants( + client: FlaskClient, task_id: str, suffix: str +) -> None: + """Variants of the provenance path never give admins the provenance. + + Redirects (e.g., of double slashes) are followed. + """ + path = f"{BASE_PATH}/tasks/{task_id}{suffix}" + response = client.get(path, headers=make_headers(ADMIN), follow_redirects=True) + assert response.status_code in {403, 404} + + def test_admins_provenance_removed_null( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, app_env: None, ) -> None: - """Overlays that remove the former rule `admins-get-provenance` stop the start. + """Overlays removing the former rule `admins-get-provenance` stop the start. The rule is no longer in the base config, and FOCA refuses to remove unknown rules (see the upgrade notes). """ - overlay = tmp_path / "policies.yaml" - overlay.write_text( - yaml.safe_dump( - { - "security": { - "access_control": {"policies": {"admins-get-provenance": None}} - } - } - ), - encoding="utf-8", - ) - set_overlays(monkeypatch, overlay) - reset_gateway() with pytest.raises(ValueError, match="admins-get-provenance"): - init_app() + _app_with_policies(monkeypatch, tmp_path, {"admins-get-provenance": None}) def test_gateway_tags_not_built( From 7858cb31819edf0deaf367f6d961ae5e18ef735c Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 5 Dec 2026 23:26:20 +0100 Subject: [PATCH 3/4] docs: clarify provenance upgrade and 401 The 0.4.0 upgrade checklist no longer tells custom rule lists to add `admins-get-provenance`, but to leave it out; the provenance docs say that requests without a valid token get `401`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FSoqPsbB5s4NvhhYYcDJk --- docs/access-control.md | 5 +++-- docs/api.md | 5 +++-- docs/upgrading.md | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/access-control.md b/docs/access-control.md index 0cee8460..38b157f0 100644 --- a/docs/access-control.md +++ b/docs/access-control.md @@ -98,8 +98,9 @@ claim set in `security.access_control.claim_identity`) becomes its owner: `404 Not Found` for a task that was deleted from the database. - `GET /tasks/{id}/provenance` is allowed for the owner only (rule - `owners-get-provenance`); everyone else gets `403 Forbidden`, also admins - and for unknown tasks, as for `GET /tasks/{id}`. The provenance holds no + `owners-get-provenance`); every other caller gets `403 Forbidden`, also + admins and for unknown tasks, as for `GET /tasks/{id}` (requests without + a valid access token get `401 Unauthorized`). The provenance holds no inputs or logs of the task, but tells which plugins and TES instances processed it and when, i.e., details of someone's task (see [Provenance](api.md#provenance)). diff --git a/docs/api.md b/docs/api.md index 770406e6..6c09d34c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -179,9 +179,10 @@ resolved pipeline (`pipeline.resolved`), e.g., shortened: } ``` -Only the owner of the task may get it; everyone else gets `403 +Only the owner of the task may get it; every other caller gets `403 Forbidden`, also admins and for unknown tasks, as for `GET /tasks/{id}` -(see [Access control](access-control.md#task-ownership)). Tasks without +(see [Access control](access-control.md#task-ownership)); requests +without a valid access token get `401 Unauthorized`. Tasks without provenance (e.g., created by earlier versions) give `404 Not Found`. The record holds no inputs, logs, IP addresses, tokens, header values or claims: plugins' changes are recorded as paths and hashes only. diff --git a/docs/upgrading.md b/docs/upgrading.md index 84090069..0c60ca8c 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -889,11 +889,12 @@ Check each item; the sections below have the details. (see [TES instance list](#tes-instance-list)). 5. **Access control rules:** custom lists of `security.access_control.policies` must add the new rules - `users-list-plugins`, `users-get-plugins`, `owners-get-provenance` and - `admins-get-provenance` (removed again, see [Unreleased - changes](#unreleased-changes)), or users get `403` (see [Task - provenance](#task-provenance)); overlays that change rules by name keep - them. + `users-list-plugins`, `users-get-plugins` and `owners-get-provenance`, + or users get `403` (see [Task provenance](#task-provenance)); overlays + that change rules by name keep them. The rule `admins-get-provenance` + of 0.4.0 is removed again in later versions: leave it out, or admins + can read the provenance of any task (see [Unreleased + changes](#unreleased-changes)). 6. **Database:** proTES uses new collections in the database of the tasks: `plugin_builds`, `pipelines` and `failed_runs` (see [Task provenance](#task-provenance)) and `plugin_store` (see [Plugin From dc8ed1ab06c577ebba33e63887b0bb130db3b52a Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sun, 6 Dec 2026 00:09:06 +0100 Subject: [PATCH 4/4] docs: drop admin provenance from permissions The Permissions API section still listed the provenance of tasks among what admins see; it is for the task's owner only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FSoqPsbB5s4NvhhYYcDJk --- docs/access-control.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/access-control.md b/docs/access-control.md index 38b157f0..27b20252 100644 --- a/docs/access-control.md +++ b/docs/access-control.md @@ -397,9 +397,11 @@ Admins (the role `admin`) see no task content, only: - the resources that tasks used, per user, also per user that service clients ran tasks for (`GET /usage`, see [Usage](api.md#usage)); - the same as execution reports, without user identifiers (`GET - /usage/reports`, see [Execution reports](api.md#execution-reports)); -- the provenance of a task: which plugins and TES instances processed it - (`GET /tasks/{id}/provenance`, see [Provenance](api.md#provenance)). + /usage/reports`, see [Execution reports](api.md#execution-reports)). + +Not the provenance of the tasks of others either (`GET +/tasks/{id}/provenance`, see [Provenance](api.md#provenance)): it is for +the owner of the task only. To change rules, change the config (see [Roles](#roles)) and restart proTES. Rules stored earlier through the API stay in the database and in