Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions dashboard/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
AgentBundlePreview,
AgentItemBody,
AgentMcpServer,
AgentMcpServerBody,
AgentRepoBody,
AgentSetDetail,
AgentSetSummary,
Expand Down Expand Up @@ -465,13 +465,13 @@ export const api = {
method: 'DELETE',
}),
/**
* Adds one MCP server to a set, or changes the headers of a server.
* Adds one MCP server to a set, or changes the headers or the upstream CA of a server.
*
* @param setId The id of the agent set.
* @param body The name, the URL, the auth mode and the headers of the server.
* @param body The name, the URL, the auth mode, the headers and the upstream CA of the server.
* @returns The whole set after the change.
*/
putAgentMcpServer: (setId: string, body: AgentMcpServer) =>
putAgentMcpServer: (setId: string, body: AgentMcpServerBody) =>
request<AgentSetDetail>(`/api/agent-sets/${setId}/mcp-servers`, {
method: 'PUT',
body: JSON.stringify(body),
Expand Down Expand Up @@ -600,12 +600,19 @@ export const api = {
* @param name The environment variable name of the key.
* @param hosts The hosts for which the egress proxy swaps in the key.
* @param secret The key. Without it, the orchestrator keeps the stored key.
* @returns The name, the hosts and the last four characters of the key.
* @param upstreamCa The upstream CA for all hosts as PEM, an empty string to remove the upstream CA of the hosts,
* or undefined to keep the upstream CAs of the hosts.
* @returns The name, the hosts, the last four characters and the upstream CA of the key, and the flag for hosts
* with different upstream CAs.
*/
putApiKey: (name: string, hosts: string[], secret?: string) =>
putApiKey: (name: string, hosts: string[], secret?: string, upstreamCa?: string) =>
request<ApiKeySummary>(`/api/api-keys/${encodeURIComponent(name)}`, {
method: 'PUT',
body: JSON.stringify({ hosts, ...(secret ? { secret } : {}) }),
body: JSON.stringify({
hosts,
...(secret ? { secret } : {}),
...(upstreamCa !== undefined ? { upstreamCa } : {}),
}),
}),
/**
* Removes an API key.
Expand Down
56 changes: 45 additions & 11 deletions dashboard/src/components/McpServers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import type {
AgentMcpAuth,
AgentMcpHeader,
AgentMcpServer,
AgentMcpServerBody,
AgentMcpServerState,
McpConnectBody,
} from '../../../shared/types.ts';
Expand All @@ -38,20 +39,30 @@ const TOKEN_STATUS = {
} as const;

/**
* Checks if a text is an http or https URL.
* Gives the scheme of a URL.
*
* @param raw The URL as typed.
* @returns True for an http or https URL.
* @returns The scheme with its colon, or null when the text is not a URL.
*/
function validUrl(raw: string): boolean {
function schemeOf(raw: string): string | null {
try {
const url = new URL(raw.trim());
return url.protocol === 'https:' || url.protocol === 'http:';
return new URL(raw.trim()).protocol;
} catch {
return false;
return null;
}
}

/**
* Checks if a text is an http or https URL.
*
* @param raw The URL as typed.
* @returns True for an http or https URL.
*/
function validUrl(raw: string): boolean {
const scheme = schemeOf(raw);
return scheme === 'https:' || scheme === 'http:';
}

/**
* The list of MCP servers, with its own add button.
*
Expand Down Expand Up @@ -148,7 +159,8 @@ export function McpSection({
*
* The name, the URL and the auth mode are fixed once the server exists. A
* secret field of a stored server starts empty, and an empty field keeps the
* stored secret.
* stored secret. The upstream CA field starts with the upstream CA of the host,
* and a save sets the upstream CA of the host to the content of the field.
*
* @param server The server to edit, or null for a new server.
* @param busy True while a save runs, which disables the buttons.
Expand All @@ -170,9 +182,9 @@ export function McpDialog({
busy: boolean;
error: string | null;
onCancel: () => void;
onSave: (body: AgentMcpServer) => void;
onSave: (body: AgentMcpServerBody) => void;
onConnect: (
body: AgentMcpServer,
body: AgentMcpServerBody,
client: Omit<McpConnectBody, 'origin'>,
) => Promise<string | null>;
}) {
Expand All @@ -189,6 +201,8 @@ export function McpDialog({
const [redirectUri, setRedirectUri] = useState<string | null>(null);
const [clientId, setClientId] = useState('');
const [clientSecret, setClientSecret] = useState('');
const [upstreamCa, setUpstreamCa] = useState(server?.upstreamCa ?? '');
const https = schemeOf(url) === 'https:';

/**
* Checks if the header of a row has a stored secret, so an empty value keeps the secret.
Expand All @@ -206,7 +220,7 @@ export function McpDialog({
};

/** The server that a save sends. */
const body: AgentMcpServer = {
const body: AgentMcpServerBody = {
name: name.trim(),
url: url.trim(),
auth,
Expand All @@ -222,6 +236,7 @@ export function McpDialog({
: auth === 'headers'
? headers.filter((h) => h.name.trim() !== '' || h.value !== '')
: [],
...(https ? { upstreamCa } : {}),
};

/**
Expand Down Expand Up @@ -392,6 +407,25 @@ export function McpDialog({
</div>
) : null}

{https ? (
<div className="flex flex-col gap-2">
<Label htmlFor="mcp-upstream-ca">Upstream CA (optional)</Label>
<Textarea
id="mcp-upstream-ca"
className="max-h-40 font-mono text-xs md:text-xs"
placeholder="-----BEGIN CERTIFICATE-----"
value={upstreamCa}
onChange={(e) => setUpstreamCa(e.target.value)}
/>
<p className="text-xs text-muted-foreground">
The certificate of a private certificate authority, as PEM. The egress proxy and the
OAuth login trust it for the host of the server, in addition to the public
authorities. The host shares it with your API keys and MCP servers for the same
host.
</p>
</div>
) : null}

{auth === 'oauth' ? (
<div className="flex flex-col gap-2">
<span className="text-sm font-medium">OAuth</span>
Expand Down
43 changes: 37 additions & 6 deletions dashboard/src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Button } from '@/components/ui/button';
import { Card } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { useUp } from '@/hooks/use-up';
import { CODEX_LOGIN_OFFERED } from '@/lib/harness';
import { shortAge } from '@/lib/rough';
Expand Down Expand Up @@ -246,7 +247,9 @@ export function Settings() {
<ApiKeys
stored={apiKeys}
busy={busy}
onSave={(name, hosts, secret) => act(() => api.putApiKey(name, hosts, secret))}
onSave={(name, hosts, secret, upstreamCa) =>
act(() => api.putApiKey(name, hosts, secret, upstreamCa))
}
onRemove={(name) => act(() => api.deleteApiKey(name))}
/>
) : null}
Expand Down Expand Up @@ -462,7 +465,8 @@ function account(stored: CredentialSummary): string {
*
* @param stored The stored API keys.
* @param busy True while a change runs, which disables the buttons.
* @param onSave Stores a key. An empty secret keeps the stored key. Resolves to true when that succeeded.
* @param onSave Stores a key. An empty secret keeps the stored key, and an empty upstream CA removes the upstream CA
* of the hosts. Resolves to true when that succeeded.
* @param onRemove Removes a key. Resolves to true when that succeeded.
*/
function ApiKeys({
Expand All @@ -473,15 +477,16 @@ function ApiKeys({
}: {
stored: ApiKeySummary[];
busy: boolean;
onSave: (name: string, hosts: string[], secret: string) => Promise<boolean>;
onSave: (name: string, hosts: string[], secret: string, upstreamCa: string) => Promise<boolean>;
onRemove: (name: string) => Promise<boolean>;
}) {
const [name, setName] = useState('');
const [hosts, setHosts] = useState('');
const [secret, setSecret] = useState('');
const [upstreamCa, setUpstreamCa] = useState('');
const [confirmRemove, setConfirmRemove] = useState<string | null>(null);
// A stored key can keep its secret while its hosts change.
const existing = stored.some((key) => key.name === name.trim());
const existing = stored.find((key) => key.name === name.trim());
const ready = name.trim() !== '' && hosts.trim() !== '' && (existing || secret.trim() !== '');

/** Saves the key in the form, and clears the form on success. */
Expand All @@ -492,9 +497,10 @@ function ApiKeys({
const typed = secret.trim();
setSecret('');
const list = hosts.split(/[\s,]+/).filter((h) => h !== '');
if (await onSave(name.trim(), list, typed)) {
if (await onSave(name.trim(), list, typed, upstreamCa)) {
setName('');
setHosts('');
setUpstreamCa('');
}
};

Expand Down Expand Up @@ -529,6 +535,7 @@ function ApiKeys({
onClick={() => {
setName(key.name);
setHosts(key.hosts.join(', '));
setUpstreamCa(key.upstreamCa ?? '');
}}
>
Edit
Expand All @@ -546,7 +553,11 @@ function ApiKeys({
</Button>
</div>
<p className="text-muted-foreground">
{[key.hosts.join(', '), key.account ? `ends ${key.account}` : 'stored'].join(' · ')}
{[
key.hosts.join(', '),
key.account ? `ends ${key.account}` : 'stored',
...(key.upstreamCa ? ['upstream CA'] : []),
].join(' · ')}
</p>
</div>
))}
Expand Down Expand Up @@ -577,6 +588,26 @@ function ApiKeys({
value={secret}
onChange={(e) => setSecret(e.target.value)}
/>
<Label htmlFor="api-key-upstream-ca">Upstream CA (optional)</Label>
<Textarea
id="api-key-upstream-ca"
className="max-h-40 font-mono text-xs md:text-xs"
placeholder="-----BEGIN CERTIFICATE-----"
value={upstreamCa}
onChange={(e) => setUpstreamCa(e.target.value)}
/>
<p className="text-xs text-muted-foreground">
The certificate of a private certificate authority, as PEM. The egress proxy trusts it for
the hosts of the key, in addition to the public authorities. Each host has one upstream
CA, which your keys and MCP servers for the host share. A save sets it for all hosts of
the key, and an empty field removes it.
</p>
{existing?.mixedUpstreamCas ? (
<Notice className="rounded-md border px-3 py-2">
The hosts of this key have different upstream CAs. A save with an empty field removes
them.
</Notice>
) : null}
<div className="flex justify-end">
<Button type="submit" disabled={busy || !ready}>
{existing ? 'Save key' : 'Add key'}
Expand Down
3 changes: 3 additions & 0 deletions doc/agent-sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ into `https` requests. An MCP server can have a private address. An authorizatio
unless it is on the host of the MCP server. The URL must not name a loopback, link-local or reserved address. The
[egress proxy](egress.md) always allows the host and the port of an MCP server.

An MCP server with `https` can have an [upstream CA](credentials.md#other-api-keys), which the egress proxy and the
OAuth login trust for the host of the MCP server.

An MCP server uses a bearer token, custom headers, an OAuth login, or no authentication. An MCP server has at most 20
custom headers, and a header value can have at most 4096 characters. A header value is literal or secret, and an
`Authorization` header must be secret. The orchestrator stores a bearer token and each secret value with the MCP
Expand Down
17 changes: 15 additions & 2 deletions doc/credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ periodically.

### Other API keys

You can add API keys for other services, for example OpenRouter. Each key has three fields:
You can add API keys for other services, for example OpenRouter. Each key has three fields and an optional upstream
CA:

- **Environment variable**: the name of the variable that holds the placeholder in each box, for example
`OPENROUTER_API_KEY`. The orchestrator refuses a name that Boxes or the box image sets itself, e.g., `GH_TOKEN` or
Expand All @@ -85,6 +86,14 @@ You can add API keys for other services, for example OpenRouter. Each key has th
with `*.`. The name `*.example.com` includes `api.example.com`, but it does not include `example.com` or
`a.b.example.com`, and a host can end in a port, as in an [egress profile](egress-profiles.md#modes-and-hosts).
- **Key**: the secret. To change only the hosts, leave it empty.
- **Upstream CA**: the certificate of a private certificate authority, as PEM, for a host with a certificate from
that authority, e.g., a Kubernetes API server. The [egress proxy](egress.md#upstream-cas) trusts it for the hosts of
the key.

A host has one upstream CA. The API keys and [MCP servers](agent-sets.md#mcp-servers) of a user share the upstream CA
of each host they name. A save sets the upstream CA of all hosts of the key to the content of the field, and an empty
field removes it. A key shows the upstream CA only when all its hosts have the same one. The orchestrator removes the
upstream CA of a host together with the last API key or MCP server of the user that names the host.

The placeholder has the same prefix and the same length as the key, so a client that checks the format of its key
accepts the placeholder. The prefix is the start of the key up to and including the last `-` or `_`, but each part
Expand Down Expand Up @@ -131,7 +140,11 @@ characters, or to nothing when the secret is that short — the API never shows
(`orchestrator/src/log.ts`) redacts fields whose name or value looks credential-shaped before they reach stderr.

The `api_keys` table holds one row for each of the other API keys, with the variable name, the hosts, the key and the
placeholder. The API returns only the name, the hosts and the last four characters of the key.
placeholder. The API returns only the name, the hosts, the upstream CA and the last four characters of the key.

The `upstream_cas` table (`orchestrator/src/upstream-cas.ts`) holds one row for each user and host pattern, with the
certificates as PEM. The host pattern is the host of the API key as entered, or the host and the port of the MCP
server. The patterns `mcp.internal` and `mcp.internal:443` are two rows.

### Refresh and delivery

Expand Down
Loading
Loading