Repository navigation
feat(core): present a provider's client certificate on model requests #61832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2f01c88
feat(core): present a configured client certificate on model requests
rekram1-node f4fc5cb
fix(core): resolve client certificate paths like other config paths a…
rekram1-node 97930bf
refactor(core): move the client certificate to provider settings.tls
rekram1-node 5fa44f6
fix(core): present the client certificate on every model request of t…
rekram1-node c599447
fix(ai): attach the client certificate where provider requests are se…
rekram1-node a213ef5
fix(core): present client certificates on both the Bun and Node runtimes
rekram1-node 4aa73c5
Merge dev into client-certs
rekram1-node File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Sender, Tls } from "./client-tls.js" | ||
|
|
||
| // Bun's fetch takes the client certificate per request. | ||
| export function sender(tls: Tls): Sender | undefined { | ||
| return { fetch: globalThis.fetch, init: { tls } } | ||
| } | ||
|
|
||
| export * as ClientTls from "./client-tls.bun.js" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // The deep path keeps Vite, which runs under Bun where "undici" is a built-in, from leaving the import external. | ||
| import { Agent, fetch } from "undici/index.js" | ||
| import type { Sender, Tls } from "./client-tls.js" | ||
|
|
||
| // Node's fetch only takes a client certificate through an undici dispatcher, and a dispatcher from the npm package | ||
| // only works with that package's own fetch, not Node's bundled one. One agent per certificate keeps its connections. | ||
| const agents = new Map<string, Agent>() | ||
|
|
||
| export function sender(tls: Tls): Sender | undefined { | ||
| const id = JSON.stringify([tls.cert, tls.key, tls.passphrase]) | ||
| const agent = agents.get(id) ?? new Agent({ connect: { cert: tls.cert, key: tls.key, passphrase: tls.passphrase } }) | ||
| agents.set(id, agent) | ||
| // SAFETY: undici's fetch implements the WHATWG fetch contract that FetchHttpClient and the AI SDK call. | ||
| return { fetch: fetch as unknown as typeof globalThis.fetch, init: { dispatcher: agent } } | ||
| } | ||
|
|
||
| export * as ClientTls from "./client-tls.node.js" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** PEM client certificate and private key, with the passphrase of an encrypted key. */ | ||
| export interface Tls { | ||
| readonly cert: string | ||
| readonly key: string | ||
| readonly passphrase?: string | ||
| } | ||
|
|
||
| /** The `fetch` and request options that present a client certificate on this runtime. */ | ||
| export interface Sender { | ||
| readonly fetch: typeof globalThis.fetch | ||
| readonly init: Record<string, unknown> | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Sender, Tls } from "./client-tls.js" | ||
|
|
||
| // Workers' fetch can't present a client certificate. Embedders use an mTLS certificate binding's fetch instead. | ||
| export function sender(_tls: Tls): Sender | undefined { | ||
| return undefined | ||
| } | ||
|
|
||
| export * as ClientTls from "./client-tls.workerd.js" |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Dropping
tlswhencertorkeyis empty (or when the object fails to decode, e.g. nokey) turns a config mistake into a confusing network failure. Withcert: "{file:./missing.pem}"I got onlyECONNRESET: The socket connection was closed unexpectedly…, retried over and over; the real cause is just a warning in the log. Someone who settlsclearly wants a certificate presented. Could an invalid or emptytlsfail the model request with a clear, non-retryable error namingsettings.tlsinstead of being silently ignored?