remove the dead multi-user surface
Officer is single-user: the server owner is the only account, created once by /auth/bootstrap. Everything that existed to serve additional users was unreachable, so it is gone rather than left looking like it does something. Accounts: drop the invite / resend-invite / delete / list-users routes and the Users settings screen, the inert /auth/signup handler, and the account verification chain it fed (verify, resend-verification, VerifyScreen, the UserInvite + VerifyAdmin + VerifyRegistration templates). /auth/verify-token survives for password resets only, and now requires a reset-password token rather than accepting any signed JWT. Roles: drop the users.role column and the four-value USER_ROLES enum. The permissions table granted every role identical methods, and every role === 'Super Admin' check was permanently true. The JWT no longer carries a role claim. Sandbox: remove sidecar/sandbox.ts and its five call sites. bwrap was selected only for non-Super-Admin users, so it never ran. It was also not a usable agent jail as written — --share-net, the project root (with .env) bound read-only, and runuser dropping to the server's own uid. Rebuilding it for agent containment would be a different construction, and git history keeps this one. getHomeDir keeps its DATA_PATH meaning; the new getOwnerHomeDir resolves the owner's real login home, which is what terminals, chats and task runs use. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
92de996412
commit
044aacf4d5
@@ -1,17 +1,12 @@
|
||||
import type { ServerWebSocket } from 'bun';
|
||||
import { mkdirSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { getHomeDir } from '@@/data-path';
|
||||
import { join } from 'node:path';
|
||||
import { sendPtyCommand, sendPtyCommandAsync, on, isTerminalConnected } from '@@/sidecar-registry';
|
||||
import type { PtyInitConfig } from '../../sidecar/protocol';
|
||||
import { buildSandboxPrefix, buildRunuserSuffix, SANDBOX_HOME } from '../../sidecar/sandbox';
|
||||
|
||||
type WSData = {
|
||||
userId: number;
|
||||
email: string;
|
||||
username: string;
|
||||
role: string;
|
||||
sandboxed: boolean;
|
||||
sessionId?: string;
|
||||
cwd?: string;
|
||||
cols?: number;
|
||||
@@ -49,60 +44,28 @@ const resolveCwd = (home: string, cwd?: string) => {
|
||||
|
||||
export const terminalWebsocket = {
|
||||
async open(ws: ServerWebSocket<WSData>) {
|
||||
const { email, username, role, sandboxed } = ws.data;
|
||||
const isHost = !sandboxed && role === 'Super Admin';
|
||||
const { email, username } = ws.data;
|
||||
|
||||
console.log(
|
||||
`[terminal] open: email=${email} username=${username} role=${role} sandboxed=${sandboxed} isHost=${isHost}`,
|
||||
);
|
||||
console.log(`[terminal] open: email=${email} username=${username}`);
|
||||
|
||||
if (!isTerminalConnected()) {
|
||||
sendOutput(ws, '\r\n[Terminal error] PTY sidecar is not connected\r\n');
|
||||
return;
|
||||
}
|
||||
|
||||
const sessionId = ws.data.sessionId ?? (isHost ? `host-${ws.data.userId}` : `default-${ws.data.userId}`);
|
||||
const sessionId = ws.data.sessionId ?? `host-${ws.data.userId}`;
|
||||
|
||||
// Build PTY init config
|
||||
let config: PtyInitConfig;
|
||||
|
||||
if (isHost) {
|
||||
config = {
|
||||
sessionId,
|
||||
host: true,
|
||||
shell: { command: process.env.SHELL ?? '/bin/zsh', args: ['-i'] },
|
||||
cwd: resolveCwd(process.env.HOME!, ws.data.cwd),
|
||||
homeDir: process.env.HOME!,
|
||||
userLabel: email,
|
||||
cols: ws.data.cols,
|
||||
rows: ws.data.rows,
|
||||
};
|
||||
} else {
|
||||
const homeDir = getHomeDir(email);
|
||||
mkdirSync(dirname(homeDir), { recursive: true });
|
||||
mkdirSync(homeDir, { recursive: true });
|
||||
|
||||
// Build bwrap command for sandboxed terminal
|
||||
const prefix = buildSandboxPrefix(email);
|
||||
prefix.push('--setenv', 'ZDOTDIR', SANDBOX_HOME);
|
||||
prefix.push('--setenv', 'ZSH', `${SANDBOX_HOME}/.oh-my-zsh`);
|
||||
prefix.push('--setenv', 'SHELL', '/bin/zsh');
|
||||
prefix.push('--setenv', 'USER', username);
|
||||
prefix.push('--setenv', 'LOGNAME', username);
|
||||
prefix.push('--setenv', 'OFFICER_TERMINAL_USER', email);
|
||||
prefix.push('--setenv', 'TERM', 'xterm-256color');
|
||||
const bwrapArgs = [...prefix, ...buildRunuserSuffix(), '/bin/zsh', '-i'];
|
||||
|
||||
config = {
|
||||
sessionId,
|
||||
shell: { command: bwrapArgs[0]!, args: bwrapArgs.slice(1) },
|
||||
cwd: SANDBOX_HOME,
|
||||
homeDir,
|
||||
userLabel: email,
|
||||
cols: ws.data.cols,
|
||||
rows: ws.data.rows,
|
||||
};
|
||||
}
|
||||
// The server owner is the only account, so the terminal is always a plain host shell.
|
||||
const config: PtyInitConfig = {
|
||||
sessionId,
|
||||
host: true,
|
||||
shell: { command: process.env.SHELL ?? '/bin/zsh', args: ['-i'] },
|
||||
cwd: resolveCwd(process.env.HOME!, ws.data.cwd),
|
||||
homeDir: process.env.HOME!,
|
||||
userLabel: email,
|
||||
cols: ws.data.cols,
|
||||
rows: ws.data.rows,
|
||||
};
|
||||
|
||||
// Subscribe to events for this session
|
||||
const unsubOutput = on('pty:output', (msg) => {
|
||||
|
||||
Reference in New Issue
Block a user