Skip to content

feat(mcp): accept client secrets from bounded files - #2188

Merged
jhrozek merged 1 commit into
mainfrom
ext-broker-01-secret-hardening
Oct 8, 2026
Merged

jhrozek merged 1 commit into
mainfrom
ext-broker-01-secret-hardening

Conversation

@jhrozek

@jhrozek jhrozek commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Preregistered OAuth MCP clients can take their client secret from
secret_file as well as secret_env. secret_file must be an absolute path to
a regular file of at most 64 KiB; surrounding whitespace is trimmed. The
two sources are mutually exclusive, exactly one is required, and both
work in direct and broker mode. Existing secret_env configs, including
those rendered by the Helm chart, are unchanged.

This lets operators deliver the secret as a mounted Kubernetes Secret or
a CSI/Vault-agent file, and adds the ClientSecretFile plumbing the
standalone broker builds on.

Broker mode passes whichever source is set to ToolHive as
ClientSecretFile or ClientSecretEnvVar and leaves the token-endpoint auth
method at ToolHive's default. A configured secret file is checked at
startup; ToolHive reads it when the upstream is built, so rotating it
still requires a restart.

A shared mcpsecretfile reader opens without blocking, rejects non-regular
files, enforces the size limit, and returns errors that never contain the
secret. Direct mode includes that reason in its profile error.

The injected Compile path resolves file or environment secrets.
WithOAuthSecretFileReader replaces WithOAuthSecretResolver and overrides
only file reads; environment secrets use os.LookupEnv as before. That path
now validates OAuth endpoints with the new ValidateProtectedURL, which is
stricter than the inline check it replaces: it also rejects query
strings, encoded paths, out-of-range ports, non-canonical IPv6 hosts, and
hostname characters outside letters, digits and hyphens. Production
brokers build through ToolHive and do not use this path.

The configuration reference and the MCP OAuth user guide document
secret_file, including that agent shell commands running as the same
user can read a known secret file path.

Co-Authored-By: mecatl [email protected]

Preregistered OAuth MCP clients can take their client secret from
secret_file as well as secret_env. secret_file must be an absolute path to
a regular file of at most 64 KiB; surrounding whitespace is trimmed. The
two sources are mutually exclusive, exactly one is required, and both
work in direct and broker mode. Existing secret_env configs, including
those rendered by the Helm chart, are unchanged.

This lets operators deliver the secret as a mounted Kubernetes Secret or
a CSI/Vault-agent file, and adds the ClientSecretFile plumbing the
standalone broker builds on.

Broker mode passes whichever source is set to ToolHive as
ClientSecretFile or ClientSecretEnvVar and leaves the token-endpoint auth
method at ToolHive's default. A configured secret file is checked at
startup; ToolHive reads it when the upstream is built, so rotating it
still requires a restart.

A shared mcpsecretfile reader opens without blocking, rejects non-regular
files, enforces the size limit, and returns errors that never contain the
secret. Direct mode includes that reason in its profile error.

The injected Compile path resolves file or environment secrets.
WithOAuthSecretFileReader replaces WithOAuthSecretResolver and overrides
only file reads; environment secrets use os.LookupEnv as before. That path
now validates OAuth endpoints with the new ValidateProtectedURL, which is
stricter than the inline check it replaces: it also rejects query
strings, encoded paths, out-of-range ports, non-canonical IPv6 hosts, and
hostname characters outside letters, digits and hyphens. Production
brokers build through ToolHive and do not use this path.

The configuration reference and the MCP OAuth user guide document
secret_file, including that agent shell commands running as the same
user can read a known secret file path.

Co-Authored-By: mecatl <[email protected]>
@jhrozek
jhrozek merged commit 024ba88 into main Oct 8, 2026
40 checks passed
@jhrozek
jhrozek deleted the ext-broker-01-secret-hardening branch October 8, 2026 15:12
This was referenced Oct 13, 2026

This branch was successfully deployed

1 active deployment
Preview — 2b5faf8f Deployed Oct 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant