Offscale was the first plugin extracted and it was done before we knew what "extracted" meant. Music, done last, is the standard. This brings offscale to it. ── The rebrand ── The plugin was `offscale` to the platform and `headscale` to itself: sidecar name and handles, the port announcement, the API proxy name, the React components, every hook, the react-query keys, the panel ids and appTypes, and the Postgres table. Now all of those say offscale. The line drawn, and it is deliberate: OffScale is Officer's tooling layer, and Headscale is the server it manages. So every IDENTIFIER is offscale, while a message like `headscale unreachable`, the `headscale apikeys create` hint and the ACL assistant's prompt still say Headscale — because they are talking about the remote server, and renaming them would make the code lie about what it reached. 495 occurrences became 180, and the 180 are all of that second kind. ── The live bug this uncovered ── `headscaleSectionPath` built links to `/headscale/<section>`. The shell has no such route — plugin routes come from `plugin.route`, which is `/offscale` — and it redirects unknown paths to the home page. So every section link in the nav, the console and the server picker silently went home. The extraction moved the route and left the link builder behind. Also live: ServersView told the user to run `pm2 start ecosystem.config.cjs --only officer-headscale`, a process that has not existed since the sidecar was renamed. ── The correctness fix music already had ── api/router.ts hardcoded `prefix: '/api/offscale'`. The proxy strips `prefix.length` characters, so a literal is correct only for a first-party publisher; published by anyone else this mounts at `/api/p/<publisher>/offscale` and forwards the wrong subpath. Derived from `mountPrefix()` now, as music does. ── The rest ── - assets/icon.png — the OffScale artwork, 256px to match music's. The tile stops being a glyph badge. - First tests: 21 of them, over the version floor and the protobuf normalisers. Those are the two places a Headscale release actually breaks this, and they had no coverage at all. `meetsFloor` has a real trap pinned now — comparing minor first would refuse 1.0 as older than 0.29. - OFFSCALE_API.md — the contract was a 45-line comment inside sidecar/index.ts, which is not linkable and not published. Now a document, as MUSIC_API.md is. - web/panels.ts re-exported three components. A plugin cannot export components; that was residue of the platform importing them before extraction. - Comments pointed at src/servers/api/headscale/ and src/servers/sidecar/headscale/, neither of which has existed since the extraction. The crypto purpose moved headscale → offscale too, and the secret-store row was renamed rather than left to create a fresh key — the material is preserved, so this is reversible. Free to do only because offscale_servers had 0 rows; with one stored API key it would have been a migration.
56 lines
3.4 KiB
TypeScript
56 lines
3.4 KiB
TypeScript
import { pgTable, serial, integer, text, boolean, timestamp, uniqueIndex } from 'drizzle-orm/pg-core';
|
|
import { sql } from 'drizzle-orm';
|
|
import { users } from 'officerdb/auth/schema';
|
|
|
|
// The Headscale servers the owner manages, for the officer-offscale sidecar. Officer targets no single
|
|
// Headscale: the owner registers one or more servers (URL + an admin API key generated on that server) and
|
|
// toggles between them, so this is configuration the user creates at runtime rather than env vars.
|
|
//
|
|
// `api_key` is a Headscale *admin* credential — it can delete every node on a tailnet — so it is encrypted
|
|
// at rest via ../crypto.ts, exactly like the vault token set. Encryption/decryption is confined to
|
|
// queries/headscale.ts; nothing outside that file ever sees ciphertext, and list callers never see the key
|
|
// at all. SECURITY_AUDIT.md L2 records plaintext credential storage as an open finding, so the plaintext
|
|
// email/integrations tables are debt to avoid copying, not a precedent to follow.
|
|
//
|
|
// Every table here is `offscale_`-prefixed and this file holds nothing else: when sidecars own their own
|
|
// schema it moves wholesale into ../sidecar/ with no untangling. Only the
|
|
// officer-offscale sidecar reads or writes these tables.
|
|
|
|
export const offscaleServers = pgTable(
|
|
'offscale_servers',
|
|
{
|
|
id: serial('id').primaryKey(),
|
|
userId: integer('user_id')
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
|
name: text('name').notNull(),
|
|
// Normalized without a trailing slash before write, so `${url}/api/v1/...` never doubles the separator.
|
|
url: text('url').notNull(),
|
|
apiKey: text('api_key').notNull(), // encrypted
|
|
// Last version seen from the server's unauthenticated GET /version. Null until first probed; the
|
|
// literal 'dev' when the server was built without VCS info, which is unknown rather than too-old.
|
|
version: text('version'),
|
|
// Where to SSH for a shell on the box running this Headscale — the last-resort escape hatch for when the
|
|
// API cannot answer (headscale is down, the tailnet is down, the logs are the only evidence). Deliberately
|
|
// NOT derived from `url`: the whole point is to reach the machine when the control plane's own hostname
|
|
// stops resolving, so this is usually a raw IP on a different path. No port, user or key material — the
|
|
// connection uses whatever ~/.ssh already knows, so there is no credential here to protect.
|
|
sshHost: text('ssh_host'),
|
|
isActive: boolean('is_active').notNull().default(false),
|
|
// Last successful probe, so the UI can distinguish "never reached" from "was reachable, now isn't".
|
|
lastSeenAt: timestamp('last_seen_at', { withTimezone: true }),
|
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
},
|
|
(t) => [
|
|
// One registration per URL — re-registering the same server should be an edit, not a duplicate.
|
|
uniqueIndex('uq_offscale_servers_user_url').on(t.userId, t.url),
|
|
// At most one active server per owner, enforced by the DB rather than by convention: a partial unique
|
|
// index over the active rows only. setActiveOffscaleServer still clears the others in a transaction,
|
|
// but a bug there fails loudly here instead of silently leaving two servers active.
|
|
uniqueIndex('uq_offscale_servers_one_active')
|
|
.on(t.userId)
|
|
.where(sql`${t.isActive}`),
|
|
],
|
|
);
|