Skip to main content
kRouter
All posts
How kRouter works

x509: certificate signed by unknown authority, and the Go trust-store trap

Antigravity's Go agent rejected our root CA while three Node apps accepted it. The cause was one environment variable from an unrelated Python install. For months it looked exactly like certificate pinning.

Kodelyth · The team behind kRouter
15 min read

For months, kRouter's own source code contained this claim about Antigravity's agent binary:

builds its own root pool ... and reads no TLS, CA or proxy environment variables, so it rejects the kRouter CA however the machine is configured

Every word of it was wrong. The binary reads SSL_CERT_FILE like any other Go program. What made the claim survive so long is that it predicted the symptoms perfectly, and the real cause was a single line in a shell profile, put there by a Python tutorial years earlier.

If you are here because something prints x509: certificate signed by unknown authority at you while your certificate is demonstrably installed and trusted, the short version is at the bottom. The longer version is worth reading, because the failure mode generalises to any Go binary on any machine.

The symptom

kRouter's MITM mode routes four apps that have no base-URL setting: Claude Desktop, Antigravity, GitHub Copilot and Kiro IDE. It points their hostnames at 127.0.0.1, answers on port 443 with a certificate signed by a local root CA, and forwards the chat requests wherever you mapped them.

Three of those four worked. Antigravity did not. Every call it made died the same way:

tls: failed to verify certificate: x509: certificate signed by unknown authority

Which should have been impossible, because everything upstream of it checked out:

# The CA is in the System keychain, and macOS agrees it is valid for TLS
$ security verify-cert -p ssl -c ~/.krouter/mitm/rootCA.crt
...certificate verification successful
 
# The hostnames resolve to us
$ grep cloudcode-pa /etc/hosts
127.0.0.1 daily-cloudcode-pa.googleapis.com
127.0.0.1 cloudcode-pa.googleapis.com
 
# And curl, which uses the system store, is perfectly happy
$ curl -sS -o /dev/null -w '%{http_code}\n' https://cloudcode-pa.googleapis.com/
200

System trust store: certificate present and valid. DNS: redirected. curl: satisfied. One application: refusing.

Why the wrong answer was so convincing

Antigravity's agent is ~/.gemini/bin/agy — a Go binary, around 200 MB, built with go1.28 and boringcrypto. Three facts pointed the same direction.

It was the only failing app. The other three are Node or Electron. Node ignores the OS trust store and reads its own bundled Mozilla root list, which is why kRouter sets NODE_EXTRA_CA_CERTS for them. They were already handled, and they worked. One tool out of four failing reads as that tool is special, not as that tool is subject to something the others are immune to.

A string scan of the binary came back empty. Searching it for HTTPS_PROXY, HTTP_PROXY, ALL_PROXY, ProxyFromEnvironment, SSL_CERT_FILE, SSL_CERT_DIR and GODEBUG found nothing useful. That was taken as evidence the binary consults no environment at all.

It is not evidence of that. A negative result from a string search over a stripped 200 MB binary is not proof of absence. Go's certificate loading lives in the standard library — crypto/x509/root_unix.go — and whether those literals survive into a particular build, and whether a given scan finds them, tells you nothing reliable about runtime behaviour. The authoritative test for "does this program read that variable" is to set the variable and watch what the program does. Nobody ran that test, because the first two facts had already made the answer obvious.

And the error message is the same for both causes. A genuinely pinned certificate and an unknown CA produce identical output. There is no distinguishing signal in the thing you are actually looking at.

So the conclusion got written into a source comment as settled fact, and from then on it was something the codebase knew. Every subsequent session read that comment and routed around the problem instead of at it.

What is actually going on

Two environment variables, and one word of difference between them.

NODE_EXTRA_CA_CERTS   ADDS this file to whatever pool is in effect
SSL_CERT_FILE         REPLACES the pool with this file

NODE_EXTRA_CA_CERTS is additive. Point it at your root CA and the runtime trusts whatever it already trusted, plus your CA. This is the behaviour almost everyone assumes they are getting from both variables, because it is the behaviour of the one most people meet first.

