task_credentials
task_credentials
¶
Operator-facing credential management for live tasks.
Two verbs ride alongside the rest of terok task ...:
revoke_credentials— nuke every phantom token bound to a(project, task)pair. The in-flight request that already reached the broker still completes; every subsequent call from the container's agent gets a 401. Operator response to "audit shows this task is misbehaving" without killing the container itself, so the forensic state stays intact for inspection.audit_credentials— filter the broker's append-only credential-audit JSONL by the task's(scope, subject)pair, with optional provider / time / tail filters.
Both translate the operator's project/task identifiers into the opaque
(scope, subject) pair the sandbox actually keys on. scope is
the project name; subject is the task id. The mapping lives here
rather than in terok-sandbox because the sandbox makes no claim
about what those labels identify.
__all__ = ['audit_credentials', 'revoke_credentials']
module-attribute
¶
revoke_credentials(project_name, task_id)
¶
Revoke every phantom token bound to (project_name, task_id).
The DB-side delete takes effect on the next request the agent
issues — the broker has no in-memory token cache, so an in-flight
proxy call already past
lookup_token
completes on its real credential. That's the intended semantics:
block further use, don't kill in-flight TCP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
str
|
Project id (becomes the token's |
required |
task_id
|
str
|
Task id (becomes the token's |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of phantom tokens removed (zero if there were none — |
int
|
idempotent). |
Source code in src/terok/lib/domain/task_credentials.py
audit_credentials(project_name, task_id, *, provider=None, since=None, tail=None)
¶
Yield audit lines for (project_name, task_id) after filtering.
Reads the broker's
credential_audit_log_path
JSONL, drops lines whose scope / subject don't match the
target task, applies the optional provider / time filters, and
keeps only the last tail survivors when set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
str
|
Project id (matched against the line's |
required |
task_id
|
str
|
Task id (matched against the line's |
required |
provider
|
str | None
|
When set, drop lines whose |
None
|
since
|
datetime | None
|
When set, drop lines whose |
None
|
tail
|
int | None
|
When set, yield only the last |
None
|
Yields:
| Type | Description |
|---|---|
dict
|
Decoded JSON dicts, one per surviving line. |