chadtmiller.com/monolith
An atproto PDS
0
0
// vlpds, in Docker, from its pinned release image, on a fresh RustFS
// (bench/impls.json), configured as lib/impls.mjs configures it, plus what
// a compatibility run needs.
import { spawnSync } from 'node:child_process'
import { join } from 'node:path'
import { Browser } from '../oauth.mjs'
import { dockerPort, fromDocker, imageId, pins, shOk, startRustfs, vlpdsArgs, vlpdsCreateArgs, vlpdsEnv, vlpdsOwnEnv } from '../impls.mjs'
import { DOCKER_NEEDS, basic, container, hidden, signer, throughForms } from './common.mjs'
export default {
about: `vlpds ${pins.implementations.vlpds.release} (commit ${pins.implementations.vlpds.commit.slice(0, 7)}), its release image, on RustFS, in Docker`,
pageApi: false,
own: false,
unsupported: {
clientFetch: 'vlpds fetches a client document from the client_id\'s own URL, https unless --dev-mode (src/oauth/client.rs:423-426); it has no mapping of origins to the harness\'s web, as PDS_OAUTH_CLIENT_FETCH is',
hostname: 'vlpds takes its hostname from VLPDS_PUBLIC_URL, which must be the URL the harness calls (DPoP\'s htu and the issuer), and asks no relay on another host to crawl when its own is local (src/crawlers.rs:366-369): it cannot be localhost, telling the harness\'s crawlers',
handleDomains: 'vlpds serves one handle domain (VLPDS_HANDLE_DOMAIN, here `test`); more are added only by its admin API, each of two labels or more, so `.example` cannot be one: describeServer\'s availableUserDomains is [".test"]',
adminPassword: 'vlpds\'s admin token must be 32 bytes or more outside --dev-mode (src/server.rs:208-237): a fresh one, not the reference\'s `admin-pass`',
mail: 'vlpds keeps the mail it sends readable (vlpds.admin.getDevMail) only with --dev-mode, which also changes how it fetches clients and resolves handles; it runs without it, as the benchmark runs it',
narrowScope: 'vlpds\'s consent form only takes scopes away from the request (src/xrpc/oauth.rs:1915-1943), where the reference\'s page API takes any scope',
restart: 'a container keeps the environment it was made with: no restart with another',
lexiconAuthority: 'the harness knows no setting of vlpds naming one DID every NSID\'s lexicon is resolved from, as PDS_LEXICON_AUTHORITY_DID does: it would look the harness\'s permission sets up in DNS, which the harness does not serve',
},
port: dockerPort,
readyMs: 120_000,
async info() {
const pin = pins.implementations.vlpds
return { version: pin.release, source: `release image ${pin.image} (commit ${pin.commit}); S3 store ${pins.images[pin.needs[0]].image} (${pins.images[pin.needs[0]].release})`, config: '' }
},
async start(o) {
const pin = pins.implementations.vlpds
for (const image of [pin.image, pins.images[pin.needs[0]].image]) if (!(await imageId(image))) throw new Error(`vlpds: no Docker image ${image}; ${DOCKER_NEEDS}`)
const id = `compat-vlpds-${process.pid}-${Date.now()}`
const store = `${id}-s3`
const pds = `${id}-pds`
const teardown = () => {
spawnSync('docker', ['rm', '-f', '-v', pds])
spawnSync('docker', ['rm', '-f', '-v', store])
spawnSync('docker', ['network', 'rm', id])
}
const { rotation, hex } = await signer()
let env
try {
await shOk('docker', ['network', 'create', id])
const s3 = await startRustfs(id, store)
// The harness's setup, as far as vlpds takes it: the reference's
// server DID, the handle domain `.test`, recovery key and invites;
// the harness's AppView; rate limits on or off. No crawlers (see
// `unsupported`).
env = {
...vlpdsEnv,
...vlpdsOwnEnv({ port: o.port, plcUrl: o.plc, rotationHex: hex, store: s3 }),
VLPDS_SERVICE_DID: 'did:web:localhost',
VLPDS_HANDLE_DOMAIN: 'test',
VLPDS_PLC_RECOVERY_DID_KEY: o.recoveryKey,
VLPDS_INVITE_REQUIRED: String(o.invites),
VLPDS_NO_RATE_LIMITS: String(!o.limits),
...(o.appView ? { VLPDS_APPVIEW: `${fromDocker(o.appView.url)},${o.appView.did}` } : {}),
}
await shOk('docker', vlpdsCreateArgs({ name: pds, network: id, port: o.port, env, args: vlpdsArgs }))
} 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: url,
recoveryKey: o.recoveryKey,
rotationKey: rotation.did(),
plcSigner: rotation,
admin: basic('admin', env.VLPDS_ADMIN_TOKEN),
takeMail: () => [],
}
},
/// vlpds's server-rendered forms (src/xrpc/oauth.rs, src/oauth/ui.rs):
/// the page sets a device cookie and carries a `csrf` field; sign-in
/// posts `identifier`, `password` and `action=sign-in`, which answers
/// the consent page with the account's `did`; consent posts `did` and
/// `action=allow` (or `deny`), which answers a 303 to the client, or a
/// `form_post` page. A page that asks to choose an account is answered
/// "another account".
async signIn(account, authorizeUrl, consent) {
const b = new Browser()
const base = (page) => ({ request_uri: hidden(page.text, 'request_uri'), csrf: hidden(page.text, 'csrf') })
const step = (page) => {
if (hidden(page.text, 'did') !== null && /\/oauth\/authorize\/consent/.test(page.text)) return { action: '/oauth/authorize/consent', fields: { ...base(page), did: hidden(page.text, 'did'), action: consent.approve ? 'allow' : 'deny' } }
if (/name="password"/.test(page.text)) return { action: '/oauth/authorize/sign-in', fields: { ...base(page), identifier: account.identifier, password: account.password, action: 'sign-in' } }
if (/\/oauth\/authorize\/select/.test(page.text)) return { action: '/oauth/authorize/select', fields: { ...base(page), did: '' } }
return null
}
return throughForms(b, authorizeUrl, [step, step, step, step])
},
}