trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

bug: extraCACerts doesn't work

Open alexanderniebuhr opened this issue 1 month ago • 1 comments

Provide environment information

System: OS: macOS 27.2 CPU: (10) arm64 Apple M1 Max Memory: 1.37 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.22.3 - /Users/alexanderniebuhr/.local/bin/node npm: 10.9.8 - /Users/alexanderniebuhr/.local/bin/npm pnpm: 10.33.0 - /Users/alexanderniebuhr/.local/share/mise/installs/pnpm/10.33.0/pnpm bun: 1.3.14 - /Users/alexanderniebuhr/.bun/bin/bun

Describe the bug

extraCACerts in trigger.config.ts has no effect since the v3 build system: packages/cli-v3/src/commands/deploy.ts never passes resolvedConfig.extraCACerts to buildImage(), so the generated Containerfile sets NODE_EXTRA_CA_CERTS= (empty) and Node ignores the CA bundle at runtime.

Reproduction repo

To reproduce

Suggested fix

No response

Additional information

No response

alexanderniebuhr avatar Oct 14 '26 13:10 alexanderniebuhr

Thanks for the report, you're right. deploy never passes extraCACerts to the image build, so NODE_EXTRA_CA_CERTS ends up as an empty string in the image, and the cert file isn't copied in either. Setting NODE_EXTRA_CA_CERTS in the dashboard won't help, because the empty value from the image wins. We'll get it fixed.

Until the fix ships, this should work around it by loading the CA in code. Add the PEM contents as an environment variable (e.g. EXTRA_CA_CERT) in the dashboard, then create init.ts at the root of your trigger directory, which runs before your tasks:

// trigger/init.ts (default `node` runtime, Node 24)
import tls from "node:tls";

const extraCa = process.env.EXTRA_CA_CERT;
if (extraCa && typeof tls.setDefaultCACertificates === "function") {
  tls.setDefaultCACertificates([...tls.getCACertificates("default"), extraCa]);
}

This covers both fetch and node:https (and clients built on them). Note that if init.ts throws, your runs will fail to start, so keep the guard in.

If you're on the node-22 runtime, tls.setDefaultCACertificates isn't available, so set the agents directly instead (this needs undici as a dependency):

// trigger/init.ts (node-22 runtime)
import https from "node:https";
import tls from "node:tls";
import { Agent, setGlobalDispatcher } from "undici";

const extraCa = process.env.EXTRA_CA_CERT;
if (extraCa) {
  const ca = [...tls.rootCertificates, extraCa];
  https.globalAgent.options.ca = ca;
  setGlobalDispatcher(new Agent({ connect: { ca } }));
}

If your HTTP client creates its own agent with an explicit ca option, pass the cert there too. Let us know if this doesn't work for you.

isshaddad avatar Oct 14 '26 13:10 isshaddad