Skip to content

A bot's token lives what its request asks, up to its maximum - #137

Merged
zlareb1 merged 24 commits into
mainfrom
pufit/trust-token-ttl
Oct 23, 2026
Merged

zlareb1 merged 24 commits into
mainfrom
pufit/trust-token-ttl

Conversation

@pufit

@pufit pufit commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Related: #110

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

Bots and workload trusts can set a maximum token lifetime from 60 seconds to one day. Clients request a lifetime with expires_in; requests without it retain the one-hour default, capped by the identity's maximum.

Why

Machine identities issue one-hour tokens regardless of how long a client needs them. A per-identity maximum lets an operator choose the renewal interval, while each request can ask for a shorter lifetime.

Scope and risk

  • Covers bot storage, both machine OAuth grants, bot administration and CLI commands, audit fields, and operator documentation. Both the admin flag and lifetime limit survive saving, listing and exchanging credentials.
  • A workload exchange still cannot outlive its subject token. Lifetime validation runs before spending the assertion or counting the exchange.
  • Longer bearer tokens increase the exposure if a token leaks. Subject revocation, bot disable or replacement, claim release and token revocation still end access. Namespace deletion and issuer-key rotation do not themselves revoke tokens already issued; the operator guide explains how to end them.
  • The Python and TypeScript MachineLogin never send expires_in, so SDK clients keep the one-hour default (or the bot's shorter maximum) and renew from the expires_in the server answers. A client that wants a longer token asks for it in its own token request.
  • A platform-admin bot may be allowed a day as well. Only a person signed in as a platform admin, or an operator on the host, registers one or sets its maximum, and revocation ends its tokens the same way as any bot's.
  • Token claims are read at issue time. A newly granted share reaches a client on its next exchange, which can be up to a day later.

Compatibility, rollout and rollback

  • Wire: /oauth/token accepts optional ASCII-digit expires_in of at least 60 seconds. An empty value means no request; repeated fields use the last value. The request is capped by max_access_token_s, and malformed values return invalid_request. The response shape is unchanged.
  • /v1/admin/bots.create accepts max_access_token_s from 60 to 86400, default 3600. /v1/admin/bots.list returns it. loom bot create --max-access-token-ttl sets it; loom bot list shows nondefault limits.
  • Audit: auth.machine_token records ttl_s; auth.machine_created records max_access_token_s.
  • Migration 077 adds max_access_token_s UInt32 DEFAULT 3600 after the merged platform-admin migration 076. Migration 076 and the admin fleet admission floor remain unchanged. No backfill is required.
  • Older builds ignore a maximum and expires_in, issue one-hour tokens, reject the creation field, and reset the maximum to 3600 when saving a bot, which can lengthen a sub-hour token as well as shorten a longer one. So registration answers 503 OVERLOADED (retry once the rollout ends) to a maximum other than 3600 until a fresh fleet view shows every replica in every deployment at migration 77, through the same fleet check that platform-admin tokens use at 76; an unread view refuses too. A request's expires_in needs no gate, since an older build answers it with an hour. After a rollback, reapply each maximum with loom bot create --replace once the newer build serves; the upgrade guide's rollback section says so.
  • A day-long workload exchange also needs a subject token and trust proof-age limit that allow a day.
  • Rollback leaves the additive column and returns new exchanges to one hour. Platform-admin bots follow the same configured lifetime policy as other bots; their human-only registration, exact claims, fleet checks and revocation protections remain in place.

Tests

  • tests/unit/test_machines.py: the hour unasked, a request capped by the bot's maximum, a maximum under an hour shortening the default, very long and zero-padded digit strings, and refusal of a lifetime under 60 s, negative, fractional, in exponent form, in words, with a leading space or in non-ASCII digits, before the assertion is spent or the exchange counted. A CI exchange never outlives its workload token, every revocation cuts a day-long agent token, /oauth/revoke keeps its row until that token expires, and each issued token's audit row carries its ttl_s.
  • tests/unit/test_account_admin.py, test_admin_account_routes.py and test_bot_cli.py: the 60 s to one-day bound in bot_from, over /v1/admin/bots.create (422 outside it) and in loom bot create; the saved, listed and audited maximum; the refusal of a nondefault maximum while an older replica serves, with the fleet check run on empty, older, mixed and current fleets and its floor matched to the migration file; and loom bot list printing a nondefault maximum after the proofs.
  • tests/unit/test_schema_baseline.py and the journal check cover migration 077 and schemas/schema.sql.
  • tests/integration/test_bots.py: a bot allowed a day gets an hour unasked, its maximum when it asks for more, and exactly a day when it asks for one; a subject revocation ends that day-long token at once.
  • Locally at this head: make format-check lint typecheck and the auth, admin and CLI unit suites (52 and 166 passed). The full unit, integration and mixed-version suites run in CI; the mixed-version gate does not exercise rule 26.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (Claude Code and Codex): coding agents wrote the implementation and review fixes. Independent source review covered OAuth validation, proof consumption, revocation, persistence and rollout behavior.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes (format, lint and typecheck pass locally; the unit and integration suites are ticked once CI is green).
  • Generated files are regenerated in this PR, not by hand.
  • The migration is additive, numbered after main, and edits no merged migration.
  • No plugin or frontend files change.
  • Documentation names operator steps and wire changes.
  • Repository text passes public-copy checks.
  • Review commits are signed off.

@pufit pufit changed the title a bot's token lives what its request asks, up to its maximum A bot's token lives what its request asks, up to its maximum Oct 21, 2026
pufit added 2 commits October 21, 2026 13:34
A bot or trust carries max_access_token_s (60 to 86400 s, default 3600;
migration 073 adds the column), set by an operator (loom bot create
--max-access-token-ttl) or a platform admin (/v1/admin/bots.create) and
listed by bots.list. /oauth/token's client-credentials and token-exchange
grants take expires_in (whole seconds, at least 60): the token lives what
was asked up to that maximum, an hour when nothing is asked (or the maximum
when shorter), and a workload token's exchange still never outlives the
token handed over. A malformed expires_in is refused (invalid_request)
before the assertion is spent or the exchange counted. The answer's
expires_in says what was issued; auth.machine_token records ttl_s and
auth.machine_created the maximum.

Revocation is unchanged and does not wait for expiry: subject revocations,
cutoffs (disable, replace, claim-release, revoke_subject with or without
issued_before) and parent revocations refuse a token by its subject and
issue time and never lapse; /oauth/revoke keeps one token's row until that
token's own exp. Unit tests pin the lifetimes, the refusals, and that each
revocation cuts a day-long agent token; an integration case registers a
day-long bot over the API, reads the column back, and revokes its subject.

Signed-off-by: pufit <[email protected]>
The bots and CI guide (docs/operations/sso.md) says how a request asks
for a longer token, what bounds it, what ends it at once, and what does
not (a namespace delete, the issuer's key rotation: replace or disable the
bot); security.md says the issued lifetime and that no revocation waits
for a token's expiry; rolling-upgrades.md gains rule 25 for the new
column: N-1 issues an hour, refuses the field and writes 3600 back when
it saves a bot, each only shortening tokens.

Signed-off-by: pufit <[email protected]>
@pufit
pufit force-pushed the pufit/trust-token-ttl branch from 77429c0 to c6b2c89 Compare October 21, 2026 17:36
pufit and others added 22 commits October 21, 2026 21:03
Replacing the shared monotonic clock can expire the model-call switch snapshot on a short-uptime runner. Replace only the hold module clock so unrelated caches keep real time.

Signed-off-by: Lareb Zafar <[email protected]>
Keep token lifetime limits and platform-admin flags through saving, listing and exchange. Migration 077 follows the merged admin migration without changing its fleet admission floor.

Signed-off-by: Lareb Zafar <[email protected]>
A long integration run can outlive the session token. Fresh per-test credentials keep the one-hour lifetime and preserve caller-supplied keys.

Signed-off-by: Lareb Zafar <[email protected]>
An adaptive queue may flush its first request immediately after an idle period. Use a fixed window for the shared-flush assertion and drain tasks even if the cleanup flush fails.

Signed-off-by: Lareb Zafar <[email protected]>
Clear graph-write buffers and timers at teardown so model transitions do not
inherit pending work. Wait for a settings reset before reading the baseline
on another worker, and check that cleanup succeeds.

Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>

# Conflicts:
#	tests/unit/conftest.py
#	tests/unit/test_integration_credentials.py
…me the lifetime they get

The bot row always carries max_access_token_s on this schema, so the fallback is gone. The SDK docstrings no longer promise an hour-long token, the day-token integration test signs its own client assertion instead of calling MachineLogin internals, and the edited security paragraphs are rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…cs name the token lifetime

The guide, the Python SDK reference and the TypeScript README no longer promise an hour-long bot token; bot_from's docstring keeps the platform-admin warning and says the maximum caps the default too; the rolling-upgrade rule says the mixed-version gate does not check it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…names the access-token maximum

asked_lifetime refuses a non-digit value outright instead of reading it as 0; loom bot list prints 'max access token', apart from the workload token age, and the create help no longer ties the limit to an exchange. An empty expires_in is tested to ask nothing; two doc-comment paragraphs are rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…eapply it

The module docstring, the SSO guide and the security page say a token lasts an hour or the bot's shorter maximum; the rollout notes name loom bot create --replace for reapplying a maximum an older server reset, and that it ends the bot's tokens. token_lifetime says why it still caps at a day.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…tion 77

An older replica issues an hour whatever the maximum and writes 3600 back when it saves the bot, silently widening a tightened cap. create_bot now refuses a nondefault maximum until a fresh fleet view shows every replica at 77, through the same fleet check the platform-admin flag uses at 76. Tests cover the refusal and the ttl_s and max_access_token_s audit fields; the upgrade guide's rollback section carries rule 26, and the CLI default reads TOKEN_TTL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…long token back in

A subject revocation with --expires-at lapses then, and a bot token allowed a day outlives an hour-long expiry. create_bot is also tested to refuse a nondefault maximum when the fleet view cannot be read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…empty view

token_lifetime drops the day cap no writer can exceed (bot_from bounds the maximum). The create refusal says an empty loom.instances view refuses as an older replica does; the SSO guide opens with the default lifetime the maximum can shorten, and its edited paragraphs are rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…migration file

The check runs on empty, older, mixed and current fleets, and its floor must match 077_machine_access_token_ttl.sql, as the platform-admin floor matches 076. The refusal names the lifetime in the words loom bot create's operator used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…stants it checks

ACCESS_TOKEN_MIGRATION is public, the message is built from it and TOKEN_TTL, and the tests match on the constant, so a renumbered migration changes the gate and its message together.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
@zlareb1
zlareb1 merged commit cc80c6f into main Oct 23, 2026
21 of 22 checks passed
@pufit pufit mentioned this pull request Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants