feat(server-s3): one Linux user per account (S3) — experimental
Server mode can now run each account as its own Linux user (ah-<name>) when `agenthub server install-system` has set S3 up. The dashboard reaches a member only through sudo -u / write-as / pane-launch, reads a member's files only through owner- and type-checked opens, and hooks are authenticated by peer uid. Local mode and server mode without S3 are unchanged. EXPERIMENTAL: tested with fake sudo and fake accounts only. It has not yet been verified on a real install with real member accounts, sudo or a real Codex login. Do not offer it to real users yet. - S3 core: provisioning, per-member tmux servers, the proxy key gateway, shared tools in /opt, dropped capabilities for children (P0–P5) - P4: plan and quota per member home - P6: ~/.claude.json seed; opt-in plugin baseline installed as the member; managed-settings spike script (not run) - P7: Codex account pool (`agenthub accounts add --tool codex`) - Roles merged with main's admin / analyst / developer: analysts write only their own rows, under S3 as well - Per-account prefs: one implementation (Chat UI + onboarding) - Security reviews F1–F49 (five rounds), each fix with a regression test: symlink/TOCTOU-safe member reads, no host writes in a member home, credentials and the data dir never served, owner and folder account must agree, pane tokens bound to the pane's uid, bounded sudo/tmux/git calls and member reads (no hang or crash from a member), async route rejections answer 500 instead of exiting - Docs: docs/SERVER-MODE.md (S3 model, accepted ceilings, operator runbook), docs/plans/server-mode/S3-PLAN.md, CLAUDE.md S3 rules Tests: server 2838/2841 (3 need 127.0.0.1:3000, held on this box); client 1162/1162; tsc clean; headers check passes. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,11 @@
|
||||
* A right-click on a profile row opens its Edit / Remove (plus Copy endpoint)
|
||||
* as a menu; the buttons stay.
|
||||
*
|
||||
* In server mode a profile is SHARED (an admin's, usable by everyone) or
|
||||
* PERSONAL (the signed-in user's own, badged "Personal"). A member edits only
|
||||
* their own and every profile they add is personal; an admin chooses when
|
||||
* adding; an analyst only reads.
|
||||
*
|
||||
* **Test** asks the endpoint itself, once as Claude Code would
|
||||
* (`/v1/messages`) and once as Codex would (`/v1/responses`), one line each.
|
||||
* "Saved" and "works" are different claims, and the gap between them is only
|
||||
@@ -43,13 +48,15 @@ import { ContextMenu, MenuItem, MenuSeparator, useContextMenu } from "../compone
|
||||
import { confirmDialog } from "../lib/confirm";
|
||||
import { copyText } from "../lib/clipboard";
|
||||
import { useDialog } from "../hooks/useDialog";
|
||||
import { useAuth } from "../components/AuthGate";
|
||||
|
||||
const TIERS: (keyof AiProxyModels)[] = ["opus", "sonnet", "haiku", "smallFast", "subagent"];
|
||||
|
||||
type FormState = Omit<AiProxyInput, "apiKey" | "models" | "behavesAs"> & {
|
||||
type FormState = Omit<AiProxyInput, "apiKey" | "models" | "behavesAs" | "scope"> & {
|
||||
apiKey: string;
|
||||
behavesAs: string;
|
||||
models: Partial<AiProxyModels>;
|
||||
scope: "shared" | "personal";
|
||||
};
|
||||
|
||||
const emptyForm = (): FormState => ({
|
||||
@@ -59,10 +66,17 @@ const emptyForm = (): FormState => ({
|
||||
model: "",
|
||||
models: {},
|
||||
behavesAs: "",
|
||||
scope: "shared",
|
||||
});
|
||||
|
||||
export function AiProxyConfig() {
|
||||
const { t } = useTranslation("settings");
|
||||
// Server mode's signed-in user; null in local mode, where the host owns
|
||||
// every (shared) profile.
|
||||
const { state: auth } = useAuth();
|
||||
const user = auth.mode === "server" ? auth.user : null;
|
||||
const isAdmin = !user || user.role === "admin";
|
||||
const canWrite = (item: AiProxy) => !item.builtin && (item.scope === "personal" || isAdmin);
|
||||
const [items, setItems] = useState<AiProxy[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<AiProxy | null>(null);
|
||||
@@ -131,6 +145,7 @@ export function AiProxyConfig() {
|
||||
model: item.model,
|
||||
models: { ...item.models },
|
||||
behavesAs: item.behavesAs ?? "",
|
||||
scope: item.scope ?? "shared",
|
||||
});
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
@@ -187,6 +202,7 @@ export function AiProxyConfig() {
|
||||
behavesAs: form.behavesAs.trim(),
|
||||
};
|
||||
if (form.apiKey.trim()) body.apiKey = form.apiKey.trim();
|
||||
if (user && isAdmin && !editing) body.scope = form.scope;
|
||||
|
||||
if (editing) await api.aiProxies.update(editing.name, body);
|
||||
else await api.aiProxies.create(body);
|
||||
@@ -253,13 +269,18 @@ export function AiProxyConfig() {
|
||||
{items.map((item) => (
|
||||
<tr
|
||||
key={item.name}
|
||||
onContextMenu={item.builtin ? undefined : (e) => ctx.open(e, item)}
|
||||
onContextMenu={canWrite(item) ? (e) => ctx.open(e, item) : undefined}
|
||||
className="border-t border-border"
|
||||
>
|
||||
<td className="px-3 py-2">
|
||||
<span className="flex items-center gap-1.5 font-medium text-fg-primary">
|
||||
{item.builtin && <Lock className="h-3 w-3 text-fg-muted" />}
|
||||
{item.label}
|
||||
{item.scope === "personal" && (
|
||||
<span className="rounded bg-accent/15 px-1.5 py-px text-[10px] font-normal text-accent">
|
||||
{t("aiProxy.personal")}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{item.builtin && (
|
||||
<span className="mt-0.5 block text-[10px] text-fg-muted">
|
||||
@@ -277,7 +298,7 @@ export function AiProxyConfig() {
|
||||
{item.builtin ? "—" : item.hasKey ? t("aiProxy.keySet") : t("aiProxy.keyMissing")}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right">
|
||||
{!item.builtin && (
|
||||
{canWrite(item) && (
|
||||
<span className="inline-flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
@@ -349,6 +370,31 @@ export function AiProxyConfig() {
|
||||
value={form.label}
|
||||
onChange={(v) => setForm((f) => ({ ...f, label: v }))}
|
||||
/>
|
||||
{user && !editing && (
|
||||
<div>
|
||||
<label className="mb-1 block text-xs text-fg-secondary" htmlFor="proxy-scope">
|
||||
{t("aiProxy.fieldScope")}
|
||||
</label>
|
||||
{isAdmin ? (
|
||||
<select
|
||||
id="proxy-scope"
|
||||
value={form.scope}
|
||||
onChange={(e) =>
|
||||
setForm((f) => ({ ...f, scope: e.target.value as FormState["scope"] }))
|
||||
}
|
||||
className="w-full rounded-md border border-border-light bg-surface-0 px-3 py-1.5 text-xs text-fg-primary focus:border-accent focus:outline-none"
|
||||
>
|
||||
<option value="shared">{t("aiProxy.scopeShared")}</option>
|
||||
<option value="personal">{t("aiProxy.scopePersonal")}</option>
|
||||
</select>
|
||||
) : (
|
||||
<p id="proxy-scope" className="text-xs text-fg-primary">
|
||||
{t("aiProxy.scopePersonal")}
|
||||
</p>
|
||||
)}
|
||||
<p className="mt-1 text-[10px] text-fg-muted">{t("aiProxy.fieldScopeHint")}</p>
|
||||
</div>
|
||||
)}
|
||||
<Field
|
||||
id="proxy-base-url"
|
||||
label={t("aiProxy.fieldBaseUrl")}
|
||||
|
||||
@@ -140,7 +140,8 @@ const MOVED: Record<string, string> = {
|
||||
};
|
||||
|
||||
/** Sections that only configure the host (ADMIN_WRITE_PREFIXES in server/lib/auth.js). */
|
||||
const ADMIN_SECTIONS = new Set(["data", "ai-proxy", "pricing"]);
|
||||
// AI Proxy is not here: every user keeps personal profiles (S3).
|
||||
const ADMIN_SECTIONS = new Set(["data", "pricing"]);
|
||||
|
||||
/** An unknown section: say so, then show Appearance. */
|
||||
function UnknownSection({ name }: { name: string }) {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* @file Tests for the AI Proxy settings page — listing profiles, creating one,
|
||||
* and the two rules that keep a key safe: the form never shows one, and an
|
||||
* edit that leaves the field blank must not send an empty key that would wipe
|
||||
* the stored one.
|
||||
* the stored one. In server mode: a developer or analyst edits only their
|
||||
* personal profiles and adds personal ones, an admin picks shared or personal.
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
|
||||
@@ -12,6 +13,12 @@ import userEvent from "@testing-library/user-event";
|
||||
import { AiProxyConfig } from "../AiProxyConfig";
|
||||
import { api } from "../../lib/api";
|
||||
import { settleConfirm, subscribeConfirm, type PendingConfirm } from "../../lib/confirm";
|
||||
import type { AuthState } from "../../lib/api";
|
||||
|
||||
let authState: AuthState = { mode: "local" };
|
||||
vi.mock("../../components/AuthGate", () => ({
|
||||
useAuth: () => ({ state: authState, logout: async () => {} }),
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/api", () => ({
|
||||
api: {
|
||||
@@ -60,6 +67,7 @@ const nineRouter = {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
authState = { mode: "local" };
|
||||
vi.mocked(api.aiProxies.list)
|
||||
.mockReset()
|
||||
.mockResolvedValue({ items: [native] });
|
||||
@@ -286,3 +294,70 @@ describe("AiProxyConfig — testing an endpoint before saving it", () => {
|
||||
off();
|
||||
});
|
||||
});
|
||||
|
||||
describe("AiProxyConfig in server mode", () => {
|
||||
const shared = { ...nineRouter, scope: "shared" as const };
|
||||
const mine = {
|
||||
...nineRouter,
|
||||
name: "u7_mine",
|
||||
label: "Mine",
|
||||
scope: "personal" as const,
|
||||
};
|
||||
const signIn = (role: "admin" | "developer" | "analyst") => {
|
||||
authState = { mode: "server", user: { id: 7, username: "mia", role } };
|
||||
};
|
||||
|
||||
it("lets a developer edit only their personal profile, badged Personal", async () => {
|
||||
signIn("developer");
|
||||
vi.mocked(api.aiProxies.list).mockResolvedValue({ items: [native, shared, mine] });
|
||||
render(<AiProxyConfig />);
|
||||
await screen.findByText("Mine");
|
||||
expect(screen.getByText("aiProxy.personal")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /aiProxy\.edit 9Router/ })).toBeNull();
|
||||
expect(screen.getByRole("button", { name: /aiProxy\.edit Mine/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("adds a developer's profile as personal, with no scope choice", async () => {
|
||||
signIn("developer");
|
||||
const user = userEvent.setup();
|
||||
render(<AiProxyConfig />);
|
||||
await user.click(await screen.findByRole("button", { name: /aiProxy\.add/ }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(within(dialog).queryByRole("combobox")).toBeNull();
|
||||
expect(within(dialog).getByText("aiProxy.scopePersonal")).toBeInTheDocument();
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldLabel"), "Mine");
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldBaseUrl"), "http://x:1");
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldModel"), "m");
|
||||
await user.click(screen.getByRole("button", { name: "aiProxy.save" }));
|
||||
await waitFor(() => expect(api.aiProxies.create).toHaveBeenCalled());
|
||||
expect(vi.mocked(api.aiProxies.create).mock.calls[0]?.[0].scope).toBeUndefined();
|
||||
});
|
||||
|
||||
it("lets an admin choose a personal profile", async () => {
|
||||
signIn("admin");
|
||||
vi.mocked(api.aiProxies.list).mockResolvedValue({ items: [native, shared] });
|
||||
const user = userEvent.setup();
|
||||
render(<AiProxyConfig />);
|
||||
expect(
|
||||
await screen.findByRole("button", { name: /aiProxy\.edit 9Router/ })
|
||||
).toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: /aiProxy\.add/ }));
|
||||
await user.selectOptions(screen.getByLabelText("aiProxy.fieldScope"), "personal");
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldLabel"), "Boss");
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldBaseUrl"), "http://x:1");
|
||||
await user.type(screen.getByLabelText("aiProxy.fieldModel"), "m");
|
||||
await user.click(screen.getByRole("button", { name: "aiProxy.save" }));
|
||||
await waitFor(() => expect(api.aiProxies.create).toHaveBeenCalled());
|
||||
expect(vi.mocked(api.aiProxies.create).mock.calls[0]?.[0].scope).toBe("personal");
|
||||
});
|
||||
|
||||
it("gives an analyst Add and Edit on personal profiles only", async () => {
|
||||
signIn("analyst");
|
||||
vi.mocked(api.aiProxies.list).mockResolvedValue({ items: [native, shared, mine] });
|
||||
render(<AiProxyConfig />);
|
||||
await screen.findByText("Mine");
|
||||
expect(screen.getByRole("button", { name: /aiProxy\.add/ })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /aiProxy\.edit 9Router/ })).toBeNull();
|
||||
expect(screen.getByRole("button", { name: /aiProxy\.edit Mine/ })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9444,7 +9444,7 @@ exit 0
|
||||
<p
|
||||
class="mt-0.5 text-xs text-fg-muted"
|
||||
>
|
||||
Theme, language, notification settings, pet, sidebar and workspace layout are kept in this browser. Save them to a file to move them to another browser, or restore them from one.
|
||||
Theme, language, notification settings and pet follow your account; the sidebar and workspace layout are kept in this browser. Save them to a file to move them to another browser, or restore them from one.
|
||||
</p>
|
||||
<div
|
||||
class="mt-2"
|
||||
@@ -9609,7 +9609,7 @@ exports[`screen snapshots > Settings — notifications 1`] = `
|
||||
<p
|
||||
class="text-xs text-fg-muted"
|
||||
>
|
||||
These notification settings are saved in this browser only. Alert rules and webhooks below are server-wide: they apply to everyone using this dashboard.
|
||||
These notification settings are saved to your account. Alert rules and webhooks below are server-wide: they apply to everyone using this dashboard.
|
||||
</p>
|
||||
<section
|
||||
class="scroll-mt-24"
|
||||
|
||||
Reference in New Issue
Block a user