Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/private-channel-owner-required.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/board': patch
---

`createChannel(path, { private: true })` (and `channels create --private`) takes its creator's grant back when the board refuses the lock that closes the channel, such as Vercel's board answering a member who isn't a team owner with 403 `owner_required`, so nothing is left half made. That error now says a team owner makes it, and `--private`'s help says so up front.
2 changes: 1 addition & 1 deletion packages/board/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const options = {
'remove-app': { type: 'string', multiple: true, value: 'app', description: 'remove an app' },
'remove-all-apps': { type: 'boolean', description: 'remove every app on the team' },
'remove-everyone': { type: 'boolean', description: 'remove everyone' },
private: { type: 'boolean', description: 'closed to everyone but you, in the same write' },
private: { type: 'boolean', description: "closed to everyone but you, in the same write (on Vercel's board, a team owner's to make)" },
schema: { type: 'string', value: 'schema', description: 'the text is JSON for this schema, such as sandbox@1' },
description: { type: 'string', value: 'text', description: 'what it holds, in a sentence' },
port: { type: 'string', value: 'N', description: 'the port to listen on' },
Expand Down
14 changes: 13 additions & 1 deletion packages/board/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,19 @@ export function createBoardClient(options: ClientOptions) {
await takeBack(own.grant.id)
throw granted(raced, [own.grant])
}
const closed = await call<{ grant: GrantView }>('POST', '/grants', { body: { principals: [{ kind: 'everyone' }], can: { [pattern]: [] } } })
// A lock the board refused, such as one on everyone from a member where it takes a team owner (403
// `owner_required`), never landed: its own grant would be all that's left, so it goes too. One that
// may have landed (the request failed on the way) keeps it, so its creator isn't shut out.
const closed = await call<{ grant: GrantView }>('POST', '/grants', { body: { principals: [{ kind: 'everyone' }], can: { [pattern]: [] } } }).catch(async (error: unknown) => {
if (!(error instanceof BoardError && error.origin === 'board' && error.status >= 400 && error.status < 500)) throw error
await takeBack(own.grant.id)
if (error.code === 'owner_required')
throw new BoardError('owner_required', `Closing ${path} to everyone else takes a team owner, so a private ${path} wasn't made, and nothing was left behind.`, error.status, {
hint: `Ask a team owner to make it, or make ${path} open: vb channels create ${path}`,
origin: error.origin,
})
throw error
})
// Once the lock is there, no one it shuts out can grant themselves past it, so this listing is
// the last word: a grant made or changed before the lock landed would still let someone in, so
// it isn't private, and both of its grants go, the lock first.
Expand Down
21 changes: 21 additions & 0 deletions packages/board/test/grants-handle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ describe('a private channel, from the handle', () => {
expect((await team.channels()).channels).toEqual([])
})

it("takes its own grant back when only a team owner may lock the channel, so nothing is left half made", async () => {
const team = testBoard()
// Vercel's board: a lock on everyone takes a team owner.
const member = async (request: Request) => {
if (request.method === 'POST' && new URL(request.url).pathname.endsWith('/grants')) {
const body = (await request.clone().json()) as { principals: { kind: string }[] }
if (body.principals.some((principal) => principal.kind === 'everyone'))
return Response.json({ error: { code: 'owner_required', message: 'a lock on everyone takes a team owner' } }, { status: 403 })
}
return team.fetch(request)
}
const before = await ids(team)
await expect(handleAs(member, () => personToken()).createChannel('vault', { private: true })).rejects.toMatchObject({
status: 403,
code: 'owner_required',
message: expect.stringContaining('nothing was left behind'),
})
expect(await ids(team)).toEqual(before)
expect((await team.channels()).channels).toEqual([])
})

it('leaves at most one way in when two make the same private channel at once', async () => {
const team = testBoard()
/** What opens once both racers have reached it. */
Expand Down