From b300df01b34d8a114fa81f4a62e3792d754c795c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 9 Nov 2026 12:55:52 +0000 Subject: [PATCH 1/2] Trust a private CA for the hosts of API keys and MCP servers The egress proxy checked the certificate of an intercepted host against the public CAs only. A credential for a host with a certificate from a private CA, such as a Kubernetes API server or an MCP server with its own CA, failed with a TLS error. An API key and an MCP server now take an optional upstream CA. The orchestrator stores one CA for each user and host pattern, so all API keys and MCP servers of a user for a host share it. It removes a CA when no API key and no MCP server of the user names the host. The proxy trusts the CA in addition to the public CAs, and only in requests from the boxes of the user. It intercepts a host with an upstream CA also when no credential belongs to the host, so an MCP server without authentication can use the CA too. The OAuth login of an MCP server trusts the CA for the host of the server. --- dashboard/src/api.ts | 21 ++- dashboard/src/components/McpServers.tsx | 56 ++++++-- dashboard/src/views/Settings.tsx | 43 +++++- orchestrator/src/agents.test.ts | 12 +- orchestrator/src/agents.ts | 38 ++++- orchestrator/src/api-keys.test.ts | 87 ++++++++++- orchestrator/src/api-keys.ts | 19 ++- orchestrator/src/app.test.ts | 1 + orchestrator/src/app.ts | 14 +- orchestrator/src/bodies.ts | 6 +- orchestrator/src/db.ts | 11 ++ orchestrator/src/egress.test.ts | 21 +++ orchestrator/src/egress.ts | 25 +++- orchestrator/src/mcp-oauth.test.ts | 25 ++++ orchestrator/src/mcp-oauth.ts | 118 +++++++++------ orchestrator/src/upstream-cas.test.ts | 138 ++++++++++++++++++ orchestrator/src/upstream-cas.ts | 184 ++++++++++++++++++++++++ proxy/src/forward.test.ts | 40 ++++++ proxy/src/forward.ts | 30 +++- proxy/src/inject.test.ts | 158 ++++++++++++++++++-- proxy/src/inject.ts | 122 +++++++++++----- proxy/src/main.ts | 10 +- proxy/src/policy.test.ts | 67 +++++++++ proxy/src/policy.ts | 70 +++++++-- shared/types.ts | 28 ++++ 25 files changed, 1201 insertions(+), 143 deletions(-) create mode 100644 orchestrator/src/upstream-cas.test.ts create mode 100644 orchestrator/src/upstream-cas.ts diff --git a/dashboard/src/api.ts b/dashboard/src/api.ts index 48259c21..624b1d7c 100644 --- a/dashboard/src/api.ts +++ b/dashboard/src/api.ts @@ -1,7 +1,7 @@ import type { AgentBundlePreview, AgentItemBody, - AgentMcpServer, + AgentMcpServerBody, AgentRepoBody, AgentSetDetail, AgentSetSummary, @@ -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(`/api/agent-sets/${setId}/mcp-servers`, { method: 'PUT', body: JSON.stringify(body), @@ -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(`/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. diff --git a/dashboard/src/components/McpServers.tsx b/dashboard/src/components/McpServers.tsx index 86a4c5d3..fd6e26cf 100644 --- a/dashboard/src/components/McpServers.tsx +++ b/dashboard/src/components/McpServers.tsx @@ -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'; @@ -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. * @@ -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. @@ -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, ) => Promise; }) { @@ -189,6 +201,8 @@ export function McpDialog({ const [redirectUri, setRedirectUri] = useState(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. @@ -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, @@ -222,6 +236,7 @@ export function McpDialog({ : auth === 'headers' ? headers.filter((h) => h.name.trim() !== '' || h.value !== '') : [], + ...(https ? { upstreamCa } : {}), }; /** @@ -392,6 +407,25 @@ export function McpDialog({ ) : null} + {https ? ( +
+ +