Closed davidstevens37 closed 4 months ago
Same issue for me and it's a blocker.
I got the same issue. My http client with bun can't be authenticated against kube-apiserver's API created by kubeadm due to this. ts-node works.
Blocker for me aswell, would love to adopt Bun but having client cert auth is a hard requirement.
Does anyone know where in the source code to find the relevant parts to possibly initiate a fork / PR ?
This is a big issue for us unfortunately.
What I've been able to gather so far is that underneath the node:https
request()
function is a call to fetch()
, which appears to be a straight reference to JavaScriptCore's fetch()
API. This does not and will not support client-specified certificates for security reasons (as it's not designed for a server-side/local use case like this).
Short of Bun implementing its own version of fetch()
(forking it from JavaScriptCore then), we're left to workarounds.
One workaround is to use a separate proxy process, which is likely what we'll go for, but it's not a good long-term solution.
Question to Bun maintainers: Is it possible to somehow supply a certificate (self-signed or otherwise) to the runtime?
fixed by #11322
Still seeing this issue in the latest 1.1.29
. Anyone else?
@asilvas-godaddy if you're still struggling with this: https://bun.sh/docs/api/fetch#tls
That's what I get for relying on intellisense as documentation 😅
Bun type definitions are incomplete for this.
Here's a wrapper I wrote so I don't have to worry about the bad internal types.
import type { BunFile } from "bun";
type CertFile = string | Buffer | BunFile;
interface FetchRequestInitWithTls extends RequestInit {
tls?: {
rejectUnauthorized?: boolean | undefined;
// If using a linter, safe to ignore rule for `any` here
checkServerIdentity?: any;
ca?: CertFile | CertFile[];
cert?: CertFile | CertFile[];
key?: CertFile | CertFile[];
};
}
/**
* @description Wrapper for bun's `fetch`, which allows to pass TLS options with correct typings.
*
* @param url
* @param init
* @returns {Promise<Response>}
*/
export function fetchWithTls(
url: string | URL | Request,
init?: FetchRequestInitWithTls,
): Promise<Response> {
return fetch(url, init);
}
@gabrieljablonski it isn't a type issue. It's broken for me.
What version of Bun is running?
1.0.9+98f20170a
What platform is your computer?
Darwin 23.0.0 arm64 arm
What steps can reproduce the bug?
When using the
node:https
module, the use of requestOptions.cert andrequestOptions.key
do not present the client certificate to the receiving server.In the example below, the request is made to https://server.cryptomix.com/sercure/, a public service which echos the presented client certificate.
index.js:
What is the expected behavior?
Node.js v19.8.1 Response:
λ node index.js
->What do you see instead?
Bun Response:
λ bun run index.js
->Additional information
No response