GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(core): present client certificates for mutual TLS by rekram1-node · Pull Request #60289 · anomalyco/opencode

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 29, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • New feature

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.

All reactions
adamdotdevin and others added 5 commits October 29, 2026 11:42
@adamdotdevin @rekram1-node
feat(core): present client certificates for mutual TLS
a338e07
@adamdotdevin @rekram1-node
fix(core): keep the key passphrase out of config and validate certifi…
383094c
…cate hosts
@adamdotdevin @rekram1-node
fix(core): canonicalize IPv6 certificate hosts and keep passphrase wh…
89e425b
…itespace
@adamdotdevin @rekram1-node
fix(core): present client certificates only on model requests and nev…
3870c24
…er to an HTTPS proxy
@rekram1-node @adamdotdevin
fix(core): read client certificate files without Bun globals
17a120a
Co-authored-by: Adam <[email protected]>
@github-actions github-actions Bot added the contributor label Oct 29, 2026
opencodejr[bot]
opencodejr Bot reviewed Oct 29, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@rekram1-node
fix(core): use the last matching client certificate rule, like permis…
c22299c
…sions
opencodejr[bot]
opencodejr Bot reviewed Oct 29, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
rekram1-node added 2 commits October 29, 2026 16:14
@rekram1-node
test(core): keep the HTTPS proxy set on Windows in the client certifi…
bf7cf3e
…cate test
@rekram1-node
test(core): format client certificate test
6db9577
opencodejr[bot]
opencodejr Bot reviewed Oct 29, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@rekram1-node rekram1-node mentioned this pull request Oct 29, 2026
feat(core): present client certificates for mutual TLS #60259
Closed
4 of 6 tasks
@adamdotdevin
refactor(core): read client certificates from Config and ignore them …
bb05d2e
…in project files
opencodejr[bot]
opencodejr Bot reviewed Oct 30, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@k-x7

k-x7 commented Nov 5, 2026

Copy link
Copy Markdown

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node

rekram1-node commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of #61832, a simpler single-certificate version (network.client_certificate) that follows normal config layering.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node rekram1-node closed this Nov 8, 2026
@github-actions github-actions Bot mentioned this pull request Nov 8, 2026
📊 AI CLI 工具社区动态日报 2026-11-08 96loveslife/big_model_radar#762
Open
@k-x7 k-x7 mentioned this pull request Nov 8, 2026
feat(core): present a provider's client certificate on model requests #61832
Merged
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

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.

3 participants

@rekram1-node @k-x7 @adamdotdevin
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.