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

harness: migrate-blobs killed once finished; issuers' keys' spec gaps closed

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:harness/migrate-kill-race
harness/checks/limits.mjs+28−5
@@ -1340,8 +1340,9 @@ async function plcConnections() {
/// An issuer that is an account here: authorizeSpaceSync with a delegation
/// token the server signed for one of its accounts, of a space another of
/// its accounts made, public: taken, with nothing read of the user's
/// document from the directory (spec/SPACES-CREDENTIALS.md, "Issuers'
/// keys").
/// document from the directory; and one signed before its account was
/// deleted, with the document read, a deleted account's DID being any
/// other issuer's (spec/SPACES-CREDENTIALS.md, "Issuers' keys").
async function plcLocalIssuer() {
const ip = freshIp()
const [authority, user] = [await serverAccount(ip), await serverAccount(ip)]
@@ -1352,15 +1353,37 @@ async function plcLocalIssuer() {
const request = { delegationToken: 'by an account here, of a space another account here made', space: 'public' }
const { P256Keypair } = await import('@atproto/crypto')
const credentialKey = (await P256Keypair.create()).did()
const trade = (token) => send(cand, 'com.atproto.space.authorizeSpaceSync', { body: { space, credentialKey, delegationToken: token }, ip })
const tokenOf = async (access) => {
const t = await send(cand, 'com.atproto.space.getDelegationToken', { params: { space }, token: access, ip })
if (t.status !== 200) await broke('com.atproto.space.getDelegationToken', {}, 200, t)
return t.body?.token
}
for (let i = 0; i < 3; i++) {
const before = plcProxy.countOf(`/${user.did}`)
const token = await send(cand, 'com.atproto.space.getDelegationToken', { params: { space }, token: user.access, ip })
if (token.status !== 200) await broke('com.atproto.space.getDelegationToken', {}, 200, token)
const traded = await send(cand, 'com.atproto.space.authorizeSpaceSync', { body: { space, credentialKey, delegationToken: token.body?.token }, ip })
const traded = await trade(await tokenOf(user.access))
const read = plcProxy.countOf(`/${user.did}`) - before
if (traded.status !== 200 || read) await broke('com.atproto.space.authorizeSpaceSync', request, '200, with nothing read of the user\'s document', { status: traded.status, error: traded.body?.error, reads: read })
}
count('an issuer that is an account here, nothing read', true)
// A deleted account (spec/LIFECYCLE.md, "deleteAccount").
const front = freshFront()
const password = `pw-${front}`
const gone = await send(cand, CREATE_ACCOUNT, { body: { handle: `${front}.test`, email: `${front}@example.com`, password }, ip })
if (gone.status !== 200) await broke(CREATE_ACCOUNT, { password: true }, 200, gone)
const signed = await tokenOf(gone.body?.accessJwt)
takeMail(cand)
const asked = await send(cand, 'com.atproto.server.requestAccountDelete', { token: gone.body?.accessJwt, method: 'POST', ip })
const mailed = takeMail(cand).filter((m) => m.kind === 'deleteAccount').at(-1)?.token
if (asked.status !== 200 || !mailed) await broke('com.atproto.server.requestAccountDelete', {}, '200, a deleteAccount token mailed', { status: asked.status, mailed: Boolean(mailed) })
const deleted = await send(cand, 'com.atproto.server.deleteAccount', { body: { did: gone.body.did, password, token: mailed }, ip })
if (deleted.status !== 200) await broke('com.atproto.server.deleteAccount', {}, 200, deleted)
const before = plcProxy.countOf(`/${gone.body.did}`)
await trade(signed)
const read = plcProxy.countOf(`/${gone.body.did}`) - before
if (!read) await broke('com.atproto.space.authorizeSpaceSync', { delegationToken: 'signed by the server before its account was deleted' }, 'the deleted account\'s document read', 'nothing read')
count('an issuer whose account here was deleted, its document read', false)
}
/// How long until a connection the server is sent `bytes` on, and then
harness/checks/migrate.mjs+50−13
@@ -46,13 +46,20 @@ function serveEnv(where) {
/// `pds <args>` with `env`, killed after `killAfter` ms if given, counted
/// from when `armed()` first holds (polled every few ms; at once without
/// it): its exit, standard output and standard error.
function pds(args, env, killAfter, armed = () => true) {
/// it); and with `stopOnStart`, shut down (SIGTERM) 5 s after it logs its
/// `start` line, once what a start after a kill finds is durable
/// (spec/STORE.md, "Scale"), so that its data directory is left as a
/// shutdown leaves it: its exit, standard output and standard error.
function pds(args, env, killAfter, armed = () => true, { stopOnStart = false } = {}) {
return new Promise((ok) => {
const p = spawn(command[0], args, { env, stdio: ['ignore', 'pipe', 'pipe'] })
const out = []
const err = []
p.stdout.on('data', (d) => out.push(d))
let stopping = null
p.stdout.on('data', (d) => {
out.push(d)
if (stopOnStart && !stopping && /"msg":"start"/.test(Buffer.concat(out).toString('utf8'))) stopping = setTimeout(() => p.kill('SIGTERM'), 5000)
})
p.stderr.on('data', (d) => err.push(d))
let timer = null
const poll = killAfter === undefined ? null : setInterval(() => {
@@ -63,6 +70,7 @@ function pds(args, env, killAfter, armed = () => true) {
p.on('exit', (code, signal) => {
clearInterval(poll)
clearTimeout(timer)
clearTimeout(stopping)
ok({ code, signal, stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8') })
})
})
@@ -79,25 +87,37 @@ function held() {
}
/// A `pds serve` on the data directory, apart from the run's server: it
/// must exit 1, with why on standard error, before it serves.
async function serveRefused(where, why, spec = SPEC) {
/// must exit 1, with why on standard error, before it serves. With
/// `servesIf`, a serve that starts, shut down at once, is allowed where
/// `servesIf()` then holds, and answers false.
async function serveRefused(where, why, spec = SPEC, servesIf) {
const port = await freePort()
const env = { ...serveEnv(where), PDS_PORT: String(port), PDS_METRICS_PORT: '' }
const r = await pds(['serve'], env, 20_000)
// Its log apart from the run's server's, which `_logs` is held to: one
// that serves writes lines there.
const env = { ...serveEnv(where), PDS_PORT: String(port), PDS_METRICS_PORT: '', PDS_LOG_DIR: '' }
const r = await pds(['serve'], env, 20_000, undefined, { stopOnStart: true })
serveEnv(where)
if (r.code !== 1 || !r.stderr.trim() || r.stdout.trim()) await differ(`pds serve ${why}`, { blobs: where }, 'exit 1, with why on standard error and nothing on standard output', { code: r.code, signal: r.signal, stdout: r.stdout.slice(0, 300), stderr: r.stderr.slice(0, 300) }, spec)
const refused = r.code === 1 && r.stderr.trim() && !r.stdout.trim()
const started = /"msg":"start"/.test(r.stdout) && r.code === 0
if (!refused && started && servesIf && (await servesIf())) return false
if (!refused) await differ(`pds serve ${why}`, { blobs: where }, 'exit 1, with why on standard error and nothing on standard output', { code: r.code, signal: r.signal, stdout: r.stdout.slice(0, 300), stderr: r.stderr.slice(0, 300) }, spec)
count(`pds serve ${why}, refused`, false)
return true
}
/// `pds migrate-blobs --to <to>`, killed now and then, run again until it
/// finishes. The store answers each request 100 ms late, and a kill lands
/// at a random moment within 600 ms of its first request of the run: after
/// the move has marked the data directory (spec/BLOBS.md, "Moving them", 4
/// before 5), while it copies, switches or cleans up. With `back`, the
/// first time it is killed the move is turned back: moved where the blobs
/// were, served from there, then moved on.
/// before 5), while it copies, switches or cleans up; or, rarely, after it
/// marked the move finished and before it exited (7). Such a kill leaves
/// the move finished: the data directory is served from where the blobs
/// went, and the next run moves nothing. With `back`, the first time it is
/// killed the move is turned back: moved where the blobs were, served from
/// there, then moved on.
async function moveTo(to, { kills = 3, back } = {}) {
let killed = 0
let lastKilled = false
for (let attempt = 0; ; attempt++) {
if (attempt > 40) throw new Error(`pds migrate-blobs --to ${to} did not finish in 40 runs`)
const kill = killed < kills && chance(0.8) ? below(600) : undefined
@@ -107,12 +127,19 @@ async function moveTo(to, { kills = 3, back } = {}) {
s3.clearFailures()
if (r.signal === 'SIGKILL') {
killed += 1
// Unfinished, the data directory is not served, whichever way.
if (killed === 1) await serveRefused(pick(['bucket', 'disk']), 'on a data directory whose blobs are moving')
lastKilled = true
// Unfinished, the data directory is not served, whichever way; but a
// kill after the move was marked finished leaves it finished.
const where = killed === 1 ? pick(['bucket', 'disk']) : null
const finished = async () => where === to && (await nothingMoved(to))
if (where && !(await serveRefused(where, 'on a data directory whose blobs are moving', SPEC, finished))) {
return count(`pds migrate-blobs --to ${to}, killed once it had finished`, true)
}
if (back && killed === 1) {
await moveTo(back, { kills: 1 })
await serves(back, `moved back to ${back} after a move to ${to} was killed`)
await server.stop('SIGTERM', 15_000)
lastKilled = false
}
continue
}
@@ -123,11 +150,21 @@ async function moveTo(to, { kills = 3, back } = {}) {
} catch {
await differ(`pds migrate-blobs --to ${to}`, { attempt: attempt + 1 }, 'one line of JSON on standard output', r.stdout.slice(0, 300), SPEC)
}
// The run killed before this one had finished, between marking the move
// finished and exiting: this one finds nothing to move.
if (lastKilled && isDeepStrictEqual(line, { moved: 0, bytes: 0 })) return count(`pds migrate-blobs --to ${to}, killed once it had finished`, true)
if (!isDeepStrictEqual(line, held())) await differ(`pds migrate-blobs --to ${to}`, { attempt: attempt + 1, killed }, held(), line, SPEC)
return count(`pds migrate-blobs --to ${to}, killed ${killed} times first`, true)
}
}
/// Whether `pds migrate-blobs --to <where>` moves nothing: the data
/// directory keeps its blobs there, with no move unfinished.
async function nothingMoved(where) {
const r = await pds(['migrate-blobs', '--to', where], migrateEnv(), 60_000)
return r.code === 0 && r.stdout.trim() === '{"moved":0,"bytes":0}'
}
/// `pds migrate-blobs --to <where>` on a data directory that keeps its
/// blobs there already: nothing moved.
async function nothingToMove(where) {
harness/spaces/compare.mjs+6−5
@@ -115,11 +115,12 @@ async function killServer(signal = 'SIGKILL') {
dying.kill(signal)
await gone
}
/// Killed, or with `gently` shut down (SIGTERM), and started again on its
/// data with `e`, as a variant of the run needs (ssrf.mjs: SSRF protection
/// on, then off again; issuers.mjs: issuers' keys across a shutdown).
async function restartWith(e, { gently = false } = {}) {
await killServer(gently ? 'SIGTERM' : 'SIGKILL')
/// Killed, or shut down with `signal` (SIGTERM or SIGINT), and started
/// again on its data with `e`, as a variant of the run needs (ssrf.mjs:
/// SSRF protection on, then off again; issuers.mjs: issuers' keys across a
/// shutdown).
async function restartWith(e, { signal = 'SIGKILL' } = {}) {
await killServer(signal)
startServer(e)
await waitReady(cand.url)
}
harness/spaces/issuers.mjs+14−5
@@ -15,8 +15,10 @@
// them, which must read nothing, and one from the first, which must
// read its document again: the key used longest ago is forgotten, and
// only it;
// 3. shut down (SIGTERM) and started again, a revocation from the second
// of those issuers reads nothing: its key outlived the restart.
// 3. shut down by SIGTERM and started again, a revocation from the second
// of those issuers reads nothing; one from the third, forgotten in 2,
// reads its document; then shut down by SIGINT and started again, one
// from the third reads nothing: the keys outlived each shutdown.
//
// With PDS_DID_CACHE_SECS=3 and PDS_DID_CACHE_MAX_SECS=8:
// 4. from a new issuer, a revocation 3.5 s after its document was read,
@@ -105,10 +107,17 @@ export async function checkIssuerKeys(h) {
await taken('one key past the bound: the key used longest ago', many[0], 1, { PDS_CACHE_BYTES: KEPT * 1024, issuers: KEPT + 2, 'the first of the last': 'used again' })
count('issuers\' keys: the one used longest ago forgotten')
// 3. Kept across a shutdown.
await restartWith(bounded, { gently: true })
// 3. Kept across a shutdown, by SIGTERM and by SIGINT (spec/OPERATIONS.md,
// "shutdown"): many[1], kept before the first; then many[2], forgotten
// above and read again after the first start, so that only the SIGINT
// shutdown can have written it.
await restartWith(bounded, { signal: 'SIGTERM' })
await sleep(1000)
await taken('after a shutdown and a start, a key kept before', many[1], 0, { restart: 'SIGTERM, then 1 s' })
await taken('after a shutdown (SIGTERM) and a start, a key kept before', many[1], 0, { restart: 'SIGTERM, then 1 s' })
await taken('a key forgotten before the shutdown', many[2], 1, { restart: 'SIGTERM, then 1 s' })
await restartWith(bounded, { signal: 'SIGINT' })
await sleep(1000)
await taken('after a shutdown (SIGINT) and a start, a key read since the start before', many[2], 0, { restart: 'SIGINT, then 1 s' })
count('issuers\' keys: kept across a shutdown')
for (const w of [first, ...many]) w.close()
spec/BLOBS.md+7−1
@@ -511,7 +511,13 @@ throughout. Blob steps of the run (uploads, records with blob refs,
time it is killed, `pds serve` must refuse the data directory, and the
move is turned back: `--to disk`, killed too, to its end, the server
started on disk and every blob read as the reference's, and the bucket
holding no object of the accounts' blobs; then `--to bucket` again.
holding no object of the accounts' blobs; then `--to bucket` again. A
kill, of either move, that came after the move was marked finished and
before the command exited (7, above) leaves it finished: the next run
may print `{"moved":0,"bytes":0}`; and the first time, `pds serve` with
the environment of the place it moved them to may serve, `--to` that
place then printing `{"moved":0,"bytes":0}`. Either way the move is
taken as done.
Each finished run must print the count and bytes of the blobs the
harness knows the accounts hold, and `--to bucket` then
`{"moved":0,"bytes":0}`.
spec/LIMITS.md+3−1
@@ -659,7 +659,9 @@ and then to this page alone:
than there are reads; and three `authorizeSpaceSync`s, each with a
delegation token from `getDelegationToken` of an account here, of a
public space another account here made: each `200`, with nothing read
of the user's document (`SPACES-CREDENTIALS.md`, "Issuers' keys");
of the user's document; and one with a token `getDelegationToken` gave
an account deleted since (`LIFECYCLE.md`), its document read
(`SPACES-CREDENTIALS.md`, "Issuers' keys");
- a connection that sends half a request head, closed within 15 s, and a
request whose body stops, closed within 40 s;
- 300 accounts made, each given three records of 140000 bytes, past what
spec/SPACES-CREDENTIALS.md+18−11
@@ -294,11 +294,14 @@ serves; for a `did:web`, its host's `/.well-known/did.json` (below). Its key is
and must be low-S: a high-S signature, which `atproto/cryptography.md`
calls malleable, does not verify.
An issuer that is an account here has its token verified first against
An issuer that is an account here, active, deactivated or taken down
(`LIFECYCLE.md`) but not deleted, has its token verified first against
the key the server holds for the account, with nothing read; a token that
does not verify against it is verified as any other issuer's is, below. So
the server reads no document for the tokens it signs itself, its accounts'
delegation tokens, credentials and service auth, however many there are.
does not verify against it is verified as any other issuer's is, below.
So the server reads no document for the tokens it signs itself, its
accounts' delegation tokens, credentials and service auth, however many
there are. A deleted account's DID is any other issuer's: its document is
read.
For any other issuer the server keeps the key it read, with when the read
began:
@@ -322,11 +325,13 @@ began:
(`STORE.md`): 262144 by default. Past that, the key used longest ago is
forgotten.
- The keys kept are written to `PDS_DATA_DIR/issuer-keys` at a shutdown
(`SIGTERM`) and at most once a minute while they change, never synced:
a cache, not state. A start reads it back in the background, dropping
any key read `PDS_DID_CACHE_MAX_SECS` ago or longer; until it has, a
token is verified as if no key were kept. A file that is missing, cannot
be read, or is not as the server writes it, is as none.
(`SIGTERM` or `SIGINT`, `OPERATIONS.md`) and at most once a minute while
they change, never synced: a cache, not state. A start reads it back in
the background, dropping any key read `PDS_DID_CACHE_MAX_SECS` ago or
longer; until it has, a token is verified as if no key were kept, and a
key read since the start is kept over the file's for the same issuer,
and counts as used later than any of the file's. A file that is
missing, cannot be read, or is not as the server writes it, is as none.
With `PDS_DID_CACHE_SECS=0` no key is kept, and every token's issuer's
document is read for it, but for the issuers that are accounts here.
@@ -577,8 +582,10 @@ this page. In this order:
from an issuer not read before, its document 400 ms slow, are each taken
with one read of it; then 65 more issuers, one revocation each, after
which one from the second of them reads nothing and one from the first
reads its document again; then shut down (`SIGTERM`) and started again,
a second later one from that second issuer reads nothing. Started again
reads its document again; then shut down by `SIGTERM` and started again,
a second later one from that second issuer reads nothing and one from
the third, forgotten before, reads its document; then shut down by
`SIGINT` and started again, one from the third reads nothing. Started again
with `PDS_DID_CACHE_SECS=3` and `PDS_DID_CACHE_MAX_SECS=8`: from a new
issuer, one 3.5 s after its document was read, the document now 1.5 s
slow, is answered within 1 s, and the document is read once more after