Repository navigation
feat(mcp): accept client secrets from bounded files - #2188
Merged
Merged
Conversation
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]>
This was referenced Oct 13, 2026
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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]