chadtmiller.com/monolith
An atproto PDS
0
0
Compatibility: pds.js, and a server that hosts one account
bench/impls.json+8−0
| @@ -24,6 +24,14 @@ | ||
"commit": "cef2c63d7d6d7dd87b90100566307e9aa8a4d170", | ||
"dockerfile": "Dockerfile", | ||
"tag": "spec-pds-bench-zds:cef2c63" | ||
}, | ||
"pds.js": { | ||
"source": "knotless://chadtmiller.com/pds.js, built from source with its own Dockerfile, for this machine's architecture; run by the compatibility check only, as it hosts one account and the benchmark's workload makes 40", | ||
"repo": "knotless://chadtmiller.com/pds.js", | ||
"release": "main, 35 commits past v2.5.2", | ||
"commit": "54f4e3a70b9d97aece3b3c9a67e65d51591415ea", | ||
"dockerfile": "Dockerfile", | ||
"tag": "spec-pds-bench-pdsjs:54f4e3a" | ||
} | ||
}, | ||
"images": { | ||
bench/README.md+7−3
| @@ -15,6 +15,7 @@ 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, tagged `spec-pds-bench-zds:cef2c63` | repository URL and commit `cef2c63` 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`, tagged `spec-pds-bench-pdsjs:54f4e3a`; run by the compatibility check only (compat/README.md), as it hosts one account and the workload makes 40 | repository URL and commit `54f4e3a` in `impls.json` | | ||
| ||
zds's published image (`atcr.io/zat.dev/zds:latest`) is amd64 only and | ||
predates v0.7.8, so the bench builds its own from the pinned commit. The | ||
| @@ -48,8 +49,9 @@ docker run --rm --network probe -e VLPDS_S3_ENDPOINT=http://s3:9000 -e VLPDS_S3_ | ||
| Node | 24 (24.22.1) | the bench client, the reference PDS, the PLC directory | | ||
| npm | 11 (11.19.1) | installs the reference from `harness/package-lock.json` | | ||
| rustup | 1.28+ (1.29.1) | builds spec-pds on `stable` (setup installs the toolchain) | | ||
| Docker | 28 (Docker Desktop 28.0.1; its Linux VM 8 CPUs, 7.7 GiB) | runs vlpds, RustFS and zds, and builds zds's image; `host.docker.internal` must reach the host | | ||
| git | any recent (2.50.1) | fetches zds at its pinned commit | | ||
| Docker | 28 (Docker Desktop 28.0.1; its Linux VM 8 CPUs, 7.7 GiB) | runs vlpds, RustFS and zds, and builds zds's and pds.js's images; `host.docker.internal` must reach the host | | ||
| git | any recent (2.50.1) | fetches zds and pds.js at their pinned commits | | ||
| git-remote-knotless | any | lets git fetch pds.js's `knotless://` repository | | ||
| sccache | optional (0.19.0) | `export RUSTC_WRAPPER=sccache` before setup makes rebuilds faster | | ||
| ||
Setup needs the network (crates.io, npm, Docker Hub, ghcr.io, tangled.org, | ||
| @@ -80,7 +82,9 @@ first, the baseline the others are read against. | ||
4. unless Docker has the image `spec-pds-bench-zds:cef2c63` already, 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); | ||
minutes the first time); and **pds.js** the same way, into | ||
`bench/vendor/pds.js`, as `spec-pds-bench-pdsjs:54f4e3a`, for the | ||
compatibility check; | ||
5. pulls the **vlpds** and **RustFS** images by digest, unless Docker has | ||
them already. | ||
| ||
compat/README.md+71−40
| @@ -8,7 +8,7 @@ random requests to the server and to a reference beside it, their answers | ||
compared as `compare.mjs` compares them. Unlike `compare.mjs`, it keeps going | ||
past a difference: each area records its checks that agree and that differ, | ||
and the first difference in full. [`RESULTS.md`](RESULTS.md) is a run against | ||
spec-pds, zds and vlpds. | ||
spec-pds, zds, vlpds and pds.js. | ||
| ||
```sh | ||
just compat # from the repository's root: everything below, in one | ||
| @@ -18,7 +18,7 @@ or by hand: | ||
| ||
```sh | ||
cd harness | ||
node bench.mjs --setup # once: spec-pds's binary, and the zds and vlpds images (bench/README.md) | ||
node bench.mjs --setup # once: spec-pds's binary, and the zds, vlpds and pds.js images (bench/README.md) | ||
node compat.mjs --steps 200 --json ../compat/results.json > ../compat/tables.md | ||
node compat.mjs --report ../compat/results.json # the tables again | ||
``` | ||
| @@ -97,6 +97,15 @@ area. The repository's `checkRepos` and the firehose's checks run every | ||
`--check-every` steps (10) and at the end; sync's crawl checks with the | ||
first accounts, every 10 steps and at the end. | ||
| ||
A server that hosts one account, by design, has that one in every area | ||
([`spec/COMPAT.md`](../spec/COMPAT.md), "One account"): its adapter's | ||
`claim` makes it, beside the reference's, made by createAccount with the | ||
password the server was started with. The checks that make an account | ||
(the accounts area, the firehose's `createAccount`) or need a second | ||
(`crossWrites`, `handleRace`, and updateHandle's refusal of a handle | ||
another account has) are not run; every other check runs on the one | ||
account. | ||
| ||
A check is one step. It goes on past what differs (in a compatibility run | ||
`differ` in `lib/report.mjs` keeps the difference rather than ending the | ||
run), and counts as failed if anything in it differed; one that throws (an | ||
| @@ -114,10 +123,12 @@ the server for the run's setup, and what it is: | ||
- `start(o)` makes the server for the setup `o` (port, data directory, PLC | ||
directory, the reference's recovery key, crawlers, AppView, the web of | ||
OAuth client documents, rate limits and invites on or off): the process | ||
the harness starts, kills and starts again, the URL it calls and the one | ||
the server's DID documents and OAuth issuer name, the rotation keys it | ||
lists in each DID and its own as a signer, its admin's `Authorization`, | ||
and `takeMail()`, the emails it sent. | ||
the harness starts, kills and starts again, the URL it calls, the one the | ||
server's DID documents name, and its OAuth issuer where that is another, | ||
the rotation keys it lists in each DID and its own as a signer, its | ||
admin's `Authorization`, and `takeMail()`, the emails it sent. A server | ||
that hosts one account answers too its `password` and `claim`, which | ||
makes that account. | ||
- `unsupported` lists each setting it cannot be given, with why: the checks | ||
that depend on one are skipped, and the report says why. | ||
- `pageApi`, or `signIn` (below). | ||
| @@ -127,37 +138,50 @@ the server for the run's setup, and what it is: | ||
`--`, given the `PDS_*` environment `compare.mjs`'s header lists, its mail | ||
read from `PDS_DEV_MAIL_DIR`, killed and restarted as a process. | ||
| ||
**zds** and **vlpds** run in Docker, from the images `bench.mjs --setup` | ||
builds and pulls (pinned in `bench/impls.json`), configured as the benchmark | ||
configures them (`harness/lib/impls.mjs`, shared with `bench.mjs`), plus what | ||
a compatibility run needs. The harness reaches each on a loopback port; each | ||
reaches the harness's PLC directory, AppView and crawlers through | ||
`host.docker.internal`. The server is the container: started, killed with a | ||
signal, and its log followed with `docker logs`. | ||
| ||
| setting | spec-pds | zds | vlpds | | ||
|---|---|---|---| | ||
| PLC directory | `PDS_PLC_URL` | `ZDS_PLC_DIRECTORY` | `VLPDS_PLC_URL`, `VLPDS_PLC_MODE=directory` | | ||
| rotation key, the harness's | `PDS_PLC_ROTATION_KEY_HEX` | `ZDS_PLC_ROTATION_KEY` | `VLPDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX` | | ||
| the reference's recovery key | `PDS_RECOVERY_DID_KEY` | `ZDS_RECOVERY_DID_KEY` | `VLPDS_PLC_RECOVERY_DID_KEY` | | ||
| server DID `did:web:localhost` | `PDS_HOSTNAME` | `ZDS_SERVER_DID` | `VLPDS_SERVICE_DID` | | ||
| hostname `localhost` (requestCrawl's) | `PDS_HOSTNAME` | **no**: from `ZDS_PUBLIC_URL`, which must be the URL the harness calls (DPoP's `htu`) | **no**: the same, and it asks no relay on another host to crawl when its own is local | | ||
| handle domains `.test`, `.example` | `PDS_HANDLE_DOMAINS` | `ZDS_HANDLE_DOMAINS` | **`.test` only**: `VLPDS_HANDLE_DOMAIN=test`; another domain needs two labels | | ||
| admin password `admin-pass` | `PDS_ADMIN_PASSWORD` | `ZDS_ADMIN_TOKEN` | **no**: its admin token must be 32 bytes or more | | ||
| invites off (or on) | `PDS_INVITE_REQUIRED` | `ZDS_INVITE_REQUIRED` | `VLPDS_INVITE_REQUIRED` | | ||
| rate limits off (or on) | `PDS_RATE_LIMITS_ENABLED` | **no** general limits to turn on; full getRepo exports raised to 8 at once | `VLPDS_NO_RATE_LIMITS` | | ||
| the harness's AppView | `PDS_BSKY_APP_VIEW_*` | `ZDS_PROXY_SERVICE_URL`, `_DID` | `VLPDS_APPVIEW` | | ||
| the harness's crawlers | `PDS_CRAWLERS` | `ZDS_CRAWLERS` | 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 SSRF guard, as the reference runs | `PDS_DISABLE_SSRF_PROTECTION` | `ZDS_ALLOW_PRIVATE_FETCH` | its default for operator-set URLs | | ||
| mail | `PDS_DEV_MAIL_DIR` | `ZDS_MAIL_PROVIDER=outbox`, read with `dev.zat.admin.listMail` | **no**: readable only with `--dev-mode` | | ||
| consent to a narrower scope | the page API | **no**: there is no consent step | **no**: its form only takes scopes away | | ||
**zds**, **vlpds** and **pds.js** run in Docker, from the images `bench.mjs | ||
--setup` builds and pulls (pinned in `bench/impls.json`), configured as the | ||
benchmark configures them (`harness/lib/impls.mjs`, shared with | ||
`bench.mjs`; pds.js, which the benchmark does not run, as its container | ||
runs by default), plus what a compatibility run needs. The harness reaches | ||
each on a loopback port; each reaches the harness's PLC directory, AppView | ||
and crawlers through `host.docker.internal`. The server is the container: | ||
started, killed with a signal, and its log followed with `docker logs`. | ||
| ||
**pds.js** hosts one account. Its adapter starts it with a fresh account | ||
password (`PDS_PASSWORD`, which it requires) and claims the account as its | ||
onboarding page does: `POST /account/onboarding/create` with that password, | ||
the handle and the email, same-origin, then createSession by the new DID. | ||
It names its endpoint `https://<PDS_HOSTNAME>` in the DID documents it | ||
makes, and its OAuth issuer is the URL it is called at: the adapter gives | ||
`https://localhost` as its public URL and the loopback URL as its issuer, | ||
each taken out of answers as a server's URL is. | ||
| ||
| setting | spec-pds | 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**: the account's signing key alone, held by the server | | ||
| 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, whose DID it then is | | ||
| hostname `localhost` (requestCrawl's) | `PDS_HOSTNAME` | **no**: from `ZDS_PUBLIC_URL`, which must be the URL the harness calls (DPoP's `htu`) | **no**: the same, and it asks no relay on another host to crawl when its own 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 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**: no admin methods | | ||
| invites off (or on) | `PDS_INVITE_REQUIRED` | `ZDS_INVITE_REQUIRED` | `VLPDS_INVITE_REQUIRED` | off: it has none | | ||
| rate limits off (or on) | `PDS_RATE_LIMITS_ENABLED` | **no** general limits to turn on; full getRepo exports 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, as 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**: readable only with `--dev-mode` | **no**: its container has no transport | | ||
| consent to a narrower scope | the page API | **no**: there is no consent step | **no**: its form only takes scopes away | **no**: its form approves or denies the scope asked | | ||
| ||
The checks each "no" skips: the hostname, sync's crawl checks; the handle | ||
domains, `describeServer`; client documents, the whole of the oauth clients | ||
area; a narrower scope, the narrowing in `oauthLogin` (the scope asked is | ||
granted). Mail, the admin password and rate limits are needed by no core | ||
check. | ||
granted); more than one account, those above; the harness's rotation key, | ||
its own PLC operation before an updateHandle; the recovery key, | ||
`recommendedCredentials`. Mail, the admin password and rate limits are | ||
needed by no core check. | ||
| ||
## The OAuth sign-in hook | ||
| ||
| @@ -180,8 +204,11 @@ signIn(account, authorizeUrl, consent) | ||
client. **vlpds**'s loads the page (its device cookie and `csrf` field), | ||
posts `/oauth/authorize/sign-in` (`identifier`, `password`), and then | ||
`/oauth/authorize/consent` (`did`, `action=allow` or `deny`), which | ||
redirects to the client or answers a `form_post` page. Neither needs a | ||
browser. | ||
redirects to the client or answers a `form_post` page. **pds.js**'s posts | ||
its consent form (`POST /oauth/authorize`: `request_uri`, `client_id`, | ||
`password`, `action=approve` or `deny`), which asks no identifier, as the | ||
server has one account, and redirects to the client with a 302. None needs | ||
a browser. | ||
| ||
With a hook, the reference still signs in through its page API, but its | ||
page's answers are its own, not compared; the server signs in through its | ||
| @@ -199,8 +226,9 @@ with why: the same things taken out of every answer as for spec-pds; the | ||
KEM key optional (held to spec-pds's form if published); an OAuth access | ||
token of 15 or 60 minutes; `describeServer`'s three compared fields; no | ||
check of the exact numbers of limits; sign-in on the server's own page, | ||
compared from the redirect on; spec-pds's own departures not held; and the | ||
settings an adapter cannot give, whose checks are skipped and reported. | ||
compared from the redirect on; spec-pds's own departures not held; one | ||
account, where a server hosts one; and the settings an adapter cannot give, | ||
whose checks are skipped and reported. | ||
The harness lets nothing else, and spec-pds is held to all of `spec/PDS.md` | ||
as before. | ||
| ||
| @@ -224,12 +252,15 @@ those. | ||
| ||
## Adding an implementation | ||
| ||
1. Pin it in `bench/impls.json` and give it a benchmark adapter | ||
(`bench/README.md`); put its Docker configuration in | ||
1. Pin it in `bench/impls.json`, and give it a benchmark adapter | ||
(`bench/README.md`) unless the benchmark's workload is not one it can | ||
serve (pds.js, which hosts one account); put its Docker configuration in | ||
`harness/lib/impls.mjs`. | ||
2. Give it an adapter in `harness/lib/adapters.mjs`: `start`, `port`, | ||
`info`, `unsupported` with why, `signIn` unless it serves the | ||
reference's page API, and `readyMs` if it starts slowly. | ||
reference's page API, `readyMs` if it starts slowly, and for a server | ||
that hosts one account, `accounts` in `unsupported` and `password` and | ||
`claim` from `start`. | ||
3. Add its name to `IMPLS` in `harness/compat.mjs`, and the differences its | ||
documentation says are on purpose to `DELIBERATE` there. | ||
4. `node compat.mjs --impls <name> --steps 60` to try it, then a full run. | ||
compat/results.json+5146−1
A large diff, not shown.
compat/RESULTS.md+466−23
489 lines changed: not loaded until asked for.
harness/checks/accounts.mjs+35−0
| @@ -152,6 +152,41 @@ export async function createFirstAccounts() { | ||
for (let i = 2 + below(2); i > 0; i--) await createAccount({ withPassword: true }) | ||
} | ||
| ||
/// The one account of a server that hosts one (spec/COMPAT.md, "One | ||
/// account"): the reference makes it with createAccount, the server through | ||
/// its adapter's `claim`, with the same handle and email and the password | ||
/// the server was started with. Their answers are not compared, nor is the | ||
/// server's genesis operation; the account's signing keys, and the server's | ||
/// rotation key, are read from the PLC directory. Then it is checked as a | ||
/// new account is, from getSession on. Answers the account, or null. | ||
export async function claimAccount() { | ||
const { handle, email } = newDetails(true) | ||
const body = { handle, email, password: cand.password } | ||
const [a, b] = await Promise.all([xrpc(ref, CREATE, { body }), cand.claim({ handle, email })]) | ||
count('createAccount (the server\'s one account)', a.status === 200 && b.status === 200) | ||
if (a.status !== 200) await differ(CREATE, body, 'an account', a.body, 'the reference refuses an account the harness means to make') | ||
if (b.status !== 200) await differ('the server\'s one account, made by its adapter', { handle, email }, 'an account', b.body, 'the adapter fails its own step') | ||
if (a.status !== 200 || b.status !== 200) return null | ||
const acct = made(body, a, b) | ||
for (const side of [ref, cand]) { | ||
const log = await plcLog(didOf(side, acct)) | ||
const op = Array.isArray(log.body) ? log.body[0] : null | ||
if (!op) { | ||
await fail(side, 'PLC log', shown({ body }), 'a genesis operation', log) | ||
continue | ||
} | ||
acct.sides[side.name].key = op.verificationMethods?.atproto | ||
if (side === cand) { | ||
acct.sides[side.name].kem = op.verificationMethods?.atproto_kem | ||
cand.rotationKey ??= op.rotationKeys?.[0] | ||
} | ||
} | ||
await both('getSession of a new account', 'com.atproto.server.getSession', { token: acct }) | ||
await syncHeads(acct) | ||
await checkRepo(acct) | ||
return acct | ||
} | ||
| ||
/// Emails a new account may have although an account has had them: those | ||
/// only accounts without a password had, which keep no email. | ||
const freeEmails = () => accounts.filter((a) => !a.password && !accounts.some((b) => b.password && b.email === a.email)).map((a) => a.email) | ||
harness/checks/identity.mjs+5−4
| @@ -126,7 +126,8 @@ async function change(acct, handle, kind, opts) { | ||
/// An operation the side did not post, as another holder of a rotation key | ||
/// might: the account's last one with an `https://` entry added to | ||
/// `alsoKnownAs`, signed with the side's rotation key. The next handle | ||
/// change must build on it and keep the entry. | ||
/// change must build on it and keep the entry. Not made where the harness | ||
/// has no rotation key of the server's to sign with (spec/COMPAT.md). | ||
async function outsideOperation(acct) { | ||
const entry = `https://${freshFront()}.example.com` | ||
const first = chance(0.5) | ||
| @@ -150,7 +151,7 @@ async function outsideOperation(acct) { | ||
/// account had before. Sometimes after an operation the server did not | ||
/// post. | ||
export async function updateHandle(acct) { | ||
if (chance(0.15) && acct.handles.server.length < 6) await outsideOperation(acct) | ||
if (chance(0.15) && acct.handles.server.length < 6 && !cand.adapter.unsupported.rotationKey) await outsideOperation(acct) | ||
const r = rand() | ||
if (r < 0.15) return change(acct, mixCase(acct.handle), 'updateHandle to its own handle') | ||
if (r < 0.3 && freed.length) return change(acct, pick(freed), 'updateHandle to a handle an account had') | ||
| @@ -159,7 +160,7 @@ export async function updateHandle(acct) { | ||
} | ||
| ||
/// Faults in updateHandle's handle, each refused alone: `[name, handle of | ||
/// a fresh front part]`. | ||
/// a fresh front part]`. A handle another account has needs one. | ||
const FAULTS = [ | ||
['handle missing', () => undefined], | ||
['handle not a string', () => pick([5, null, true, ['x.test']])], | ||
| @@ -181,7 +182,7 @@ const FAULTS = [ | ||
/// or one never given out, which come first. Each side must refuse it as | ||
/// the reference does, and post no operation. | ||
export async function updateHandleRefused(acct) { | ||
const [name, make] = pick(FAULTS) | ||
const [name, make] = pick(accounts.length > 1 ? FAULTS : FAULTS.filter(([n]) => n !== 'handle taken')) | ||
const handle = make(freshFront(), acct) | ||
const r = rand() | ||
const token = r < 0.15 ? undefined : r < 0.3 ? 'never-given-out' : acct | ||
harness/checks/oauth.mjs+3−1
| @@ -19,7 +19,9 @@ import { strip } from '../lib/xrpc.mjs' | ||
import { API, Browser, Dpop, answer, b64u, form, formPost, fresh, newKey, pkce, proof, sha256, signJwt, target, wwwError } from '../lib/oauth.mjs' | ||
| ||
export const sides = () => [ref, cand] | ||
export const issuer = (side) => new URL(side.publicUrl).origin | ||
/// The side's OAuth issuer: its public URL's origin, unless its adapter | ||
/// names another (lib/adapters.mjs). | ||
export const issuer = (side) => new URL(side.issuer ?? side.publicUrl).origin | ||
const URN = 'urn:ietf:params:oauth:request_uri:' | ||
const REDIRECT = 'http://127.0.0.1/callback' | ||
const DEFAULT_REDIRECTS = ['http://127.0.0.1/', 'http://[::1]/'] | ||
harness/lib/adapters.mjs+93−11
| @@ -10,15 +10,20 @@ | ||
// `{command, port, dataDir, logDir, plc, recoveryKey, | ||
// crawlers, appView, clientFetch, limits, invites, backfillMs, | ||
// cacheBytes, metricsPort, otlp}`. Answers `{server, url, | ||
// publicUrl, recoveryKey, rotationKey, plcSigner, admin, | ||
// takeMail}`: `server` the process the harness starts, kills | ||
// and starts again (`child`, or `container` here); the URL | ||
// the harness calls, and the one its DID documents and OAuth | ||
// issuer name; the rotation keys it lists in each DID it | ||
// makes, and its own as a signer; the `Authorization` its | ||
// admin is; and `takeMail()`, the emails it sent since the | ||
// last call, oldest first, as `{to, kind, token}` (or a | ||
// promise of them). | ||
// publicUrl, issuer, recoveryKey, rotationKey, plcSigner, | ||
// admin, takeMail}`: `server` the process the harness starts, | ||
// kills and starts again (`child`, or `container` here); the | ||
// URL the harness calls, the one its DID documents name, and | ||
// its OAuth issuer if that is not the same; the rotation keys | ||
// it lists in each DID it makes, and its own as a signer; the | ||
// `Authorization` its admin is; and `takeMail()`, the emails | ||
// it sent since the last call, oldest first, as `{to, kind, | ||
// token}` (or a promise of them). A server that hosts one | ||
// account (`unsupported.accounts`) answers too its | ||
// `password`, the one it was started with, and | ||
// `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"). | ||
// 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 | ||
| @@ -43,6 +48,7 @@ | ||
// (compat/README.md lists them). Only spec-pds is. | ||
| ||
import { spawn, spawnSync } from 'node:child_process' | ||
import { randomBytes } from 'node:crypto' | ||
import { mkdtempSync, openSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs' | ||
import { tmpdir } from 'node:os' | ||
import { join } from 'node:path' | ||
| @@ -50,7 +56,7 @@ import { Secp256k1Keypair } from '@atproto/crypto' | ||
import { ADMIN_PASSWORD, HANDLE_DOMAINS, serverEnv } from './env.mjs' | ||
import { Browser } from './oauth.mjs' | ||
import { noteSecret, now } from './observe.mjs' | ||
import { dockerPort, fromDocker, imageId, pins, root, sh, shOk, startRustfs, vlpdsArgs, vlpdsCreateArgs, vlpdsEnv, vlpdsOwnEnv, zdsCreateArgs, zdsEnv, zdsOwnEnv } from './impls.mjs' | ||
import { dockerPort, fromDocker, imageId, pdsjsCreateArgs, pdsjsEnv, pins, root, sh, shOk, startRustfs, vlpdsArgs, vlpdsCreateArgs, vlpdsEnv, vlpdsOwnEnv, zdsCreateArgs, zdsEnv, zdsOwnEnv } from './impls.mjs' | ||
| ||
/// The server's PDS_DEV_MAIL_DIR: empty, the harness's own. | ||
export const MAIL_DIR = mkdtempSync(join(tmpdir(), 'pds-mail-')) | ||
| @@ -414,5 +420,81 @@ const vlpds = { | ||
}, | ||
} | ||
| ||
const PDSJS = pins.implementations['pds.js'] | ||
const pdsjs = { | ||
about: `pds.js ${PDSJS.release} (${PDSJS.repo} at ${PDSJS.commit.slice(0, 7)}), its image built by \`node bench.mjs --setup\` with its own Dockerfile, in Docker`, | ||
pageApi: false, | ||
own: false, | ||
unsupported: { | ||
accounts: 'pds.js hosts one account (README.md, "one server, one identity"): createAccount only adopts a DID made elsewhere, for a migration (packages/core/src/handlers/xrpc-server.js:222-340), and a new one is made once, by POST /account/onboarding/create on an empty server (xrpc-server.js:453-615), which the adapter\'s claim calls', | ||
rotationKey: 'pds.js lists the account\'s signing key alone as its rotation key, held by the server (xrpc-server.js:540-551): the harness has no key to sign an operation of its own with', | ||
recoveryKey: 'the genesis operation\'s rotation keys are the account\'s signing key alone (xrpc-server.js:547): the reference\'s recovery key cannot be one', | ||
hostname: 'pds.js tells one relay of itself (RELAY_URL), at most every 20 minutes (packages/core/src/pds.js:149, 1934-1950), not each crawler it is given; and it names its endpoint https://<PDS_HOSTNAME> (xrpc-server.js:546), so the hostname cannot be the URL the harness calls', | ||
handleDomains: 'pds.js\'s one handle domain is its hostname (xrpc-server.js:127): describeServer\'s availableUserDomains is [".localhost"], and `.test` and `.example` cannot be given', | ||
clientFetch: 'pds.js fetches a client document from the client_id\'s own URL (packages/core/src/oauth.js:635-646); it has no mapping of origins to the harness\'s web, as PDS_OAUTH_CLIENT_FETCH is', | ||
narrowScope: 'pds.js\'s consent form approves or denies the scope asked (packages/core/src/handlers/oauth.js:884-956): a narrower one cannot be chosen', | ||
adminPassword: 'pds.js has no com.atproto.admin.* methods (docs/endpoint-comparison.md)', | ||
mail: 'its container has no mail transport (docker/server.js), so it sends none', | ||
limits: 'pds.js has no rate limits to turn on', | ||
restart: 'a container keeps the environment it was made with: no restart with another', | ||
}, | ||
port: dockerPort, | ||
readyMs: 120_000, | ||
async info() { | ||
return { version: PDSJS.release, source: `${PDSJS.repo} at ${PDSJS.commit}, image ${PDSJS.tag} (${await imageId(PDSJS.tag)}) built with its own ${PDSJS.dockerfile}`, config: 'PDS_HOSTNAME localhost; the rest its container\'s defaults (docs/configuration.md)' } | ||
}, | ||
async start(o) { | ||
const image = await imageId(PDSJS.tag) | ||
if (!image) throw new Error(`pds.js: no Docker image ${PDSJS.tag}; ${DOCKER_NEEDS}`) | ||
const name = `compat-pdsjs-${process.pid}-${Date.now()}` | ||
const password = `pdsjs-${randomBytes(12).toString('hex')}` | ||
// The harness's setup, as far as pds.js takes it (docs/configuration.md): | ||
// the reference's hostname, the harness's PLC directory and AppView. | ||
// Its one account is made by `claim`, not here. | ||
const env = { | ||
...pdsjsEnv({ hostname: 'localhost', plcUrl: o.plc, password }), | ||
...(o.appView ? { APPVIEW_URL: fromDocker(o.appView.url), APPVIEW_DID: o.appView.did } : {}), | ||
} | ||
await shOk('docker', pdsjsCreateArgs({ name, port: o.port, env, image })) | ||
const url = `http://127.0.0.1:${o.port}` | ||
const json = (r) => r.json().catch(() => null) | ||
return { | ||
server: container(name, env, join(o.logDir, 'server.log'), join(o.logDir, 'server.err'), () => spawnSync('docker', ['rm', '-f', '-v', name])), | ||
url, | ||
// Its DID documents name https://<PDS_HOSTNAME>; its OAuth issuer is | ||
// the URL it is called at. | ||
publicUrl: 'https://localhost', | ||
issuer: url, | ||
recoveryKey: null, | ||
// The account's own, read from its genesis operation once it is made. | ||
rotationKey: null, | ||
plcSigner: null, | ||
admin: null, | ||
takeMail: () => [], | ||
password, | ||
/// The account, made as its onboarding page makes it (a same-origin | ||
/// POST of the server's password, the handle and the email), then a | ||
/// session of it by createSession. | ||
async claim({ handle, email }) { | ||
const made = await fetch(`${url}/account/onboarding/create`, { method: 'POST', headers: { 'content-type': 'application/json', origin: url }, body: JSON.stringify({ password, handle, email }) }) | ||
const body = await json(made) | ||
if (made.status !== 200) return { status: made.status, body } | ||
const session = await fetch(`${url}/xrpc/com.atproto.server.createSession`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ identifier: body.did, password }) }) | ||
return { status: session.status, body: await json(session) } | ||
}, | ||
} | ||
}, | ||
/// Its consent page (packages/core/src/oauth.js, the form at | ||
/// /oauth/authorize): `request_uri`, `client_id`, the account's password, | ||
/// and `action=approve` or `deny`, which answers a 302 to the client. It | ||
/// asks no identifier: the server has one account. | ||
async signIn(account, authorizeUrl, consent) { | ||
const b = new Browser() | ||
return throughForms(b, authorizeUrl, [ | ||
(page) => ({ action: '/oauth/authorize', fields: { request_uri: hidden(page.text, 'request_uri'), client_id: hidden(page.text, 'client_id'), password: account.password, action: consent.approve ? 'approve' : 'deny' } }), | ||
]) | ||
}, | ||
} | ||
| ||
/// The adapters, by name. | ||
export const ADAPTERS = { 'spec-pds': specPds, zds, vlpds } | ||
export const ADAPTERS = { 'spec-pds': specPds, zds, vlpds, 'pds.js': pdsjs } | ||
harness/lib/areas.mjs+29−19
| @@ -21,7 +21,7 @@ import { below, chance, pick } from './random.mjs' | ||
import { adapter, shutdown } from './processes.mjs' | ||
import { allowed, counts, found, run } from './report.mjs' | ||
import { accounts } from './state.mjs' | ||
import { accountRace, createAccount, createAccountRefused, createSession, crossWrites } from '../checks/accounts.mjs' | ||
import { accountRace, claimAccount, createAccount, createAccountRefused, createSession, crossWrites } from '../checks/accounts.mjs' | ||
import { blobRecord, getBlob, listBlobs, uploadBlob } from '../checks/blobs.mjs' | ||
import { checkCrawls, getBlocks, getGoneBlocks, getRepoStatus, listRepos, noCrawlsYet, syncGetRecord } from '../checks/federation.mjs' | ||
import { checkFirehose, checkReplay, startFirehose } from '../checks/firehose.mjs' | ||
| @@ -48,10 +48,12 @@ const crawlsSoFar = Object.defineProperty(() => checkCrawls(0), 'name', { value: | ||
/// The areas, in the order the report lists them. Each has `about`, what it | ||
/// checks; `steps`, `[check, weight, needs]`, drawn as compare.mjs draws | ||
/// its steps, `needs` the settings (lib/adapters.mjs, `unsupported`) a | ||
/// check depends on; `support`, `[step, weight]` drawn among them, whose | ||
/// differences are kept apart; `pre`, checks of the area before the steps | ||
/// (and after the first accounts unless `beforeAccounts`); and `every`, | ||
/// checks of the area every `--check-every` steps and at the end. | ||
/// check depends on; `support`, `[step, weight, needs]` drawn among them, | ||
/// whose differences are kept apart; `pre`, checks of the area before the | ||
/// steps (and after the first accounts unless `beforeAccounts`); and | ||
/// `every`, checks of the area every `--check-every` steps and at the end. | ||
/// `accounts` is the need of a check that makes an account or needs a | ||
/// second one (spec/COMPAT.md, "One account"). | ||
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', | ||
| @@ -72,11 +74,11 @@ export const AREAS = { | ||
}, | ||
accounts: { | ||
about: 'Accounts: createAccount, the DID it registers with the PLC directory and its genesis operation, and what it refuses', | ||
steps: [[newAccount, 4], [createAccountRefused, 4], [accountRace, 1]], | ||
steps: [[newAccount, 4, ['accounts']], [createAccountRefused, 4, ['accounts']], [accountRace, 1, ['accounts']]], | ||
}, | ||
records: { | ||
about: 'Records: createRecord, putRecord, deleteRecord, applyWrites, swapCommit and swapRecord, getRecord, listRecords, describeRepo, writes to another account\'s repository, and requests the lexicons refuse', | ||
steps: [[createRecord, 14], [putRecord, 14], [deleteRecord, 8], [applyWrites, 8], [getRecord, 10], [listRecords, 6], [describeRepo, 2], [createWithTid, 2], [concurrent, 6], [oddRequests, 3], [crossWrites, 3]], | ||
steps: [[createRecord, 14], [putRecord, 14], [deleteRecord, 8], [applyWrites, 8], [getRecord, 10], [listRecords, 6], [describeRepo, 2], [createWithTid, 2], [concurrent, 6], [oddRequests, 3], [crossWrites, 3, ['accounts']]], | ||
}, | ||
validation: { | ||
about: 'Records checked against their lexicons: known types valid and not, `validate`, duplicates replaced, in applyWrites too', | ||
| @@ -97,12 +99,12 @@ export const AREAS = { | ||
}, | ||
firehose: { | ||
about: 'The firehose: each side\'s subscribeRepos from the start, every event checked as a consumer would, in order, with its blocks, and replays from a cursor', | ||
support: [...WRITES, [newAccount, 1], [updateHandle, 2]], | ||
support: [...WRITES, [newAccount, 1, ['accounts']], [updateHandle, 2]], | ||
every: [[firehoseChecks]], | ||
}, | ||
identity: { | ||
about: 'Identity: handles, their changes and the PLC operations they make, resolveHandle, /.well-known/atproto-did, getRecommendedDidCredentials, and DID documents', | ||
steps: [[updateHandle, 3], [updateHandleRefused, 3], [updateHandleNoToken, 1], [resolveHandle, 3], [wellKnownHandle, 2], [recommendedCredentials, 1], [describeRepo, 2], [handleRace, 1]], | ||
steps: [[updateHandle, 3], [updateHandleRefused, 3], [updateHandleNoToken, 1], [resolveHandle, 3], [wellKnownHandle, 2], [recommendedCredentials, 1, ['recoveryKey']], [describeRepo, 2], [handleRace, 1, ['accounts']]], | ||
}, | ||
blobs: { | ||
about: 'Blobs: uploadBlob, records that reference them, getBlob, listBlobs', | ||
| @@ -177,23 +179,31 @@ export async function areaRun() { | ||
console.error(`no area ${AREA}; there are ${Object.keys(AREAS).join(', ')}`) | ||
await shutdown(2) | ||
} | ||
const steps = [] | ||
for (const [fn, w, needs] of area.steps ?? []) { | ||
const why = missing(needs) | ||
if (why.length) skipped[fn.name] = why | ||
else steps.push([fn, w, true]) | ||
const drawn = [] | ||
const drawable = (list, mine) => { | ||
for (const [fn, w, needs] of list ?? []) { | ||
const why = missing(needs) | ||
if (why.length) skipped[fn.name] = why | ||
else drawn.push([fn, w, mine]) | ||
} | ||
} | ||
drawable(area.steps, true) | ||
drawable(area.support, false) | ||
if (FIREHOSE) await check(startFirehose, [], true) | ||
await runAll(area.pre, true, true) | ||
// The first accounts, as compare.mjs makes them, each a supporting step; | ||
// as many more as it takes (up to ten tries), when the server refuses | ||
// one the reference makes, which is then not kept. | ||
const first = Object.defineProperty(() => createAccount({ withPassword: true }), '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) | ||
// one the reference makes, which is then not kept. A server that hosts | ||
// one account has that one, made once, through its adapter. | ||
if (adapter.unsupported.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 want = 2 + below(2) | ||
for (let tries = 0; accounts.length < want && tries < 10; tries++) await check(first, [], false) | ||
} | ||
for (const acct of accounts) await check(describeRepo, [acct], false) | ||
await runAll(area.pre, true, false) | ||
const drawn = [...steps, ...(area.support ?? []).map(([fn, w]) => [fn, w, false])] | ||
const total = drawn.reduce((n, [, w]) => n + w, 0) | ||
for (run.step = 1; run.step <= STEPS; run.step++) { | ||
if (drawn.length && accounts.length) { | ||
harness/lib/impls.mjs+23−0
| @@ -184,3 +184,26 @@ export const zdsCreateArgs = ({ name, port, env, image = pins.implementations.zd | ||
'create', '--name', name, '-p', `127.0.0.1:${port}:2583`, '--add-host', 'host.docker.internal:host-gateway', '-v', '/data', | ||
...Object.entries(env).flatMap(([k, v]) => ['-e', `${k}=${v}`]), image, | ||
] | ||
| ||
// ---- pds.js -------------------------------------------------------------- | ||
| ||
// pds.js as its container runs it (docs/deploy-docker.md, its Dockerfile): | ||
// SQLite and blobs on the /data volume, listening on 3000; its optional | ||
// features as they default (spaces off), and no relay told of it. | ||
| ||
/// pds.js's environment: its hostname `hostname`, registering its account's | ||
/// DID with the directory at `plcUrl` (on this machine), a fresh JWT secret, | ||
/// and `password`, its one account's, which it requires. | ||
export const pdsjsEnv = ({ hostname, plcUrl, password }) => ({ | ||
PDS_HOSTNAME: hostname, | ||
PLC_URL: fromDocker(plcUrl), | ||
JWT_SECRET: randomBytes(32).toString('hex'), | ||
PDS_PASSWORD: password, | ||
}) | ||
| ||
/// `docker create`'s arguments for pds.js as `name`, its port 3000 on | ||
/// loopback's `port`, with `env`, from `image` (by default its pinned tag). | ||
export const pdsjsCreateArgs = ({ name, port, env, image = pins.implementations['pds.js'].tag }) => [ | ||
'create', '--name', name, '-p', `127.0.0.1:${port}:3000`, '--add-host', 'host.docker.internal:host-gateway', '-v', '/data', | ||
...Object.entries(env).flatMap(([k, v]) => ['-e', `${k}=${v}`]), image, | ||
] | ||
harness/lib/processes.mjs+3−2
| @@ -24,7 +24,8 @@ import { startReceiver } from './otlp.mjs' | ||
/// its DID documents name, the `did:key`s of the rotation keys it lists in | ||
/// each DID it creates, and its rotation key, to sign operations as it | ||
/// does. The server's side also has its `adapter`, its `admin` | ||
/// authorization, `takeMail()` and, without the page API, `signIn` | ||
/// authorization, `takeMail()`, without the page API `signIn`, and on a | ||
/// server that hosts one account, its `password` and `claim` | ||
/// (lib/adapters.mjs). Set by `start`, with the server's data directory, | ||
/// and with `--limits` or `--lifecycle` the proxy its requests to the | ||
/// directory go through; the OTLP receiver the server exports its spans to, | ||
| @@ -72,7 +73,7 @@ export async function start() { | ||
const made = await adapter.start({ command, port, dataDir, logDir, plc: plcProxy?.url ?? plcUrl, recoveryKey, crawlers: crawlers.server, appView, clientFetch, limits: LIMITS, invites: INVITES, backfillMs: BACKFILL_MS, cacheBytes: CACHE_BYTES, metricsPort, otlp }) | ||
server = made.server | ||
ref = { name: 'reference', url: net.pds.url, publicUrl: net.pds.ctx.cfg.service.publicUrl, recoveryKey, rotationKey: net.pds.ctx.plcRotationKey.did(), plcSigner: net.pds.ctx.plcRotationKey } | ||
cand = { name: 'server', url: made.url, publicUrl: made.publicUrl, recoveryKey: made.recoveryKey, rotationKey: made.rotationKey, plcSigner: made.plcSigner, adapter, admin: made.admin, takeMail: made.takeMail, signIn: adapter.signIn?.bind(adapter) } | ||
cand = { name: 'server', url: made.url, publicUrl: made.publicUrl, issuer: made.issuer, recoveryKey: made.recoveryKey, rotationKey: made.rotationKey, plcSigner: made.plcSigner, adapter, admin: made.admin, takeMail: made.takeMail, signIn: adapter.signIn?.bind(adapter), password: made.password, claim: made.claim } | ||
watch(cand.url, () => server.lives.length - 1) | ||
server.start() | ||
await waitReady(server, cand.url) | ||