SSL_CERT_FILE does the opposite. Go's crypto/x509 loads that file as the complete root pool: the system store is not consulted, it is not merged, and as far as that process is concerned the certificates in it do not exist.

That much was the original diagnosis, and it was right about Go. It was wrong to file the variable under Go — see the measurements below.

Now the line that caused it all. From ~/.zshrc, line 15, added during an unrelated Python setup:

export SSL_CERT_FILE=$(python3 -c "import certifi; print(certifi.where())")

That is certifi's bundle: 119 public roots, maintained by the Python packaging ecosystem, and containing no kRouter CA because why would it.

Follow the inheritance. The shell exports it. The IDE, launched from that shell, inherits it. agy, spawned by the IDE, inherits it from the IDE. One Go process ends up with a root pool of 119 certificates that does not include the one certificate it needs — while the System keychain, three feet away, has trusted that certificate the entire time and is never asked.

Nothing was misconfigured. The certificate install was correct. The DNS redirect was correct. The MITM server was correct. A variable set years earlier for a different purpose silently narrowed trust for one runtime, and that runtime happened to be the one app in the set that read it.

It is not only Go any more

This post originally called SSL_CERT_FILE a Go variable, and said the three Node apps were immune because Node reads NODE_EXTRA_CA_CERTS instead. That was true when the incident happened. It is no longer true, and the correction is worth more than the original claim.

Measured on macOS: one HTTPS request to example.com, with SSL_CERT_FILE pointing at a file whose entire contents are the text not a certificate.

Nodewith that junk SSL_CERT_FILE
22.11, 22.21, 24.14ignored — the request succeeds
26.0every TLS request fails, UNABLE_TO_GET_ISSUER_CERT_LOCALLY

The CA-source flags pin down what changed:

runresult
24, --use-openssl-cafails — OpenSSL's default verify paths have always read it
24, --use-system-casucceeds — that path did not read it
26, --use-system-ca (now the default)fails — that path does read it now
26, --use-bundled-casucceeds

Two changes landed together: the system-CA path learned to honour SSL_CERT_FILE, and it became the default. Neither is wrong on its own. Together they mean a variable that used to affect Go programs and nothing else now narrows trust for every modern Node and Electron process on the machine — which is most of a developer's toolchain.

NODE_EXTRA_CA_CERTS still layers on top, and that is the escape hatch: junk SSL_CERT_FILE plus a real bundle in NODE_EXTRA_CA_CERTS succeeds. A bad NODE_EXTRA_CA_CERTS is inert; a bad SSL_CERT_FILE is not. The asymmetry is the whole point.

No introspection API will tell you

With that junk bundle in place and every handshake failing, Node 26 reports:

tls.rootCertificates               145
tls.getCACertificates('default')   148
tls.getCACertificates('system')      3

Healthy numbers, and all of them useless. Those counts describe the lists Node assembled at startup, not the pool OpenSSL actually verifies against. The obvious probe says nothing is wrong.

Which is this post's own lesson, one layer down: the scan of the binary could not have proved what it was taken to prove, and neither can a root count. The only thing that answers "does this process trust that certificate" is making it try.

The proof, in one command

# With the inherited certifi bundle: TLS failure
$ agy models
tls: failed to verify certificate: x509: certificate signed by unknown authority
 
# With a bundle that is the system roots PLUS the kRouter CA: the live model list,
# served through the interceptor
$ SSL_CERT_FILE=~/.krouter/mitm/ssl-cert-file.pem agy models
gemini-3.8-flash-high
gemini-3.8-flash-medium
...

Same binary. Same certificate. Same hosts file. One environment variable. A binary that "reads no TLS, CA or proxy environment variables" changed behaviour based on a TLS CA environment variable.

The fix, and the two rules that fall out of it

Since 0.5.179, starting the MITM server writes ~/.krouter/mitm/ssl-cert-file.pem — the system roots plus the kRouter CA — and points SSL_CERT_FILE at it from your shell profiles. Two details are load-bearing, and both are consequences of replaces rather than adds.

The bundle must be a superset. Never the CA alone.

