Databases and Redis · Decision guide
Your app rejects the Cosmos DB emulator's certificate on localhost:8081
Short answer
An invalid SSL certificate error from the Azure Cosmos DB emulator on https://localhost:8081 means your client does not trust the certificate the container made for itself. Download it from the emulator, then install it where the failing runtime looks: the OS bundle, NODE_EXTRA_CA_CERTS for Node.js 22 to 26, the requests bundle for Python, or cacerts for Java.
The Cosmos DB emulator in a container creates its own TLS certificate. No public certificate authority signed it, so nothing trusts it until you say so. The tricky part is that every runtime keeps its own list of trusted certificates: the operating system, Node.js, Python's requests library and Java's JDK each have a separate one, and trusting the emulator in one does not trust it in the others.
So the fix is always the same two moves: download the emulator's certificate, then add it to the store that the failing program reads. Which store that is depends on what is failing.
Find your case
- If curl itself fails, or you have never imported the certificate on this machineTrust it in the operating system first.
- If curl works now but a Node.js script using @azure/cosmos still failsNode.js does not read the system store by default.
- If the Python SDK fails, often inside a virtual environmentrequests reads a different bundle.
- If a Java client fails against the vNext emulatorThe JDK's cacerts file needs the certificate, and the emulator must run in HTTPS mode.
Tell a host problem from an SDK problem
Make one HTTPS request to the emulator with verification on and one with it off. Any HTTP status code means the TLS part worked. If only the --insecure call gets a code, the host does not trust the emulator yet. If both get one and your SDK still fails, that SDK reads its own certificate store.
Verification on, then off
curl -sS -o /dev/null -w "%{http_code}\n" https://localhost:8081/
curl --insecure -sS -o /dev/null -w "%{http_code}\n" https://localhost:8081/Trust it in the operating system
The Docker (Linux) emulator publishes its certificate at the path _explorer/emulator.pem. Save it with a .crt name, because update-ca-certificates only picks up PEM files that end in .crt, then copy it into /usr/local/share/ca-certificates and rebuild the bundle.
Ubuntu and Debian: import the certificate
curl --insecure https://localhost:8081/_explorer/emulator.pem > ~/emulatorcert.crt
sudo cp ~/emulatorcert.crt /usr/local/share/ca-certificates/
sudo update-ca-certificatesThe request without --insecure should now print a status code.
Node.js
Node.js ships a fixed list of well-known root authorities and trusts only that list plus the files named in NODE_EXTRA_CA_CERTS. The variable is read once, at start-up, so assigning process.env.NODE_EXTRA_CA_CERTS inside the script changes nothing. Set it in the environment that launches Node.js.
On Node.js 22.19 or 24.6 and newer you can instead set NODE_USE_SYSTEM_CA=1, which makes Node.js use the OS store you just rebuilt.
Two ways to trust the emulator in Node.js
NODE_EXTRA_CA_CERTS=$HOME/emulatorcert.crt node app.js
# Node.js 22.19+ or 24.6+
NODE_USE_SYSTEM_CA=1 node app.jsPython
When the Python SDK still reports an SSL error, the requests library is reading a bundle other than the one you updated. Microsoft's emulator guide shows how to print its path: inside a virtual environment it is typically certifi's cacert.pem under site-packages, and outside one it can be /etc/ssl/certs/ca-certificates.crt.
Find the bundle, then append the certificate after a blank line
python3 -c "from requests.utils import DEFAULT_CA_BUNDLE_PATH; print(DEFAULT_CA_BUNDLE_PATH)"
echo >> /path/to/ca_bundle
cat ~/emulatorcert.crt >> /path/to/ca_bundleIf the path is a system file, run the appends as root and regenerate the bundle afterwards, as the guide says. Run the script again from the same activated environment.
Java and the vNext emulator
The JDK trusts only its own cacerts file. The vNext emulator also starts in plain HTTP mode by default, which the .NET and Java SDKs do not support, so it has to run with --protocol https before Java can connect at all. Pull the certificate out of a handshake and import it into the JDK the app really starts with.
HTTPS mode, then import into cacerts
docker run --detach --publish 8081:8081 --publish 8080:8080 --publish 1234:1234 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-latest --protocol https
openssl s_client -connect localhost:8081 </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/cosmos_emulator.cert
keytool -cacerts -importcert -alias cosmos_emulator -file /tmp/cosmos_emulator.cert
# "alias already exists": keytool -cacerts -delete -alias cosmos_emulator, then import againkeytool may ask for the store password, which is changeit unless someone changed it. With several Java versions installed, import into the one the app starts with, and check with keytool -cacerts -list -alias cosmos_emulator.
Why it breaks again later
Import the certificate again after a data reset, and on every start of a vNext container in HTTPS mode with persisted data, because the emulator then makes a new one. Put the import next to the docker run line in your setup script or CI job so a fresh machine never starts untrusted.
Avoid NODE_TLS_REJECT_UNAUTHORIZED=0 as a shortcut: Node.js documents it as insecure and strongly discouraged, and it tends to leak into shared environments.
In short
- Each runtime has its own trust store: OS, Node.js, Python requests, Java cacerts.
- Download the emulator certificate, then add it to the store the failing program reads.
- Re-import after a reset, and script it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.