GeezerVison is showing github.com — feat(core): present client certificates for mutual TLS by rekram1-node · Pull Request #60289 · anomalyco/opencode
Conversation
rekram1-node
commented
Oct 29, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Builds on #60259 by @adamdotdevin (that branch doesn't allow maintainer edits). His 4 commits are unchanged, with one fix on top.
Type of change
What does this PR do?
Some company gateways require mutual TLS: the client has to present its own certificate, not just check the server's. This lets OpenCode do that.
// ~/.config/opencode/opencode.jsonc, /etc/opencode, or MDM managed preferences
{
"network": {
"client_certificates": [
{
"hosts": ["llm.company.example"],
"cert": "/etc/company/client.pem",
"key": "/etc/company/client.key",
"passphrase_file": "/etc/company/client.pass"
}
]
}
}
Rules work like permissions: an ordered list, */? wildcards, and the last matching rule wins, so put broad patterns first and specific hosts after:
[ { hosts: ["*.company.example"], cert: general.pem },
{ hosts: ["llm.company.example"], cert: special.pem } ]
llm.company.example → both match, last wins → special.pem
api.company.example → first only → general.pem
Which requests present it:
flowchart LR
R[outgoing request] --> M{model request?}
M -- "no: webfetch, skills, MCP" --> P[plain fetch]
M -- yes --> H{https and host in a rule?}
H -- no --> P
H -- yes --> X{https:// proxy applies?}
X -- yes --> F[fail: cert would reach the proxy]
X -- no --> T["read cert, key, passphrase<br/>fetch with tls, redirect: error"]
Loading
Where it can be set (highest wins, the whole list is replaced):
managed preferences (MDM) ✓
system dir (/etc/opencode) ✓
global config ✓
project opencode.json ✗ a repo can't pick the machine's identity
OPENCODE_CONFIG_CONTENT ✗
The fix on top. Reading the files with Bun.file put Bun.file into the packed workerd SDK bundle and failed verify:package. They're now read through FSUtil, still on every request so a rotated cert works without a restart:
+ const tls = yield* Effect.all({
+ cert: fs.readFileString(rule.cert),
+ key: fs.readFileString(rule.key),
+ passphrase: rule.passphraseFile ? fs.readFileString(rule.passphraseFile) : Effect.succeed(undefined),
+ }) // unreadable file -> "Could not read the client certificate for <host>"
fetch(input, {
...init,
- tls: { ...init?.tls, cert: Bun.file(rule.cert), key: Bun.file(rule.key), passphrase: ... },
+ tls: { ...init?.tls, ...tls },
Not covered yet: remote MCP servers, the WebSocket transport, and AI SDK providers that aren't native.
How did you verify your code works?
bun run verify:package in packages/sdk passes. client-certificate.test.ts passes (real mTLS handshake with an encrypted key and passphrase file). bun typecheck and typecheck:tsc pass in packages/core.
Visual
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 72" width="240" height="72" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<style>
.c{animation:go 2.4s ease-in-out infinite}
.k{animation:ok 2.4s ease-in-out infinite;opacity:.35}
@keyframes go{0%,15%{transform:translateX(0)}55%,100%{transform:translateX(96px)}}
@keyframes ok{0%,50%{opacity:.35}65%,100%{opacity:1}}
@media (prefers-reduced-motion:reduce){.c,.k{animation:none}.k{opacity:1}}
</style>
<rect x="16" y="20" width="44" height="32" rx="6" opacity=".6"/>
<path d="M28 44h20M28 36h12" opacity=".6"/>
<path d="M72 36h96" stroke-dasharray="4 6" opacity=".4"/>
<g class="c"><rect x="64" y="28" width="20" height="16" rx="3"/><circle cx="74" cy="36" r="3"/></g>
<g class="k"><rect x="188" y="34" width="28" height="22" rx="4"/><path d="M194 34v-6a8 8 0 0 1 16 0v6"/></g>
</svg>
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #40111
Public API: adds the network.client_certificates config key and Config.Network schemas (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sound to me. Against a local gateway that requires mutual TLS, a model request through the production request path presented the configured certificate and succeeded; without the config, the gateway rejected the handshake. client-certificate.test.ts and the config tests pass, and core, schema and server type-check on the pinned Bun 1.4.4. I couldn't run the full opencode run flow because the dev CLI's server process fails to start in this sandbox on both base and this branch.
Public API: two additions, both backwards compatible. There is a new config key, network.client_certificates (hosts, cert, key, optional passphrase_file; read only from managed, system and global config). The matching Config.Network / Config.Network.ClientCertificate schemas are added to the OpenAPI spec and the generated client types. Nothing is removed or changed.
No blocking concerns: certificates are limited to model requests, the HTTPS-proxy and redirect protections hold, and the workerd build uses ClientCertificate.empty.
Related: #40111
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commit looks good. My earlier review had no open points. When several client_certificates entries match a host, the last one now wins, as with permission rules. The schema description, the docs and a new test case cover this, and the tests and the core type check pass.
Public API: the same addition as before, the network.client_certificates config key, still backwards compatible. The only change is which entry wins when several match, and this key hasn't been released yet, so no existing config relies on the old order.
No concerns.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commits only touch the test. Setting both HTTPS_PROXY and https_proxy stops the HTTPS-proxy case from losing its proxy on Windows, where env names ignore case, and withEnv restores both afterwards. client-certificate.test.ts passes (8/8, Linux). My earlier reviews had no open points, and there are no new concerns.
Public API: nothing new in these commits. The PR as a whole still adds the network.client_certificates config key and its schemas, which is backwards compatible.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commit works. My earlier reviews had no open points. I ran serve from this branch against a local gateway that requires a client certificate. With the rule in the global config, model requests presented the certificate and got a reply. With the rule only in the project's opencode.json, the gateway rejected the connection. client-certificate.test.ts and config.test.ts pass, and core and server type-check.
Public API: the same addition as before, the network.client_certificates config key, still backwards compatible. The schema description now says the key is ignored in project configuration.
One scope change to confirm. The rules used to come only from managed preferences, the system directory and the global config. Now every non-project source counts, including remote well-known org config, OPENCODE_CONFIG_CONTENT and --config files. The docs say so, but the description's table still marks OPENCODE_CONFIG_CONTENT as not used. A remote org config can already point model traffic at any host, so this is probably fine. If it's intended, the table needs updating.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@rekram1-node @adamdotdevin
Nice addition. A related case: a provider endpoint that uses a self-signed cert or one from a private CA. Right now opencode won't trust it unless the cert is installed system-wide or NODE_EXTRA_CA_CERTS is set, which isn't always possible (see #17798).
Could this also take a CA or a cert to trust? Something like:
"network": {
"trusted_certificates": [
{ "hosts": ["llm.example.com"], "cert": "/path/to/cert.pem" }
]
}
It could reuse the same host matching here and just add ca to the tls options passed to fetch (the default CAs plus the file, so public hosts keep working). I can open a PR for it if you're open to it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing in favor of #61832, a simpler single-certificate version (network.client_certificate) that follows normal config layering.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|