Repository navigation
feat(oauth): OAuth 2.1 server, admin list, consent and grants pages - #82
Conversation
… page Adds the OAuth spec (docs/specs/oauth.md), the OAuth and consent routes in lodge-http.md with the 2 amended rules, the reserved app ID oauth and the hearth member in the app contract, Phase 7 of the roadmap, and the user docs for admins, consent and grants.
lodge issues agent access through OAuth 2.1 on github.com/ory/fosite (ADR-0023, docs/specs/oauth.md): discovery, dynamic registration of public clients, PKCE S256, loopback redirects on any port, refresh rotation with family revocation on reuse, and revocation. An admin listed with lodgectl allow admin decides each sign-in and access request on the consent page, under same-origin, a CSRF token and the request hash. The grants page lists principals, clients, grants and last use, and revokes a client or a principal. /mcp/<id> lgm_ tokens are unchanged.
A sign-in approval decides the request, makes the principal and binds the client in one transaction, with a bind that never changes a bound client; a sign-in for another principal than the client's is refused with 409. An access approval writes its grant in the same transaction. Registration checks the unbound-client limit in its insert, and the grants page takes its CSRF token and timestamp from one clock read.
A code or refresh token is consumed by one conditional update; a second use revokes its family in a transaction of its own, after fosite's transaction is gone. A nested rollback poisons the outer transaction, and storage reads run in the transaction. Revoking a client or a principal is one transaction, and so is creating a request with its client check and the pending limit. The sweep keeps the evidence of a used token while its family lives. The request hash sorts selector keys. Revoking an access token revokes its family (RFC 7009, section 2.1). The docs state each consent route's write and each refusal's status.
…mmit A family whose revocation write fails stays denied in memory, and the sweep writes it again until it is stored. The grant hook runs after the approval's transaction commits.
A concurrent second use of a code or refresh token revokes its family in fosite's own transaction, stores no token for it, and answers invalid_grant, so the revocation is as durable as the database. A code read as used at fosite's second read revokes its family before the answer. Request creation re-checks the client, the principal and the pending limit in its insert statement.
…orting it fosite revokes a used code's tokens in 2 writes with no transaction, so a refresh between them could issue a pair that survives. The storage now revokes the family in 1 transaction before it reports the used code.
Cross-review recordReviewer:
The 4 review rounds of the budget are used. Head
No reviewer has checked |
Cross-review: Ready at
|
| Fix | Reverted | Test | Failure |
|---|---|---|---|
| R3.1 | the family revocation in GetAuthorizeCodeSession |
go test -count=1 -run TestUsedCodeRevokesItsFamilyFirst ./internal/oauth/ |
"the family's refresh token was still active while its revocation was written" |
| R1.1 | the reusedIn skip in CreateAccessTokenSession |
go test -count=1 -run TestReuseRevokesInTheTransaction ./internal/oauth/ |
"the loser's access token = , want it never stored" |
| B1.1 | the conditional bind AND (principal IS NULL OR principal = ?) |
go test -count=1 -run TestOAuthConcurrentBinding ./internal/gateway/ |
"2 codes and 0 conflicts, want 1 and 1" |
| B3.2 | json.Deterministic(true) in the request hash |
go test -count=1 -run TestRequestHashIsDeterministic ./internal/oauth/ |
the hash differs from the fixed value and changes between runs |
The scratch worktree was restored and removed. All CI checks pass at 90d8f1c.
Takes the embedded NATS broker (#81). Both reserve an app ID: the list is now app, device, lodge, mcp, nats and oauth. The gateway serves /nats and the OAuth routes, and the daemon passes both the broker and the OAuth server to it.
Merge of main: unchanged-update exemptionPR #81 merged into main, so this PR needed a merge of main. History was not rewritten and nothing was force-pushed.
Comparison. For each of the PR's 48 files, I compared the PR's own
These conflicts resolved with no line of the PR changed: Compatibility check. Checks. |
Summary
lodge issues agent access through OAuth 2.1 and an admin's consent page
(ADR-0023,
contract in docs/specs/oauth.md). This is task t6 of
the MCP-first plan for frostyard's apps. It reads the hearth manifest format
of frostyard/hearth#2 (
schema/manifest-v1.json)."No browser route writes" (the consent decision and the grants page's
revocation write, under same-origin, a CSRF token and the request hash) and
"the control socket is the only place that issues credentials" (an OAuth
token is issued only after an admin approves).
github.com/ory/fosite(v0.49.0), imported only byinternal/oauth(internal/repocheck/fosite_test.go):/.well-known/oauth-authorization-serverand/.well-known/oauth-protected-resourcelgc_IDs,token_endpoint_auth_methodnone)httploopback IP redirect matches on any port (RFC 8252)lgo_at_(1 h),lgo_rt_(30 d),lgo_ac_(10 min);only signatures are stored
lodgectl allow admin LOGIN,disallow admin LOGINandadmins, on the control socket. Only a listed admin's tailnet login passes/oauth/authorize, the consent page and the grants page./oauth/consent/<id>: client, principal, app,capabilities and selectors from the app's hearth manifest. The admin
narrows scopes or paths, approves or declines. A request is decided once
and expires after 24 h; at most 64 wait.
approved sign-in and carries scope
mcp,eventsor both. The grants pagelists principals, clients, grants and last use, and revokes a client or a
principal.
/mcp/<id>and itslgm_tokens are unchanged. Existing tests areunchanged (the diff of existing
_test.gofiles is additions only).oauthis reserved, andapp.jsongets an optionalhearthmember naming the hearth manifest.
Overlap: #81 (embedded NATS) touches
docs/specs/lodge-http.md,docs/specs/app-contract.md,docs/design/overview.md,AGENTS.md,.github/risk-paths.json,cmd/lodge/main.go,internal/gateway/gateway.go,kit/manifest/manifest.goandgo.mod. Whichever merges second takes a mergeof main. The
eventsscope is recorded now; #81's broker reads it later.Risk tier
Risk tier: 3 — new authentication and credential issuance, and a browser route that writes.
Matched paths in
.github/risk-paths.jsonand why the change is safe:internal/oauth/**(L1, new): the OAuth server, its storage and thepages. Tokens are HMACs with a 32-byte key made at the first start; only
signatures are stored (
TestNoTokenInRows). Every decision needs anadmin, same-origin, the request's CSRF token and the request hash, each
with a negative test.
internal/gateway/oauth.go(L1, new): the checks of the OAuth and consentroutes, in the order of lodge-http.md's "OAuth routes". OAuth routes refuse
any
Origin; consent routes run every identity check and the admin check.internal/gateway/gateway.go(L1): 1 Config field and 1 dispatch case.Other routes are untouched.
cmd/lodge/main.go(L1): wiring only;mcpBaserenamedbaseand sharedwith the issuer.
internal/allow/**,internal/control/**(L1): the admin list and its 3control methods, modeled on the login list.
internal/apps/apps.go(L1): reads the optional hearth manifest (regularfile, 1 MiB cap, format major 1, matching app ID); a bad one disables only
that app.
kit/manifest/**(L1): the reserved IDoauthand the optionalhearthmember. Additive: an existing
app.jsonstays valid.internal/store/migrations/**(L1): migration 0005 only creates newtables; no existing table changes.
internal/repocheck/**(L2): a new test of fosite's import boundary..github/risk-paths.json(L2): adds the 2 new L1 globs above.Docs housekeeping
TEMPLATE.mddocs/README.mdVerification
make cigreen before the first push (verify, race, cross, and client-check, ui-check, shell-check in nsl)make vulncheck: "No vulnerabilities found" in both modules (fosite's indirect dependencies are raised for it)internal/oauth/oauth_test.go,internal/gateway/oauth_test.go(discovery, registration, PKCE S256, loopback redirect on a random port,
refresh rotation, reuse revokes the family, admin only, consent negatives:
Origin, Sec-Fetch-Site, CSRF, hash, decided twice, expired, narrowing),
plus the admin list in
allow,controlandlodgectl.