annals.tokens#
Read tokens: a credential for an agent that cannot reach the store (a cloud session).
A token is scoped to ONE group, can only read (GET), is stored hashed, and expires (14
days unless told, 90 at most; there is no “never”). It never reaches a document tagged
private or noindex (annals.records.is_withheld()), however the group is edited
later. The server accepts it as Authorization: Bearer <token> on the API
(annals.api.mk_app()), where it is answered by a read-only room over the group
(annals.store.GroupScopedStore), so a route added later is out of reach until it is
named in annals.api.TOKEN_ROUTES.
The records are tokens/<id>.json under the data root (through the store’s target, so
annals token new works over ssh like annals publish):
{"id": "...", "name": "cloud-agent", "group": "<gid>", "created": "<iso>",
"expires": "<iso>", "hash": "<sha256 of the secret>", "revoked": "<iso>" | null}
The token itself, annt_<id>.<secret>, is shown once at creation and never stored. The
secret is 256 random bits, so a plain SHA-256 is enough (there is nothing to guess and
nothing to stretch); it is compared in constant time.
>>> import tempfile
>>> from annals.store import DocStore
>>> store = DocStore(tempfile.mkdtemp())
>>> d = store.publish(text="# a", title="A")["id"]
>>> g = store.make_group("G", [d])["id"]
>>> tokens = ReadTokens(store)
>>> token, rec = tokens.create(g, name="agent")
>>> tokens.verify(token)["group"] == g, tokens.verify(token + "x")
(True, None)
>>> _ = tokens.revoke(rec["id"]); tokens.verify(token)
Module Attributes
a long-lived credential is what the scope exists to avoid |
Functions
|
The token in an |
Classes
|
Make, check, list and revoke the read tokens of a |
- annals.tokens.MAX_DAYS = 90#
a long-lived credential is what the scope exists to avoid
- Type:
the longest a token may live
- class annals.tokens.ReadTokens(store, *, clock=<function now_utc>, max_days=90)[source]#
Bases:
objectMake, check, list and revoke the read tokens of a
DocStore’s groups.- create(group, *, name, expires='14d')[source]#
(token, record): the token is shown once, only its hash is kept.
- list(*, all=False)[source]#
The records without their hash, newest first (
all: revoked and expired too).