~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

compat: tranquil beside the others, at its main

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:compat/tranquil
bench/impls.json+3−3
@@ -36,10 +36,10 @@
"tranquil": {
"source": "https://tangled.org/tranquil.farm/tranquil-pds, built from source with its own Dockerfile, for this machine's architecture; on PostgreSQL, its default repository backend",
"repo": "https://tangled.org/tranquil.farm/tranquil-pds",
"release": "v0.8.0",
"commit": "ce17e8a4948aa216c6c1056122966a11b8a693c8",
"release": "main, 10 commits past v0.8.0",
"commit": "b95f999e639fbf392ffe9c21a84a38b21704536c",
"dockerfile": "Dockerfile",
"tag": "monolith-bench-tranquil:ce17e8a",
"tag": "monolith-bench-tranquil:b95f999",
"needs": ["postgres"]
},
"pds.js": {
bench/README.md+2−2
@@ -15,7 +15,7 @@ in [`impls.json`](impls.json), so nothing on the machine is set up by hand.
| vlpds | its release image `ghcr.io/jazware/vlpds`, v1.3.0 (commit `91fa452`) | image digest in `impls.json` |
| RustFS (vlpds's S3 store) | `rustfs/rustfs` 1.0.4 | image digest in `impls.json` |
| zds | `tangled.org/zat.dev/zds` v0.7.8, built by `--setup` with its own `Dockerfile` for this machine's architecture and tagged `monolith-bench-zds:cef2c63` | repository URL and commit `cef2c63` in `impls.json` |
| tranquil | `tangled.org/tranquil.farm/tranquil-pds` v0.8.0, built by `--setup` with its own `Dockerfile` for this machine's architecture and tagged `monolith-bench-tranquil:ce17e8a` | repository URL and commit `ce17e8a` in `impls.json` |
| tranquil | `tangled.org/tranquil.farm/tranquil-pds` main at `b95f999` (10 commits past v0.8.0), built by `--setup` with its own `Dockerfile` for this machine's architecture and tagged `monolith-bench-tranquil:b95f999` | repository URL and commit `b95f999` in `impls.json` |
| PostgreSQL (tranquil's database) | `postgres` 18.7 on Alpine, run the way tranquil's compose files run it | image digest in `impls.json` |
| pds.js | `knotless://chadtmiller.com/pds.js` main at `54f4e3a` (35 commits past v2.5.2), built by `--setup` with its own `Dockerfile` and tagged `monolith-bench-pdsjs:54f4e3a`. Only the compatibility check runs it (compat/README.md), since it hosts one account and the workload makes 40 | repository URL and commit `54f4e3a` in `impls.json` |
@@ -111,7 +111,7 @@ since it's the baseline the others are read against.
fetches zds at its pinned commit into `bench/vendor/zds` (gitignored) and
builds that image with zds's own `Dockerfile` (`docker build`, a few
minutes the first time). It does the same for tranquil, into
`bench/vendor/tranquil` as `monolith-bench-tranquil:ce17e8a` (a Rust
`bench/vendor/tranquil` as `monolith-bench-tranquil:b95f999` (a Rust
workspace, and the longest build of them all). It does the same for
pds.js, into `bench/vendor/pds.js` as `monolith-bench-pdsjs:54f4e3a`, for
the compatibility check.
compat/README.md+57−22
@@ -8,7 +8,8 @@ same random requests to the server and to a reference running beside it,
and compares their answers the way `compare.mjs` does. Unlike `compare.mjs`,
it keeps going past a difference. Each area records which of its checks
agree and which differ, plus the first difference in full.
[`RESULTS.md`](RESULTS.md) is a run against Monolith, zds, vlpds and pds.js.
[`RESULTS.md`](RESULTS.md) is a run against Monolith, zds, vlpds, pds.js and
tranquil.
```sh
just compat # from the repository's root: everything below, in one
@@ -157,7 +158,7 @@ command after `--` with the `PDS_*` environment that `compare.mjs`'s header
lists, reads its mail from `PDS_DEV_MAIL_DIR`, and kills and restarts it as
a process.
**zds**, **vlpds** and **pds.js** run in Docker, from the images
**zds**, **vlpds**, **pds.js** and **tranquil** run in Docker, from the images
`bench.mjs --setup` builds and pulls (pinned in `bench/impls.json`). They're
configured the way the benchmark configures them (`harness/lib/impls.mjs`,
shared with `bench.mjs`), plus whatever a compatibility run needs. pds.js,
@@ -177,24 +178,37 @@ is the URL it's called at. So the adapter gives `https://localhost` as its
public URL and the loopback URL as its issuer, and each is taken out of
answers the way a server's URL is.
| setting | Monolith | zds | vlpds | pds.js |
|---|---|---|---|---|
| PLC directory | `PDS_PLC_URL` | `ZDS_PLC_DIRECTORY` | `VLPDS_PLC_URL`, `VLPDS_PLC_MODE=directory` | `PLC_URL` |
| rotation key, the harness's | `PDS_PLC_ROTATION_KEY_HEX` | `ZDS_PLC_ROTATION_KEY` | `VLPDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX` | **no**: only the account's signing key, which the server holds |
| the reference's recovery key | `PDS_RECOVERY_DID_KEY` | `ZDS_RECOVERY_DID_KEY` | `VLPDS_PLC_RECOVERY_DID_KEY` | **no**: the same |
| server DID `did:web:localhost` | `PDS_HOSTNAME` | `ZDS_SERVER_DID` | `VLPDS_SERVICE_DID` | `PDS_HOSTNAME` until it has its account, then that account's DID |
| hostname `localhost` (requestCrawl's) | `PDS_HOSTNAME` | **no**: it comes from `ZDS_PUBLIC_URL`, which must be the URL the harness calls (DPoP's `htu`) | **no**: the same, and it doesn't ask a relay on another host to crawl when its own host is local | **no**: it tells one relay (`RELAY_URL`) at most every 20 minutes |
| handle domains `.test`, `.example` | `PDS_HANDLE_DOMAINS` | `ZDS_HANDLE_DOMAINS` | **`.test` only**: `VLPDS_HANDLE_DOMAIN=test` (another domain needs two labels) | **no**: its hostname is its only one |
| accounts, more than one | yes | yes | yes | **no**: one, made by `claim` |
| admin password `admin-pass` | `PDS_ADMIN_PASSWORD` | `ZDS_ADMIN_TOKEN` | **no**: its admin token must be 32 bytes or more | **no**: it has no admin methods |
| invites off (or on) | `PDS_INVITE_REQUIRED` | `ZDS_INVITE_REQUIRED` | `VLPDS_INVITE_REQUIRED` | off, since it has none |
| rate limits off (or on) | `PDS_RATE_LIMITS_ENABLED` | **no** general limits to turn on, and full getRepo exports are raised to 8 at once | `VLPDS_NO_RATE_LIMITS` | **no** limits to turn on |
| the harness's AppView | `PDS_BSKY_APP_VIEW_*` | `ZDS_PROXY_SERVICE_URL`, `_DID` | `VLPDS_APPVIEW` | `APPVIEW_URL`, `APPVIEW_DID` |
| the harness's crawlers | `PDS_CRAWLERS` | `ZDS_CRAWLERS` | not given (see hostname) | not given (see hostname) |
| OAuth client documents from the harness's web | `PDS_OAUTH_CLIENT_FETCH` | **no**: it fetches the client_id's own https URL | **no**: the same (http only with `--dev-mode`) | **no**: it fetches the client_id's own URL |
| no SSRF guard, the way the reference runs | `PDS_DISABLE_SSRF_PROTECTION` | `ZDS_ALLOW_PRIVATE_FETCH` | its default for operator-set URLs | its default |
| mail | `PDS_DEV_MAIL_DIR` | `ZDS_MAIL_PROVIDER=outbox`, read with `dev.zat.admin.listMail` | **no**: it's readable only with `--dev-mode` | **no**: its container has no transport |
| consent to a narrower scope | the page API | **no**: there's no consent step | **no**: its form only takes scopes away | **no**: its form approves or denies the scope asked for |
**tranquil** runs on a fresh PostgreSQL of its own, on a Docker network
with it, as the benchmark runs it. It names itself `https://<PDS_HOSTNAME>`
everywhere: its OAuth issuer, the endpoint in its DID documents, and the
`htu` its DPoP proofs must name. So the adapter gives it the hostname
`localhost` and `https://localhost` as its public URL, which is its issuer
too, while the harness reaches it on a loopback port: the checks sign each
proof's `htu` with the issuer and send the request to the port. Its one
operator key, `PLC_ROTATION_KEY`, is a public `did:key`, listed first in
each DID it makes, so it takes the reference's recovery key; its other
rotation key is each account's own signing key, which it holds and signs
with, so the harness has none of its own.
| setting | Monolith | zds | vlpds | pds.js | tranquil |
|---|---|---|---|---|---|
| PLC directory | `PDS_PLC_URL` | `ZDS_PLC_DIRECTORY` | `VLPDS_PLC_URL`, `VLPDS_PLC_MODE=directory` | `PLC_URL` | `PLC_DIRECTORY_URL` |
| rotation key, the harness's | `PDS_PLC_ROTATION_KEY_HEX` | `ZDS_PLC_ROTATION_KEY` | `VLPDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX` | **no**: only the account's signing key, which the server holds | **no**: each account's own signing key, which the server holds |
| the reference's recovery key | `PDS_RECOVERY_DID_KEY` | `ZDS_RECOVERY_DID_KEY` | `VLPDS_PLC_RECOVERY_DID_KEY` | **no**: the same | `PLC_ROTATION_KEY`, its one operator key |
| server DID `did:web:localhost` | `PDS_HOSTNAME` | `ZDS_SERVER_DID` | `VLPDS_SERVICE_DID` | `PDS_HOSTNAME` until it has its account, then that account's DID | `PDS_HOSTNAME` |
| hostname `localhost` (requestCrawl's) | `PDS_HOSTNAME` | **no**: it comes from `ZDS_PUBLIC_URL`, which must be the URL the harness calls (DPoP's `htu`) | **no**: the same, and it doesn't ask a relay on another host to crawl when its own host is local | **no**: it tells one relay (`RELAY_URL`) at most every 20 minutes | **no**: with the hostname `localhost` it asks no crawler to crawl |
| handle domains `.test`, `.example` | `PDS_HANDLE_DOMAINS` | `ZDS_HANDLE_DOMAINS` | **`.test` only**: `VLPDS_HANDLE_DOMAIN=test` (another domain needs two labels) | **no**: its hostname is its only one | `PDS_USER_HANDLE_DOMAINS=test,example`, which it names with no leading dot |
| accounts, more than one | yes | yes | yes | **no**: one, made by `claim` | yes |
| admin password `admin-pass` | `PDS_ADMIN_PASSWORD` | `ZDS_ADMIN_TOKEN` | **no**: its admin token must be 32 bytes or more | **no**: it has no admin methods | **no**: an admin is an account marked so in its database |
| invites off (or on) | `PDS_INVITE_REQUIRED` | `ZDS_INVITE_REQUIRED` | `VLPDS_INVITE_REQUIRED` | off, since it has none | `INVITE_CODE_REQUIRED` |
| rate limits off (or on) | `PDS_RATE_LIMITS_ENABLED` | **no** general limits to turn on, and full getRepo exports are raised to 8 at once | `VLPDS_NO_RATE_LIMITS` | **no** limits to turn on | `DISABLE_RATE_LIMITING` |
| the harness's AppView | `PDS_BSKY_APP_VIEW_*` | `ZDS_PROXY_SERVICE_URL`, `_DID` | `VLPDS_APPVIEW` | `APPVIEW_URL`, `APPVIEW_DID` | **no** setting: it proxies by the `atproto-proxy` header, resolving the DID that names |
| the harness's crawlers | `PDS_CRAWLERS` | `ZDS_CRAWLERS` | not given (see hostname) | not given (see hostname) | not given (see hostname) |
| OAuth client documents from the harness's web | `PDS_OAUTH_CLIENT_FETCH` | **no**: it fetches the client_id's own https URL | **no**: the same (http only with `--dev-mode`) | **no**: it fetches the client_id's own URL | **no**: it fetches the client_id's own URL |
| no SSRF guard, the way the reference runs | `PDS_DISABLE_SSRF_PROTECTION` | `ZDS_ALLOW_PRIVATE_FETCH` | its default for operator-set URLs | its default | `ALLOW_PRIVATE_FETCH` |
| mail | `PDS_DEV_MAIL_DIR` | `ZDS_MAIL_PROVIDER=outbox`, read with `dev.zat.admin.listMail` | **no**: it's readable only with `--dev-mode` | **no**: its container has no transport | **no**: it sends only to an SMTP relay and keeps none to read back |
| reached at the address it names | yes | yes | yes | yes | **no**: it names itself `https://localhost`, reached on a loopback port |
| consent to a narrower scope | the page API | **no**: there's no consent step | **no**: its form only takes scopes away | **no**: its form approves or denies the scope asked for | **no**: its consent takes the scopes approved, but the hook carries none (below) |
Each "no" skips these checks:
@@ -206,6 +220,8 @@ Each "no" skips these checks:
- more than one account: those above
- the harness's rotation key: its own PLC operation before an updateHandle
- the recovery key: `recommendedCredentials`
- the address it names: `oauthClientLibrary`, as the atproto client library
refuses an https address on a loopback host
No core check needs mail, the admin password or rate limits.
@@ -234,7 +250,18 @@ and `csrf` field), posts `/oauth/authorize/sign-in` (`identifier`,
**pds.js**'s hook posts its consent form (`POST /oauth/authorize`:
`request_uri`, `client_id`, `password`, `action=approve` or `deny`). The form
doesn't ask for an identifier, since the server has one account, and it
redirects to the client with a 302. None of them needs a browser.
redirects to the client with a 302. **tranquil**'s page is a script calling
its JSON endpoints, and its hook calls them as the script does: it posts
`request_uri`, `username` and `password` to `/oauth/authorize`, which
answers the next page as `redirect_uri`. That's the consent page, whose
scopes `/oauth/authorize/consent` answers and then takes back approved, or
at once tranquil's `/oauth/authorize/redirect`, which redirects to the
client with a 303. To refuse, it posts `request_uri` to
`/oauth/authorize/deny`, which answers the client's URL with
`error=access_denied` as JSON, and the script navigates there; the hook
answers that as a 303 there. Its consent can approve fewer scopes than were
asked, but the hook is given no scope to approve, so it approves the scope
asked. None of them needs a browser.
When an adapter has a hook, the reference still signs in through its page
API, but its page's answers are its own and aren't compared. The server
@@ -259,6 +286,10 @@ section, with the reason for each:
redirect on
- Monolith's own departures aren't held against them
- a server that hosts one account uses that one
- a server with password rules of its own gets each area's first accounts
with a password its adapter makes to fit them
- a server named by an https address it isn't reached at has the requests
for that address sent where it is reached
- the settings an adapter can't give have their checks skipped and reported
The harness allows nothing else, and Monolith is held to all of
@@ -316,7 +347,11 @@ Here are the steps:
`unsupported` with reasons, `signIn` unless it serves the reference's
page API, and `readyMs` if it starts slowly. For a server that hosts one
account, it also lists `accounts` in `unsupported` and gets `password`
and `claim` from `start`.
and `claim` from `start`. For a server that refuses passwords by a rule
of its own, it has `passwordFor(p)` (spec/COMPAT.md, "Password rules").
For a server that names itself by an https origin it isn't reached at,
`start` answers that origin as `publicUrl` and `fronted: true`
(spec/COMPAT.md, "Its own address").
3. Add its name to `IMPLS` in `harness/compat.mjs`, and add the differences
its documentation says are on purpose to `DELIBERATE` there.
4. Run `node compat.mjs --impls <name> --steps 60` to try it, then do a full
compat/results.json+6797−145
A large diff, not shown.
compat/RESULTS.md+648−24
672 lines changed: not loaded until asked for.
docs/guide/comparing.md+1−1
@@ -365,7 +365,7 @@ adapter in `harness/lib/adapters/`, and keeps going past a difference.
[compat/README.md](../../compat/README.md) says which checks it runs and
how to add an implementation.
[compat/RESULTS.md](../../compat/RESULTS.md) holds the last run, against
Monolith, zds, vlpds and pds.js.
Monolith, zds, vlpds, pds.js and tranquil.
```sh
just compat
harness/checks/accounts.mjs+4−1
@@ -161,8 +161,11 @@ const freeEmails = () => accounts.filter((a) => !a.password && !accounts.some((b
/// createAccount that both sides must make: mixed-case handles and emails,
/// accounts with no password or an empty one, and sometimes the email of an
/// account without a password (spec/ACCOUNTS.md, "createAccount").
export async function createAccount({ withPassword = false } = {}) {
export async function createAccount({ withPassword = false, password } = {}) {
const d = newDetails(withPassword)
// A first account's password, made to fit the server's own rules
// (spec/COMPAT.md, "Password rules"): no draw, and on Monolith the same.
if (password && typeof d.password === 'string') d.password = password(d.password)
const free = freeEmails()
if (free.length && chance(0.2)) d.email = pick(free)
const body = inputOf(d, true)
harness/lib/adapters/index.mjs+11−1
@@ -29,6 +29,10 @@
// `claim({handle, email})`, which makes that account and
// answers `{status, body}`, the body a session's as
// createSession answers it (spec/COMPAT.md, "One account").
// A server that names itself by an https origin it is not
// reached at answers that origin as `publicUrl` and
// `fronted: true`: every request for it then goes to `url`
// (spec/COMPAT.md, "Its own address").
// port() a port for it to listen on.
// info() what it is: `{version, source, config}`.
// unsupported each setting it cannot be given, by name, with why. The
@@ -46,6 +50,11 @@
// the client, with its `code` (a redirect, or a `form_post`
// page), as lib/oauth.mjs's Browser answers. Only that answer
// is compared with the reference's.
// passwordFor(p)
// for a server that refuses passwords by rules of its own,
// a password they take made from `p`, the same each time and
// with no draw: each area's first accounts are made with it
// (spec/COMPAT.md, "Password rules"). None for Monolith.
// own whether Monolith's own rules hold it: its commands, logs,
// traces and metrics, store and scale, the exact numbers of
// its limits, its timing floors, and what the specs it is
@@ -56,8 +65,9 @@
import pdsjs from './pds.js.mjs'
import monolith from './monolith.mjs'
import tranquil from './tranquil.mjs'
import vlpds from './vlpds.mjs'
import zds from './zds.mjs'
/// The adapters, by name.
export const ADAPTERS = { monolith, zds, vlpds, 'pds.js': pdsjs }
export const ADAPTERS = { monolith, zds, vlpds, 'pds.js': pdsjs, tranquil }
harness/lib/adapters/tranquil.mjsnew+134−0
@@ -0,0 +1,134 @@
// tranquil, in Docker, from the image `node bench.mjs --setup` builds from
// its pinned commit (bench/impls.json), on a fresh PostgreSQL, configured as
// lib/impls.mjs configures it, plus what a compatibility run needs.
import { spawnSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { join } from 'node:path'
import { Browser } from '../oauth.mjs'
import { dockerPort, imageId, pins, shOk, startPostgres, tranquilCreateArgs, tranquilEnv, tranquilOwnEnv } from '../impls.mjs'
import { DOCKER_NEEDS, container } from './common.mjs'
const TRANQUIL = pins.implementations.tranquil
/// The origin tranquil names itself by: `https://<PDS_HOSTNAME>`, its
/// issuer, its DID documents' endpoint and the `htu` its DPoP proofs must
/// name (crates/tranquil-config/src/lib.rs:583-586,
/// crates/tranquil-oauth-server/src/endpoints/token/grants.rs:100), though
/// the harness reaches it on a loopback port (spec/COMPAT.md, "Its own
/// address").
const NAMED = 'https://localhost'
export default {
about: `tranquil ${TRANQUIL.release} (${TRANQUIL.repo} at ${TRANQUIL.commit.slice(0, 7)}), its image built by \`node bench.mjs --setup\`, on PostgreSQL, in Docker`,
pageApi: false,
own: false,
unsupported: {
rotationKey: 'tranquil signs each account\'s PLC operations with that account\'s own signing key, which it holds and which is always one of its rotation keys; its one operator key, PLC_ROTATION_KEY, is a public did:key it cannot sign with (crates/tranquil-config/src/lib.rs:648-653, crates/tranquil-pds/src/plc/mod.rs:368-377): the harness has no key to sign an operation of its own with',
hostname: 'tranquil names itself https://<PDS_HOSTNAME>, which must be localhost for the reference\'s server DID, and with that hostname it asks no crawler to crawl (crates/tranquil-pds/src/crawlers.rs:45-48)',
clientFetch: 'tranquil fetches a client document from the client_id\'s own URL (crates/tranquil-oauth/src/client.rs:251); it has no mapping of origins to the harness\'s web, as PDS_OAUTH_CLIENT_FETCH is',
narrowScope: 'tranquil\'s consent takes the scopes approved (crates/tranquil-oauth-server/src/endpoints/authorize/consent.rs:87), but the sign-in hook (compat/README.md, "The OAuth sign-in hook") carries no scope to approve: the scope asked is approved',
adminPassword: 'tranquil has no admin password: an admin is an account marked so in its database, calling with its own access token (crates/tranquil-pds/src/auth/extractor.rs:170, 214)',
mail: 'tranquil sends mail only to an SMTP relay (MAIL_SMARTHOST_HOST, crates/tranquil-config/src/lib.rs:1152) and keeps none to read back; with no sender address its email is off',
restart: 'a container keeps the environment it was made with: no restart with another',
address: 'tranquil names itself https://localhost, reached in the run on a loopback port (spec/COMPAT.md, "Its own address"); the atproto OAuth client library refuses an https resource on a loopback host, so it cannot sign in to it here',
lexiconAuthority: 'tranquil looks a permission set\'s lexicon up in DNS, as `_lexicon.<authority>` (crates/tranquil-scopes/src/permission_set.rs:297), with no setting naming one DID for every NSID, as PDS_LEXICON_AUTHORITY_DID does; the harness serves no DNS',
},
port: dockerPort,
readyMs: 120_000,
/// A password tranquil's rules take (spec/COMPAT.md, "Password rules"):
/// 8 to 256 bytes, with a lowercase and an uppercase letter and a digit
/// (crates/tranquil-pds/src/validation/mod.rs:275-299), made from `p`:
/// `p` itself if it fits, else `p` (or, past 240 bytes, its SHA-256 in
/// hex) with `-Aa1` after it.
passwordFor(p) {
const bytes = Buffer.byteLength(p)
if (bytes >= 8 && bytes <= 256 && /[a-z]/.test(p) && /[A-Z]/.test(p) && /[0-9]/.test(p)) return p
return `${bytes <= 240 ? p : createHash('sha256').update(p).digest('hex')}-Aa1`
},
async info() {
const db = pins.images[TRANQUIL.needs[0]]
return { version: TRANQUIL.release, source: `${TRANQUIL.repo} at ${TRANQUIL.commit}, image ${TRANQUIL.tag} (${await imageId(TRANQUIL.tag)}) built with its own ${TRANQUIL.dockerfile}; PostgreSQL ${db.image} (${db.release})`, config: '' }
},
async start(o) {
for (const image of [TRANQUIL.tag, pins.images[TRANQUIL.needs[0]].image]) if (!(await imageId(image))) throw new Error(`tranquil: no Docker image ${image}; ${DOCKER_NEEDS}`)
const id = `compat-tranquil-${process.pid}-${Date.now()}`
const store = `${id}-db`
const pds = `${id}-pds`
const teardown = () => {
spawnSync('docker', ['rm', '-f', '-v', pds])
spawnSync('docker', ['rm', '-f', '-v', store])
spawnSync('docker', ['network', 'rm', id])
}
let env
try {
await shOk('docker', ['network', 'create', id])
const db = await startPostgres(id, store)
// The harness's setup, as far as tranquil takes it
// (crates/tranquil-config/src/lib.rs): the reference's hostname, so
// its server DID; the handle domains, which it names with no
// leading dot; the reference's recovery key, its one operator key,
// listed first in each DID it makes; invites and rate limits on or
// off. No AppView setting: it proxies by the `atproto-proxy` header,
// resolving the DID it names.
env = {
...tranquilEnv,
...tranquilOwnEnv({ plcUrl: o.plc, db }),
PDS_HOSTNAME: 'localhost',
PDS_USER_HANDLE_DOMAINS: 'test,example',
PLC_ROTATION_KEY: o.recoveryKey,
INVITE_CODE_REQUIRED: String(o.invites),
DISABLE_RATE_LIMITING: String(!o.limits),
}
await shOk('docker', tranquilCreateArgs({ name: pds, network: id, port: o.port, env }))
} catch (e) {
teardown()
throw e
}
const url = `http://127.0.0.1:${o.port}`
return {
server: container(pds, env, join(o.logDir, 'server.log'), join(o.logDir, 'server.err'), teardown),
url,
publicUrl: NAMED,
fronted: true,
recoveryKey: o.recoveryKey,
// Each account's own signing key (see `unsupported`).
rotationKey: null,
plcSigner: null,
admin: null,
takeMail: () => [],
}
},
/// tranquil's authorization page, a script calling its JSON endpoints
/// (crates/tranquil-oauth-server/src/endpoints/authorize/), as its script
/// calls them: sign-in posts `request_uri`, `username` and `password` to
/// /oauth/authorize, which answers the next page as `redirect_uri`: the
/// consent page, whose scopes /oauth/authorize/consent answers and
/// approves, or at once the redirect. That redirect,
/// /oauth/authorize/redirect, answers the 303 to the client. Refusing,
/// /oauth/authorize/deny answers the client's URL with
/// `error=access_denied` as JSON, which the script navigates to: here a
/// 303 there, as the browser goes.
async signIn(account, authorizeUrl, consent) {
const at = (u) => new URL(u, NAMED).href
const page = new URL(authorizeUrl)
const requestUri = page.searchParams.get('request_uri')
const b = new Browser()
const call = (path, body) => b.request(at(path), { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json', origin: page.origin, referer: page.href }, body: JSON.stringify(body) })
await b.navigate(page.href)
if (!consent.approve) {
const denied = await call('/oauth/authorize/deny', { request_uri: requestUri })
if (denied.status !== 200 || typeof denied.json?.redirect_uri !== 'string') return denied
return { status: 303, headers: { location: denied.json.redirect_uri }, text: '', json: undefined, data: {} }
}
let next = await call('/oauth/authorize', { request_uri: requestUri, username: account.identifier, password: account.password, remember_device: false })
if (next.status !== 200 || typeof next.json?.redirect_uri !== 'string') return next
if (new URL(next.json.redirect_uri, NAMED).pathname.startsWith('/app/oauth/consent')) {
const shown = await b.request(at(`/oauth/authorize/consent?${new URLSearchParams({ request_uri: requestUri })}`), { headers: { accept: 'application/json', referer: page.href } })
if (shown.status !== 200 || !Array.isArray(shown.json?.scopes)) return shown
const approved = [...shown.json.scopes.map((s) => s.scope), ...(shown.json.permission_sets ?? []).map((s) => s.include_scope)]
next = await call('/oauth/authorize/consent', { request_uri: requestUri, approved_scopes: approved, remember: false })
if (next.status !== 200 || typeof next.json?.redirect_uri !== 'string') return next
}
return b.navigate(at(next.json.redirect_uri), { site: 'same-origin', referer: page.href })
},
}
harness/lib/areas.mjs+3−3
@@ -21,7 +21,7 @@ import { below, chance, pick } from './random.mjs'
import { fail, plcLog } from './plc.mjs'
import { adapter, cand, ref, shutdown } from './processes.mjs'
import { allowed, count, counts, differ, found, run } from './report.mjs'
import { can } from './server.mjs'
import { can, passwordFor } from './server.mjs'
import { accounts, didOf } from './state.mjs'
import { both, shown, xrpc } from './xrpc.mjs'
import { accountRace, createAccount, createAccountRefused, createSession, crossWrites, made, newDetails } from '../checks/accounts.mjs'
@@ -98,7 +98,7 @@ export const AREAS = {
oauth: {
about: 'OAuth, the protocol: the server\'s metadata, PAR, the code exchange with PKCE, DPoP and its nonces, refresh and its rotation, revocation, DPoP-bound calls to XRPC, and a client app\'s own library',
pre: [[checkOAuthMetadata]],
steps: [[oauthLogin, 4], [oauthParRefused, 3], [oauthDpopRefused, 3], [oauthTokenRefused, 2], [oauthRevokeRefused, 1], [oauthRefresh, 3], [oauthRevoke, 2], [oauthGetSession, 2], [oauthClientLibrary, 1]],
steps: [[oauthLogin, 4], [oauthParRefused, 3], [oauthDpopRefused, 3], [oauthTokenRefused, 2], [oauthRevokeRefused, 1], [oauthRefresh, 3], [oauthRevoke, 2], [oauthGetSession, 2], [oauthClientLibrary, 1, ['address']]],
},
'oauth scopes': {
about: 'OAuth scopes, enforced on every method: calls with an OAuth session\'s token, and with one thing wrong in its proof, token or scheme',
@@ -242,7 +242,7 @@ export async function areaRun() {
if (!can('accounts')) {
await check(Object.defineProperty(() => claimAccount(), 'name', { value: 'the server\'s one account' }), [], false)
} else {
const first = Object.defineProperty(() => createAccount({ withPassword: true }), 'name', { value: 'createAccount (a first account)' })
const first = Object.defineProperty(() => createAccount({ withPassword: true, password: passwordFor }), 'name', { value: 'createAccount (a first account)' })
const want = 2 + below(2)
for (let tries = 0; accounts.length < want && tries < 10; tries++) await check(first, [], false)
}
harness/lib/front.mjsnew+27−0
@@ -0,0 +1,27 @@
// A server named by an https origin it is not reached at in the run, as
// one behind a TLS front is (spec/COMPAT.md, "Its own address"): every
// request the harness makes for that origin goes to the URL it is reached
// at, and is otherwise as it was. Nothing is set for Monolith, or for any
// server reached at the address it names: then every URL is as given.
let front = null
/// From now on, requests for `origin`'s URLs go to `url` instead.
export function setFront(origin, url) {
front = { origin: new URL(origin).origin, url }
const sent = globalThis.fetch
globalThis.fetch = (input, init) => {
if (typeof input === 'string' || input instanceof URL) return sent(reach(input), init)
// A Request, as the OAuth client library's fetch makes them: the same
// request, for the reached URL.
const to = reach(input.url)
return sent(to === input.url ? input : new Request(to, input), init)
}
}
/// Where a request for `u` is sent: `u` itself, unless it is the front's.
export function reach(u) {
if (!front) return u
const s = String(u)
return s === front.origin || s.startsWith(`${front.origin}/`) || s.startsWith(`${front.origin}?`) ? front.url + s.slice(front.origin.length) : u
}
harness/lib/oauth.mjs+2−1
@@ -10,6 +10,7 @@
import { createHash, randomBytes, webcrypto } from 'node:crypto'
import http from 'node:http'
import { reach } from './front.mjs'
import { begin, end, noteSetCookies, noteUrl, now, toServer } from './observe.mjs'
const { subtle } = webcrypto
@@ -140,7 +141,7 @@ export class Browser {
return new Promise((resolve) => {
const all = Object.fromEntries(Object.entries({ cookie: this.cookieHeader() || undefined, ...headers }).filter(([, v]) => v !== undefined))
const rec = toServer(url) ? begin(method, url, all, body) : null
const req = http.request(url, { method, headers: all }, (res) => {
const req = http.request(reach(url), { method, headers: all }, (res) => {
const chunks = []
res.on('data', (c) => chunks.push(c))
res.on('end', () => {
harness/lib/processes.mjs+4−0
harness/lib/server.mjs+5−0
harness/compat.mjs+12−6
spec/COMPAT.md+33−1