gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainfe209ffeMerge branch 'w56-owner-members' into mainGitoriamain/reports/W42-REPORT.md

5.4 KB

  1. # W42 report — gitoria#42: an app's short-lived token, git read over HTTPS
  2. Branch `w42-app-token` (worktree `/media/STORAGE/claude-scratch/gitoria/W42/wt`), one commit `b5d696f` on top of main fdb9ed2. Not pushed, not deployed, no tickets touched.
  3. `docs/apps-api.md` is untracked in main, so I copied it into the worktree to read it and did NOT commit it.
  4. ## Built
  5. - `lib/app-tokens.hl` (new): table `apptokens.db` { hash (sha256 only), app, repo, created, expires }. `issueToken`, `rowOfToken`, `dropTokensOfApp`, `sweepExpired`.
  6. Token = `gat_` + 40 hex, life 1 h. Expired rows are swept on every issue (no timer) and deleted when found expired at use.
  7. `GITORIA_APP_TOKEN_LIFE_MS` shortens the life, for the gate only.
  8. - `lib/app-auth.hl` (new): `appOfRequest(route, req)` → `{ app, repo }` or `{ error }` (a ready §6 Response).
  9. 401 `unauthorized` for a missing, unknown or expired token, or an app that was removed. 404 `not_found` when the token's repo is not the repo the address names. Also `bearerOf`, `unauthorized()`, `notFound()`, `appOfToken`.
  10. - `lib/apps.hl`: `removeApp` and a re-connect (a new key) call `dropTokensOfApp`, so the tokens die at once.
  11. - `lib/api.hl`: `appToken` route, `POST {api}/apps/token` with `Bearer gak_…` → `200 {"token","expires"}`.
  12. `expires` is UTC ISO with milliseconds (`timestamp()`), e.g. `2026-11-02T07:00:00.000Z`; the contract's example has no ms.
  13. GET → 405 `invalid`. No, unknown or wrongly shaped key → 401. A key used on another repo's address → 404.
  14. - `lib/transport.hl`: a `gat_` password = READ of its own repo, including a private one, on the repo address and the org address.
  15. Push (`info/refs?service=git-receive-pack` and the POST) → 403. Another repo: no access, i.e. a private repo gives 404 "no such repository", a public repo is plain anonymous read as before. An expired or removed token also counts as no credential.
  16. - apiError already gave exactly the §6 shape, so it is reused unchanged.
  17. ## API base, both spellings (point 4)
  18. `apiPatterns(path)` in `lib/api-helpers.hl` returns `['/api'+path, '/api/:orepo'+path, '/:orepo/api'+path]`. project.hl lists a route once:
  19. `for (p of apiPatterns('/apps/token')) { { pattern = p function = appToken } }`. The exchange route now uses the same helper.
  20. #43/#44 add routes the same way, with `:n` and the like inside `path`. Inside the handler, `repoOfRequest(route, req)` reads `route.params.orepo`.
  21. ## Tests
  22. - `tests/app-token.mjs` (added to GATES in deploy.sh), 42 checks, 0 failed. It covers:
  23. - issue and token shape;
  24. - a 3 s life, with the first token still working beside a newer one, then dead after the life;
  25. - the key as password and the missing / unknown key cases;
  26. - wrong repo 404 and no-repo 404;
  27. - the org address in both spellings;
  28. - git ls-remote, clone and v2 shallow fetch with the token on a private repo, with any user name;
  29. - push refused 403;
  30. - the token on another private repo → 404 and on a public repo → anonymous read;
  31. - re-connect and remove kill the old tokens;
  32. - the key and every token never appear in the server log, even when the key is used as a git URL password or a query value;
  33. - a restart.
  34. - `tests/app-auth-unit.hl` (run by the gate): calls `appOfRequest` directly, because no API route uses it yet.
  35. - Full gates, `LC_ALL=C`, ports inside 8730–8739: signin-return 3/0, check-theme 61 files 0 problems, browser 265/0, security 82/0, private 158/0, ident-access-gitoria 30/0, apps 95/0, app-token 42/0. 0 failed, no flake.
  36. - Not run: his Chrome on lisbeth, since there is no UI change. The old-code failure of the new checks is trivially true (no route, no table).
  37. ## Contract points
  38. - Covered: §0 key and token, §2 token route, Bearer and Basic with `gat_`, read-only, own repo only, §3 fetch with the token (clone, ls-remote, shallow v2 fetch; `refs/pull/*` is served by the same upload-pack once they exist), §6 401 and 404 codes.
  39. - Not covered: the API routes that use `appOfRequest` (#44). `appOfRequest` is tested only directly. §6 429 and 413 are #47.
  40. ## Bugs found on the way (mine, fixed)
  41. A hybrid literal `{ app = a.id repo = a.repo }` rebinds `app` inside the literal, so a parameter named `app` read as a String. I renamed the parameter. This may be worth a DOCS note: inside a hybrid literal a named entry shadows a same-named outer variable for the later entries.
  42. ## DOCS / GAP
  43. DOCS used: HL-PRIMER, CODE-ORDER, hl:time README (`timestamp`). No framework gap hit. No UI, so the COMPONENTS sections were not needed. Open question for docs: the route list in project.hl takes `for (p of …) { { … } }` splices. It works (gate proves it), but I found it only by trying; it is not shown in the docs I read.
  44. ## Open risks
  45. - `expires` carries milliseconds; a strict client parsing `…:00Z` literally would need an ISO parser. Easy to cut if Kunibert wants it.
  46. - Sweep cost is one pass over the token table per issue; fine for ≤20 apps per repo at one token per hour.
  47. - A token for a private repo is not tied to the app's later settings (e.g. the repo turning private→public); it simply reads the same repo.
  48. - With the same app and key, an exchange (reconnect) invalidates its tokens at once; an app that holds a token across a reconnect gets 401 and must fetch a new one, which is the contract's "get a new token" path.
  49. - Requests used: ~35.
  50. ## Stopped / left
  51. Two server processes of my own aborted gate run (pids 3511390 and 3511171) were killed. At the end nothing of mine runs or listens (`ss` on 873x is empty, no Chrome in my scratch). Test stores are under `wt/.scratch/` (git-ignored).

Branches

Latest commits

  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre