Track Bun custom CA support for HTTPS OTLP export to Aspire Dashboard
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Summary
`AddBunApp` wires Aspire certificate trust for Bun by setting `NODE_EXTRA_CA_CERTS` for append-scope trust and `NODE_OPTIONS=--use-openssl-ca` for override/system-scope trust. That environment wiring is covered by unit tests and shows up in `aspire describe`, but a full HTTPS OTLP export from a Bun app to the Aspire Dashboard currently fails because Bun does not accept the Aspire-injected development certificate as a custom trust anchor.
## Repro
Using `playground/AspireWithBun` and a locally built Aspire CLI:
1. Start the app with isolated ports:
```bash
aspire start --isolated --non-interactive --format Json --apphost apphost.mts
```
2. Inspect the Bun resource environment:
```text
OTEL_EXPORTER_OTLP_ENDPOINT=https://localhost:
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=x-otlp-api-key=
NODE_EXTRA_CA_CERTS=/tmp/.../bunapp-.../cert.pem
SSL_CERT_DIR=/tmp/.../bunapp-.../certs
```
3. Send an HTTPS request to the Dashboard OTLP endpoint using the injected cert.
Works with curl:
```bash
curl --cacert "$NODE_EXTRA_CA_CERTS" \
-H "x-otlp-api-key: " \
-H "content-type: application/json" \
--data-binary @trace.json \
"$OTEL_EXPORTER_OTLP_ENDPOINT/v1/traces"
```
Result: HTTP 200 and the span appears in `aspire otel spans`.
Works with Node:
```bash
NODE_EXTRA_CA_CERTS="$NODE_EXTRA_CA_CERTS" node fetch-otlp.js
```
Result: HTTP 200.
Fails with Bun 1.3.10 and Bun 1.3.14:
```bash
NODE_EXTRA_CA_CERTS="$NODE_EXTRA_CA_CERTS" bun fetch-otlp.ts
```
Result:
```text
UNABLE_TO_VERIFY_LEAF_SIGNATURE
```
Also failed with:
```text
NODE_USE_SYSTEM_CA=1
SSL_CERT_FILE=
SSL_CERT_DIR=
bun --use-system-ca
bun --use-openssl-ca
node:https.Agent({ ca: readFileSync(cert) }) in Bun
```
## Certificate details
The Aspire-injected cert is a self-signed localhost development certificate. It has `Basic Constraints: CA:FALSE` and includes SAN entries for `localhost`, loopback IPs, and dev hostnames.
`curl --cacert` and Node accept it as an explicit trust anchor. Bun currently rejects it with `UNABLE_TO_VERIFY_LEAF_SIGNATURE`.
## Related Bun issues
- https://github.com/oven-sh/bun/issues/24581 - `NODE_EXTRA_CA_CERTS not working in recent versions`
- https://github.com/oven-sh/bun/issues/21643 - `node:https Agent doesn't seem to be sending specified certificate properly. error UNABLE_TO_VERIFY_LEAF_SIGNATURE`
- https://github.com/oven-sh/bun/issues/17325 - `Limitations of bun operation in corporate networks: self-signed CA`
## Impact
Until this is fixed in Bun or Aspire has a safe workaround, we can verify only the Aspire-side TLS wiring for Bun (`NODE_EXTRA_CA_CERTS`/`NODE_OPTIONS`) and Dashboard HTTPS ingestion with curl/Node. We cannot add a reliable Bun-to-Dashboard HTTPS OTLP E2E test that validates Bun's custom CA behavior without disabling TLS verification.
## Acceptance criteria
- Identify a safe Bun-supported way to trust Aspire's injected development certificate for outgoing HTTPS requests.
- Add or update an E2E test/playground scenario where a Bun app exports OTLP spans to the Aspire Dashboard over HTTPS and `aspire otel spans` shows the spans.
- Do not use `NODE_TLS_REJECT_UNAUTHORIZED=0` or equivalent insecure TLS bypasses as the default path.
Follow-up from PR #17416.
Contributor guide
Assessment
This issue has not been assessed yet.