mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 12:07:28 +01:00
The org write token added in #634 was handed to any signed-in account. It can create, seed and DELETE repositories in the bitbaum organisation — a server-held admin credential reachable by whoever holds a session is a privilege escalation waiting for the first external user, and FleetCrown is schema-ready for those today. It is now offered only to accounts already entitled to fleet-owned infrastructure — founder or explicit allowlist, the same boundary the shared cloud builder draws (docs/architecture/multitenancy-execution-plan.md). Anyone else writes with their own GitHub token exactly as before, and if their org refuses it they get the honest 403 that names both remedies. `isFleetInfrastructureAllowed` is separate from `getExecutionAccess` on purpose: that one also reads runner presence, which a GitHub write has no use for, and "may this account act as the fleet" deserves one name every caller asks by rather than each re-deriving `isDefault || allowlist`. Verified: tsc, eslint, scripts/test/github-org-token.ts (extended to pin that an unentitled account falls back to its own token, never the org's). Claude-Session: https://claude.ai/code/session_01WSNERoZZqW2TgqbAGHSQZf Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
/**
|
|
* Pins which token an org-scoped GitHub write uses.
|
|
* Run: npx tsx scripts/test/github-org-token.ts
|
|
*/
|
|
import { pickRepoWriteToken } from "@/lib/github-org-token";
|
|
|
|
const org = pickRepoWriteToken("org-tok", "user-tok");
|
|
if (!org || org.source !== "org" || org.token !== "org-tok") {
|
|
throw new Error("a configured org token must win over the person's token");
|
|
}
|
|
const user = pickRepoWriteToken(null, "user-tok");
|
|
if (!user || user.source !== "user" || user.token !== "user-tok") {
|
|
throw new Error("without an org token the person's token is used");
|
|
}
|
|
if (pickRepoWriteToken(null, null) !== null) throw new Error("no token → null, never a guess");
|
|
if (pickRepoWriteToken("", "user-tok")?.source !== "user") {
|
|
throw new Error("an empty org token is no org token");
|
|
}
|
|
// The entitlement is the caller's job (getRepoWriteToken passes null for an
|
|
// account that may not use fleet infrastructure); this pins that passing null
|
|
// is exactly equivalent to having no server token at all.
|
|
if (pickRepoWriteToken(null, "user-tok")?.source !== "user") {
|
|
throw new Error("an unentitled account falls back to its own token, never the org's");
|
|
}
|
|
if (pickRepoWriteToken(null, null) !== null) {
|
|
throw new Error("an unentitled account with no token of its own gets nothing to write with");
|
|
}
|
|
|
|
console.log("✓ github org token");
|