Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ config:
# off; see docs/configuration.md, Retention of finished tasks)
# retention:
# finished_days: 90
# Example: record the resources that tasks used, per user, for admins
# Example: record the resources that tasks used, for their owners and,
# as anonymous totals, for admins
# (`GET /usage`; default: off; see docs/configuration.md, Accounting of
# resource usage)
# accounting:
Expand Down
48 changes: 27 additions & 21 deletions docs/access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 anonymous totals of the resources that all tasks used ([Usage](api.md#usage)) and the records as execution reports ([Execution reports](api.md#execution-reports)); not the tasks of others nor their provenance or usage, 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
Expand All @@ -58,11 +58,12 @@ 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
`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`,
`authenticated-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:
Expand Down Expand Up @@ -97,12 +98,13 @@ 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`); 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)).

- `GET /plugins` and `GET /plugins/{plugin_id}` (what users may choose per
task, see [Choices of clients](plugins.md#choices-of-clients)) are allowed
Expand Down Expand Up @@ -366,8 +368,9 @@ gets no access to the task, and doesn't see it in their list. With
usage](configuration.md#accounting-of-resource-usage), the usage record of
the task also holds the named user (`acting_for`), which is personal data
as the owner is, and kept and deleted as the records are (see [Usage
records](operations.md#usage-records)): admins can get the totals per named
user (`GET /usage?group_by=acting_for`, see [Usage](api.md#usage));
records](operations.md#usage-records)): the named user gets the totals of
those tasks, and the client can split its totals by named user (`GET
/usage`, see [Usage](api.md#usage)); admins get only anonymous totals, and
execution reports leave it out. The header is read on `POST /tasks` only,
and ignored on other requests. proTES checks nothing about the named user
(that the user exists, may run tasks, or consented): the client is trusted
Expand All @@ -393,12 +396,15 @@ startup.

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)).
- anonymous totals of the resources that all tasks used, withheld below a
minimum number of tasks (`GET /usage`, see [Usage](api.md#usage));
- the usage records as execution reports, without user identifiers
(`GET /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
Expand Down
119 changes: 74 additions & 45 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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 /usage` | proTES extension: get the resources that the tasks of each user used, for admins, if accounting is enabled (see [Usage](#usage)). |
| `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 caller's tasks used, and anonymous totals over all tasks 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). |
| `POST /tasks/{id}:cancel` | Cancel a task of the caller that has not finished yet (also in state `UNKNOWN`, e.g., not tracked yet), at the TES instance that runs it; the task is then in state `CANCELING` until the TES instance reports its final state (usually `CANCELED`), or answers that it no longer has the task (`404` or `410`; then `CANCELED`). Meanwhile, the task stays `CANCELING`, also while the TES instance is unavailable, until the first poll after `polling.max_cancel_time` seconds (default 3600; then `SYSTEM_ERROR`, and it is no longer tracked; see [Task tracking](operations.md#task-tracking)); finished tasks are left as they are, also tasks that finish while they are canceled (their final state is kept), and tasks that the TES instance refuses to cancel as they have finished there (`200`; proTES stores their final state with the next poll). If a TES instance refuses to cancel a task that it hasn't finished, the task stays as it is (`502 Bad Gateway`). Unfinished tasks whose identifier at their TES instance is unknown (e.g., while they are being forwarded, or if forwarding failed unexpectedly) can't be canceled (`409 Conflict`). |
Expand Down Expand Up @@ -179,81 +179,110 @@ 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
inputs, logs, IP addresses, tokens, header values or claims: plugins'
changes are recorded as paths and hashes only.
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)); 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.

## Usage

`GET /usage` (a proTES extension) returns the resources that the tasks of
each user used, as recorded when they finished, if [accounting of resource
usage](configuration.md#accounting-of-resource-usage) is enabled: per user
(`user_id`, the owner of the tasks, `client:<client ID>` for [service
clients](access-control.md#service-clients); `null` for tasks without
owner), the
number of tasks, those without known run time (`untimed_tasks`), the run
time in seconds, and the requested resources times the run time:
`GET /usage` (a proTES extension) returns the resources that tasks used, as
recorded when they finished, if [accounting of resource
usage](configuration.md#accounting-of-resource-usage) is enabled. Every
authenticated caller gets the totals of their own tasks, and of the tasks
that service clients ran for them; admins get, besides, anonymous totals over
all tasks. Nobody gets the totals of anyone else, admins neither. Each total
holds the number of tasks, those without known run time (`untimed_tasks`),
the run time in seconds, and the requested resources times the run time:

```json
{
"recording": true,
"users": [
{"user_id": "alice", "tasks": 12, "untimed_tasks": 0,
"wall_seconds": 5400.0, "cpu_core_seconds": 10800.0,
"ram_gb_seconds": 21600.0, "disk_gb_seconds": 54000.0}
"ram_gb_seconds": 21600.0, "disk_gb_seconds": 54000.0},
{"user_id": "client:engine", "acting_for": "alice", "tasks": 3, ...}
]
}
```

`recording` tells whether finishing tasks are recorded
(`custom.accounting.enabled`); stored records are served either way. A total
too large for a 64-bit float is the largest one (`1.7976931348623157e+308`),
as JSON has no infinity. The
query parameters limit the totals:

- `user_id`: the tasks of one user only;
- `acting_for`: the tasks that service clients ran for one user only (named
when they created the tasks, see [Acting for
users](access-control.md#acting-for-users); in the form of `user_id`), not
the tasks that the user owns;
as JSON has no infinity.

`users` holds the caller's totals: first those of the tasks the caller owns
(`user_id`: the caller, as owners are stored, `client:<client ID>` for
[service clients](access-control.md#service-clients)), then, per service
client, those of the tasks that it ran for the caller (`user_id`: the
client, `acting_for`: the caller; see [Acting for
users](access-control.md#acting-for-users)). The list is empty if the
caller has no recorded tasks. A service client splits the totals of its own
tasks by the users it ran them for with `group_by=acting_for` (the default
is `user_id`; other values give `400 Bad Request`): its totals are then per
named user, each with `acting_for` (`null` for tasks run for no one, also
for tasks recorded by earlier versions of proTES, which didn't record the
named users), in the order of the named users:

```json
{
"recording": true,
"users": [
{"user_id": "client:engine", "acting_for": "alice", "tasks": 3, ...},
{"user_id": "client:engine", "acting_for": "bob", "tasks": 1, ...}
]
}
```

The query parameters limit the totals:

- `user_id`: only the caller's own tasks, without those that service clients
ran for the caller; it must name the caller, in the form of `user_id` in
the response (by default namespaced by issuer, `<issuer>|<sub>`, see
[Task owners](operations.md#task-owners));
- `acting_for`: only the tasks that service clients ran for the caller; it
must name the caller (both together match no tasks);
- `since` and `until`: the tasks that finished at or after `since` and
before `until` (date-times of RFC 3339, e.g., `2026-11-01T00:00:00Z`; UTC
without time zone), by the end of the task at its TES instance, or, if that
is unknown, by when it was recorded. Other values, also other forms of
ISO 8601 (e.g., a date without time) and leap seconds (`:60`), give
`400 Bad Request`.

Tasks that a service client ran for a user it named count for the client
(`client:<client ID>`). To split its totals by those users, set
`group_by=acting_for` (the default is `user_id`; other values give `400 Bad
Request`): the totals are then per owner and named user, each with
`acting_for` (`null` for tasks run for no one, e.g., those of users, and
for tasks recorded by earlier versions of proTES, which didn't record the
named users):
`user_id` or `acting_for` naming anyone else than the caller give `403
Forbidden`, also for admins.

Admins (the role `admin`) also get `aggregate`: the totals over all tasks
that finished in the time range (`since`, `until`), without user
identifiers. Totals over fewer tasks than
`custom.accounting.min_aggregate_tasks` (default `5`, see [Accounting of
resource usage](configuration.md#accounting-of-resource-usage)) are
withheld, so that a narrow time range with few tasks doesn't tell what
single users did: `aggregate` then holds only `"withheld": true`.

```json
{
"recording": true,
"users": [
{"user_id": "alice", "acting_for": null, "tasks": 12, ...},
{"user_id": "client:engine", "acting_for": "bob", "tasks": 3, ...}
]
"users": [],
"aggregate": {"withheld": false, "tasks": 132, "untimed_tasks": 2,
"wall_seconds": 480000.0, "cpu_core_seconds": 960000.0,
"ram_gb_seconds": 1920000.0, "disk_gb_seconds": 4800000.0}
}
```

E.g., `GET /usage?user_id=client:engine&group_by=acting_for` gives the
totals per user that the client `engine` ran tasks for. Without
`group_by=acting_for`, the totals have no `acting_for`, also with the
`acting_for` filter.
The minimum is no privacy guarantee: it counts tasks, not users (one
user's five tasks in a time range are given), and an admin can compare the
totals of overlapping time ranges (differencing), e.g., two ranges that
differ by one second, to get the totals of the tasks that finished in
between.

Only admins may get it (rule `admins-get-usage`); everyone else gets `403
Forbidden` (see [Access control](access-control.md#roles)). All users are
listed in one response, in the order of their identifiers (and then of the
named users).
Every authenticated caller may get it (rule `authenticated-get-usage`);
requests without a valid access token get `401 Unauthorized` (see [Access
control](access-control.md#roles)).

### Execution reports

Expand Down
22 changes: 19 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ The Celery workers delete the tasks:

## Accounting of resource usage

Deployments can record which resources the tasks of each user used, and
give admins the totals per user (see [Usage](api.md#usage)). Accounting is
off by default:
Deployments can record which resources the tasks of each user used: each
caller gets the totals of their own tasks, and admins anonymous totals over
all tasks (see [Usage](api.md#usage)). Accounting is off by default:

```yaml
custom:
Expand Down Expand Up @@ -877,6 +877,22 @@ tasks](#retention-of-finished-tasks), until operators delete them (see
[Usage records](operations.md#usage-records)). Turning accounting off stops
the recording; stored records are still served.

Admins get the totals over all tasks only if they cover at least
`min_aggregate_tasks` tasks (default `5`; at least `1`); totals over fewer
tasks, e.g., of a narrow time range with one user's tasks, are withheld,
so that they don't tell what single users did. The minimum counts tasks,
not users, and doesn't stop admins from comparing overlapping time ranges
(see [Usage](api.md#usage)). A minimum of 1 withholds nothing but empty
totals, so admins can read the totals of single tasks in narrow time
ranges:

```yaml
custom:
accounting:
enabled: true
min_aggregate_tasks: 20
```

### Execution reports

Admins get the records as execution reports of the Tool Execution Report
Expand Down
7 changes: 4 additions & 3 deletions docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ finished at its TES instance has a record in the collection `usage` (by
task identifier, `_id`), with its owner (`user_id`) and, for tasks that a
service client ran for a user it named (see [Acting for
users](access-control.md#acting-for-users)), that user (`acting_for`, in
the form of owners; `null` otherwise), and admins get the totals per user
at [`GET /usage`](api.md#usage), also per named user. The records hold the
the form of owners; `null` otherwise); each caller gets the totals of
their own tasks at [`GET /usage`](api.md#usage), admins also anonymous
totals over all tasks. The records hold the
subject identifiers of the owner and the named user, which are personal
data: they are kept until you delete them, also after their tasks are
deleted (by the [retention of finished
Expand Down Expand Up @@ -422,7 +423,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. 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.
Expand Down
Loading
Loading