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
@@ -2,7 +2,6 @@ import { join } from 'node:path';
|
||||
import type { Subprocess } from 'bun';
|
||||
import type { ChatEvent } from '../../api/chat/types';
|
||||
import type { ClaudeSpawnParams, ClaudeSpawnStreamingParams, ClaudeCodeResult } from '../protocol';
|
||||
import { buildSandboxPrefix, buildRunuserSuffix, SANDBOX_HOME } from '../sandbox';
|
||||
import { setClaudeSession, clearClaudeSession, getClaudeSession } from './state';
|
||||
import { parseStream } from './stream-parser';
|
||||
|
||||
@@ -16,26 +15,13 @@ const CLAUDE_BIN = '/usr/local/bin/claude';
|
||||
const HOST_HOME = process.env.HOME!;
|
||||
const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
|
||||
|
||||
// Build full bwrap sandbox args for Claude (prefix + Anthropic env + runuser suffix)
|
||||
function buildSandboxArgs(email: string): string[] {
|
||||
const prefix = buildSandboxPrefix(email);
|
||||
|
||||
// Claude-specific env vars
|
||||
if (process.env.ANTHROPIC_BASE_URL) prefix.push('--setenv', 'ANTHROPIC_BASE_URL', process.env.ANTHROPIC_BASE_URL);
|
||||
if (process.env.ANTHROPIC_API_KEY) prefix.push('--setenv', 'ANTHROPIC_API_KEY', process.env.ANTHROPIC_API_KEY);
|
||||
|
||||
return [...prefix, ...buildRunuserSuffix()];
|
||||
}
|
||||
|
||||
// Active streaming processes
|
||||
const activeProcs = new Map<string, Subprocess>();
|
||||
|
||||
// MCP config paths, set by user-instance at startup
|
||||
let mcpSandboxPath: string | undefined; // path inside bwrap sandbox (/data/...)
|
||||
let mcpHostPath: string | undefined; // path on the host filesystem
|
||||
|
||||
export function setMcpConfigPath(sandboxPath: string, hostPath: string): void {
|
||||
mcpSandboxPath = sandboxPath;
|
||||
export function setMcpConfigPath(hostPath: string): void {
|
||||
mcpHostPath = hostPath;
|
||||
}
|
||||
|
||||
@@ -57,8 +43,7 @@ export async function spawnClaude(params: ClaudeSpawnParams): Promise<ClaudeCode
|
||||
|
||||
const claudeArgs = [CLAUDE_BIN, '-p', prompt, '--dangerously-skip-permissions', '--output-format', 'json'];
|
||||
|
||||
const isSuperAdmin = params.role === 'Super Admin';
|
||||
const mcpConfig = isSuperAdmin ? mcpHostPath : mcpSandboxPath;
|
||||
const mcpConfig = mcpHostPath;
|
||||
if (mcpConfig) claudeArgs.push('--mcp-config', mcpConfig);
|
||||
|
||||
const subModel = params.model?.split('/')[1];
|
||||
@@ -68,10 +53,10 @@ export async function spawnClaude(params: ClaudeSpawnParams): Promise<ClaudeCode
|
||||
claudeArgs.push('--resume', existingSession);
|
||||
}
|
||||
|
||||
const spawnCmd = isSuperAdmin ? claudeArgs : [...buildSandboxArgs(email), ...claudeArgs];
|
||||
// Honor a caller-provided working directory (e.g. /chat runs from a dedicated general_chat_sessions dir);
|
||||
// fall back to the host home for Super Admin, or the sandbox default otherwise.
|
||||
const spawnCwd = isSuperAdmin ? (params.cwd ?? HOST_HOME) : undefined;
|
||||
const spawnCmd = claudeArgs;
|
||||
// Honor a caller-provided working directory (e.g. /chat runs from a dedicated general_chat_sessions
|
||||
// dir); fall back to the owner's host home.
|
||||
const spawnCwd = params.cwd ?? HOST_HOME;
|
||||
|
||||
const proc = Bun.spawn(spawnCmd, {
|
||||
stdin: 'pipe',
|
||||
@@ -156,8 +141,7 @@ export async function spawnClaudeStreaming(
|
||||
];
|
||||
|
||||
const { CLAUDECODE: _, ...cleanEnv } = process.env;
|
||||
const isSuperAdmin = params.role === 'Super Admin';
|
||||
const mcpConfig = isSuperAdmin ? mcpHostPath : mcpSandboxPath;
|
||||
const mcpConfig = mcpHostPath;
|
||||
if (mcpConfig) claudeArgs.push('--mcp-config', mcpConfig);
|
||||
|
||||
const subModel = params.model?.split('/')[1];
|
||||
@@ -171,10 +155,10 @@ export async function spawnClaudeStreaming(
|
||||
if (!existingSession) setClaudeSession(sessionKey, resumeId);
|
||||
}
|
||||
|
||||
const spawnCmd = isSuperAdmin ? claudeArgs : [...buildSandboxArgs(email), ...claudeArgs];
|
||||
// Honor a caller-provided working directory (e.g. /chat runs from a dedicated general_chat_sessions dir);
|
||||
// fall back to the host home for Super Admin, or the sandbox default otherwise.
|
||||
const spawnCwd = isSuperAdmin ? (params.cwd ?? HOST_HOME) : undefined;
|
||||
const spawnCmd = claudeArgs;
|
||||
// Honor a caller-provided working directory (e.g. /chat runs from a dedicated general_chat_sessions
|
||||
// dir); fall back to the owner's host home.
|
||||
const spawnCwd = params.cwd ?? HOST_HOME;
|
||||
|
||||
const proc = Bun.spawn(spawnCmd, {
|
||||
stdin: 'ignore',
|
||||
|
||||
@@ -4,7 +4,6 @@ import { homedir } from 'node:os';
|
||||
import type { SidecarCommand, SidecarEvent } from '../protocol';
|
||||
import { initPaths, loadState, flushAndSave, acquireLock, releaseLock } from './state';
|
||||
import { setMcpConfigPath } from './claude-manager';
|
||||
import { SANDBOX_DATA } from '../sandbox';
|
||||
import * as claudeManager from './claude-manager';
|
||||
import { createSidecarConnector } from '../connect';
|
||||
import { sign } from '../../jwt';
|
||||
@@ -27,16 +26,12 @@ if (!dbUser) {
|
||||
console.error(`[user-instance] no user found for ${email}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const OFFICER_AUTH_TOKEN = await sign(
|
||||
{ id: dbUser.id, email, username: dbUser.username, role: dbUser.role },
|
||||
'30d',
|
||||
);
|
||||
const OFFICER_AUTH_TOKEN = await sign({ id: dbUser.id, email, username: dbUser.username }, '30d');
|
||||
|
||||
// Single-user platform: the Super Admin runs Claude with no isolation — real HOME, real ~/.claude —
|
||||
// so platform sessions have perfect parity with terminal sessions (same config, credentials, and
|
||||
// transcript store, interchangeable via `claude --resume`). Any non-super-admin keeps an isolated home.
|
||||
const homeDir =
|
||||
dbUser.role === 'Super Admin' ? (process.env.HOME_DIR ?? homedir()) : join(DATA_PATH, email, 'home');
|
||||
// Single-user platform: the owner runs Claude with no isolation — real HOME, real ~/.claude — so
|
||||
// platform sessions have perfect parity with terminal sessions (same config, credentials and
|
||||
// transcript store, interchangeable via `claude --resume`).
|
||||
const homeDir = process.env.HOME_DIR ?? homedir();
|
||||
const globalToolsDir = join(DATA_PATH, 'tools');
|
||||
|
||||
// The email_db MCP tool reads one account's SQLite store; match the API's choice (first enabled).
|
||||
@@ -60,52 +55,14 @@ if (!acquireLock()) {
|
||||
|
||||
loadState();
|
||||
|
||||
// ── CLAUDE.md refresh ──
|
||||
|
||||
function refreshClaudeMd(): void {
|
||||
const claudeDir = join(homeDir, '.claude');
|
||||
if (!existsSync(claudeDir)) mkdirSync(claudeDir, { recursive: true });
|
||||
|
||||
// generateContainerContext writes and returns the file path
|
||||
// Import inline to avoid circular deps at module level
|
||||
const { generateContainerContext } = require('../../generate-container-context') as {
|
||||
generateContainerContext: (email: string) => string;
|
||||
};
|
||||
const contextFile = generateContainerContext(email!);
|
||||
writeFileSync(join(claudeDir, 'CLAUDE.md'), readFileSync(contextFile, 'utf-8'));
|
||||
}
|
||||
|
||||
// ── MCP config ──
|
||||
|
||||
type McpPaths = { sandboxPath: string; hostPath: string };
|
||||
|
||||
function generateMcpConfig(): McpPaths {
|
||||
function generateMcpConfig(): string {
|
||||
const contextDir = join(DATA_PATH, email!, '.container-context');
|
||||
mkdirSync(contextDir, { recursive: true });
|
||||
|
||||
const userRoot = join(DATA_PATH, email!);
|
||||
|
||||
// Sandbox config (paths relative to /data mount)
|
||||
const sandboxToolsDirs = [globalToolsDir, ...(existsSync(userToolsDir) ? [`${SANDBOX_DATA}/tools`] : [])].join(':');
|
||||
const sandboxConfig = {
|
||||
mcpServers: {
|
||||
'officer-tools': {
|
||||
type: 'stdio',
|
||||
command: 'bun',
|
||||
args: ['run', MCP_SERVER_SCRIPT],
|
||||
env: {
|
||||
PI_TOOLS_DIRS: sandboxToolsDirs,
|
||||
OFFICER_EMAIL_DB: `${SANDBOX_DATA}/${emailDbRel}`,
|
||||
MCP_TOOLS_LOG: `${SANDBOX_DATA}/logs/mcp-tools.log`,
|
||||
OFFICER_API_URL,
|
||||
OFFICER_AUTH_TOKEN,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
writeFileSync(join(contextDir, 'mcp.json'), JSON.stringify(sandboxConfig));
|
||||
|
||||
// Host config (real filesystem paths, for Super Admin)
|
||||
const hostToolsDirs = [globalToolsDir, ...(existsSync(userToolsDir) ? [userToolsDir] : [])].join(':');
|
||||
const hostConfig = {
|
||||
mcpServers: {
|
||||
@@ -125,27 +82,16 @@ function generateMcpConfig(): McpPaths {
|
||||
};
|
||||
writeFileSync(join(contextDir, 'mcp-host.json'), JSON.stringify(hostConfig));
|
||||
|
||||
return {
|
||||
sandboxPath: `${SANDBOX_DATA}/.container-context/mcp.json`,
|
||||
hostPath: join(contextDir, 'mcp-host.json'),
|
||||
};
|
||||
return join(contextDir, 'mcp-host.json');
|
||||
}
|
||||
|
||||
// ── Startup ──
|
||||
|
||||
// Only sandboxed users get the generated container CLAUDE.md. For the un-isolated Super Admin, HOME is
|
||||
// the real home, so writing it there would pollute the personal global ~/.claude/CLAUDE.md (loaded by
|
||||
// the terminal `claude` too) — parity means running as the user, not injecting platform context.
|
||||
if (dbUser.role !== 'Super Admin') {
|
||||
try {
|
||||
refreshClaudeMd();
|
||||
} catch (err) {
|
||||
console.error(`[claude:${email}] failed to refresh CLAUDE.md:`, err instanceof Error ? err.message : err);
|
||||
}
|
||||
}
|
||||
// The owner runs un-isolated with HOME as their real home, so the generated container CLAUDE.md is
|
||||
// deliberately not written — it would pollute the personal global ~/.claude/CLAUDE.md that the
|
||||
// terminal `claude` loads too.
|
||||
|
||||
const mcpPaths = generateMcpConfig();
|
||||
setMcpConfigPath(mcpPaths.sandboxPath, mcpPaths.hostPath);
|
||||
setMcpConfigPath(generateMcpConfig());
|
||||
|
||||
console.log(`[claude:${email}] started (HOME=${homeDir})`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user