user provisioning: the platform pushes the account list to plugins that declare it
a plugin that creates accounts in an upstream service — jellyfin first, immich next — needs to know who the platform's users are. it now gets told. DECLARED IN THE MANIFEST, not asserted at registration. `name` and `handles` arrive on an unauthenticated socket and are believed, so a capability claimed there would be a plugin granting itself one. the manifest was reviewed when the owner installed it, and sits beside `permissions` where "this plugin will be told who your users are" belongs — on the install screen, not discovered later. PUSHED, not requested. a sidecar has no authenticated way to ask, so a request could only be answered, never authorised. a push inverts that: the platform decides who gets it, and a caller registering under a name with no such manifest gets nothing. `listProvisionableUsers` is a hand-written projection — id, email, username, name, role — and NOT `select *`. `users` holds `password` and `os_user`, and `getUsers()` returns both, so a plugin reaching for the obvious function would get every account's password hash. naming the columns means adding a secret to the table cannot silently add it to what plugins receive. pinned by a test that asserts the key set, not just the absence of today's secrets. the owner is excluded. they bypass every permission check and already have whatever upstream account they want; provisioning them is at best a no-op and at worst a second admin nobody asked for. sent after the ack rather than inside it, so registration never waits on a database query — a slow postgres would otherwise stall every sidecar's startup, and none of them need the list to start. and re-sent on every account create and delete, because the registration copy is a snapshot: a plugin still holding a deleted user would keep an upstream login alive for someone the platform has removed. read once per broadcast, so two plugins cannot be told different things about the same moment.
This commit is contained in:
@@ -25,3 +25,5 @@ export {
|
||||
export { USER_ROLES, OWNER_USER_ID } from './schema';
|
||||
|
||||
export type { UserRole } from './schema';
|
||||
export { listProvisionableUsers } from './queries';
|
||||
export type { ProvisionableUser } from './queries';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { eq, and, lt, sql } from 'drizzle-orm';
|
||||
import { eq, ne, and, lt, sql } from 'drizzle-orm';
|
||||
import { db } from '../db';
|
||||
import { users, passkeys, passkeyChallenges, tokenBlacklist, OWNER_USER_ID } from './schema';
|
||||
import type { UserSelect, UserInsert, PasskeySelect, PasskeyInsert } from '../types';
|
||||
@@ -9,6 +9,40 @@ export async function getUsers(): Promise<UserSelect[]> {
|
||||
return db.select().from(users);
|
||||
}
|
||||
|
||||
/** What a plugin is told about an account. Deliberately not a `UserSelect`. */
|
||||
export type ProvisionableUser = {
|
||||
id: number;
|
||||
email: string;
|
||||
username: string | null;
|
||||
name: string | null;
|
||||
role: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* The accounts a plugin may provision in its upstream service.
|
||||
*
|
||||
* A hand-written projection, NOT `select *`. `users` holds `password` (the hash) and `os_user`, and
|
||||
* `getUsers()` returns both — so a plugin reaching for the obvious function gets every account's
|
||||
* password hash. The columns are named here so that cannot happen by accident: adding a secret to the
|
||||
* table does not silently add it to what plugins receive.
|
||||
*
|
||||
* The OWNER is excluded. They are user 1 by CHECK constraint, they bypass every permission check, and
|
||||
* they already have whatever account they want upstream — provisioning them is at best a no-op and at
|
||||
* worst a second admin nobody asked for.
|
||||
*/
|
||||
export async function listProvisionableUsers(): Promise<ProvisionableUser[]> {
|
||||
return db
|
||||
.select({
|
||||
id: users.id,
|
||||
email: users.email,
|
||||
username: users.username,
|
||||
name: users.name,
|
||||
role: users.role,
|
||||
})
|
||||
.from(users)
|
||||
.where(ne(users.id, OWNER_USER_ID));
|
||||
}
|
||||
|
||||
export async function getUserById(id: number): Promise<UserSelect | undefined> {
|
||||
const [user] = await db.select().from(users).where(eq(users.id, id));
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user