This is the trap on the other side of the fix. The naive implementation is to write your root CA to a file and point SSL_CERT_FILE at it. Do that and every Go program on the machine — gh, docker, kubectl, terraform, the Go toolchain itself — now trusts your local CA and nothing else, and cannot make an HTTPS request to anywhere on the internet. You would have fixed one tool by breaking every other Go binary the user owns.

Since Node 26 that blast radius includes Node and Electron, which is most of the rest of the toolchain. The superset rule was written for Go and now carries far more weight than it was asked to.

So kRouter assembles system roots first, appends its CA, counts what it has, and refuses to write a bundle that looks implausibly small:

// A real root store is dozens to hundreds of certs. Anything tiny means we
// read the wrong file, and pointing SSL_CERT_FILE at it would break TLS for
// every Go tool on the machine.
const total = countCerts(roots) + countCerts(ca);
if (total < 20) return { ok: false, reason: `implausible-bundle-${total}` };

If the system roots cannot be read, nothing is written and nothing is pointed anywhere. A missing feature is recoverable; a machine-wide trust store of one certificate is a bad afternoon.

The shell block must run last, and merge whatever is already set.

If kRouter exported its bundle at the top of your profile and line 15 exported certifi afterwards, you would be exactly back where you started — because the last writer wins and SSL_CERT_FILE has no concept of merging. So the managed block goes at the end of the file and consumes whatever is currently set:

if [ -n "${SSL_CERT_FILE:-}" ] && [ "${SSL_CERT_FILE}" != "$BUNDLE" ]; then
  # Something else set it. Keep their roots and add ours, rather than
  # silently narrowing the trust they chose.
  cat "${SSL_CERT_FILE}" "$CA" > "$MERGED"
  export SSL_CERT_FILE="$MERGED"
else
  export SSL_CERT_FILE="$BUNDLE"
fi

Your certifi bundle keeps working. So does the interceptor. Nobody has to choose.

On Windows none of this is needed: Go uses the system certificate store there, which certutil -addstore Root has already filled.

One thing the fix cannot do

Environment variables are inherited at process launch. A Go program that is already running keeps the value it started with, forever, no matter what you write to a profile afterwards.

So after starting MITM you need a new shell, and Antigravity needs a full quit and reopen — not a window reload, which keeps the same process tree and the same inherited environment. kRouter prints a warning when it wires the variable for exactly this reason. Ignoring it is the single most common cause of "I did the steps and it still doesn't work."

If you just want to fix your machine

Any Go program failing TLS against a certificate you know is installed:

# 1. Is something hiding your trust store?
echo "$SSL_CERT_FILE"

Empty output means this is not your problem; Go is reading the system store and you should look elsewhere. Any path means that file is your entire root pool for every Go program in that environment.

# 2. Does it contain the CA you need?
grep -c 'BEGIN CERTIFICATE' "$SSL_CERT_FILE"   # how many roots
# 3. Fix it by adding, never replacing
cat "$SSL_CERT_FILE" /path/to/your-ca.crt > ~/.certs/merged.pem
export SSL_CERT_FILE=~/.certs/merged.pem

Then restart the program. Not reload — restart.

The part worth keeping

The engineering lesson is about SSL_CERT_FILE semantics, and it is genuinely useful: one variable that replaces a trust store rather than adding to it, inherited silently down a process tree, and — as of Node 26 — honoured by far more of your toolchain than the one runtime this investigation blamed.

The expensive lesson is different. A plausible explanation got written down as a fact, in a comment, next to the code. After that it stopped being a hypothesis anybody tested. It explained the symptoms, it was consistent with a scan that could not have proved it, and it was wrong — so every session that read it was steered away from the one experiment that would have settled the question in about four seconds.

The symptoms matched. That is the problem with a good wrong answer: matching the symptoms is what it is for.

If you are routing Antigravity through kRouter today, see the MITM interception guide for the four trust mechanisms and what each one covers.

Kodelyth · The team behind kRouter

Published by Kodelyth, the team that builds kRouter. Posts are drafted with AI assistance and reviewed by a person before they go out. kRouter is free and MIT licensed.

Install kRouter