Compass won’t establish connection to VPS MongoDB instance. Here is the log:
{"t":{"$date":"2024-12-05T20:38:26.097+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"185.121.228.66:51324","uuid":{"uuid":{"$uuid":"5f86b525-d80e-45ea-b05d-ca1e33028b58"}},"connectionId":52,"connectionCount":1}}
{"t":{"$date":"2024-12-05T20:38:26.111+00:00"},"s":"I", "c":"NETWORK", "id":6723804, "ctx":"conn52","msg":"Ingress TLS handshake complete","attr":{"durationMillis":13}}
{"t":{"$date":"2024-12-05T20:38:26.112+00:00"},"s":"E", "c":"NETWORK", "id":23256, "ctx":"conn52","msg":"SSL peer certificate validation failed","attr":{"error":"SSL peer certificate validation failed: unable to get issuer certificate"}}
{"t":{"$date":"2024-12-05T20:38:26.112+00:00"},"s":"I", "c":"EXECUTOR", "id":22988, "ctx":"conn52","msg":"Error receiving request from client. Ending connection from remote","attr":{"error":{"code":141,"codeName":"SSLHandshakeFailed","errmsg":"SSL peer certificate validation failed: unable to get issuer certificate"},"remote":"185.121.228.66:51324","connectionId":52}}
{"t":{"$date":"2024-12-05T20:38:26.112+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn52","msg":"Connection ended","attr":{"remote":"185.121.228.66:51324","uuid":{"uuid":{"$uuid":"5f86b525-d80e-45ea-b05d-ca1e33028b58"}},"connectionId":52,"connectionCount":0}}
No idea what is causing the problem. The files have the same contents on both ends and readable.
mongo.conf:
net:
port: 27017
# bindIp: 127.0.0.1
bindIpAll: true
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/certAndKey.pem
CAFile: /etc/ssl/chain.pem
Before I tried NGINX on VPS end and Compass was establishing connection fine. Make me think the issue is on MongoDB end.
certAndKey contents:
-----BEGIN CERTIFICATE-----
MIIDkTCCAxigAwIBAgISBFenOkN8BKV0K4KSsaH2eRvgMAoGCCqGSM49BAMDMDIx
CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBF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DVR0g
BAwwCjAIBgZngQwBAgEwJwYDVR0fBCAwHjAcoBqgGIYWaHR0cDovL3gxLmMubGVu
Y3Iub3JnLzANBgkqhkiG9w0BAQsFAAOCAgEAfYt7SiA1sgWGCIpunk46r4AExIRc
MxkKgUhNlrrv1B21hOaXN/5miE+LOTbrcmU/M9yvC6MVY730GNFoL8IhJ8j8vrOL
pMY22OP6baS1k9YMrtDTlwJHoGby04ThTUeBDksS9RiuHvicZqBedQdIF65pZuhp
eDcGBcLiYasQr/EO5gxxtLyTmgsHSOVSBcFOn9lgv7LECPq9i7mfH3mpxgrRKSxH
pOoZ0KXMcB+hHuvlklHntvcI0mMMQ0mhYj6qtMFStkF1RpCG3IPdIwpVCQqu8GV7
s8ubknRzs+3C/Bm19RFOoiPpDkwvyNfvmQ14XkyqqKK5oZ8zhD32kFRQkxa8uZSu
h4aTImFxknu39waBxIRXE4jKxlAmQc4QjFZoq1KmQqQg0J/1JF8RlFvJas1VcjLv
YlvUB2t6npO6oQjB3l+PNf0DpQH7iUx3Wz5AjQCi6L25FjyE06q6BZ/QlmtYdl/8
ZYao4SRqPEs/6cAiF+Qf5zg2UkaWtDphl1LKMuTNLotvsX99HP69V2faNyegodQ0
LyTApr/vT01YPE46vNsDLgK+4cL6TrzC/a4WcmF5SRJ938zrv/duJHLXQIku5v0+
EwOy59Hdm0PT/Er/84dDV0CSjdR/2XuZM3kpysSKLgD1cKiDA+IRguODCxfO9cyY
Ig46v9mFmBvyH04=
-----END CERTIFICATE-----
There is also fullchain.pem file, but not using it. All certs obtained from LetsEncrypt via Certbot.
Any ideas why MongoDB on VPS not liking what Compass is trying to communicate?
3
Answers
To summarize the solution provided by Wernfried Domscheit and put everything in plain English, as this certificate subject us super-ultra-confusing. As Certbot by LetsEncrypt generates you the following files:
Here is what you need to do:
RootCA isn't provided by Certbot! You need download it from LetEncrypt website directly.
https://letsencrypt.org/certificates/][1]
It is ISRG Root X1, the self-signed one. Here is the direct link
[https://letsencrypt.org/certs/isrgrootx1.pem][1]
As for your mongod.cong, the tls part should like something like this:
As for Compass connection, accordingly:
Currently certAndKey.pem contains
and chain.pem contains
The .pem file passed as CAFile should contain just the root certificate, i.e. ISRG Root X1. You will need to obtain that root cert and pass it in CAFile.
Put the intermediate certificate, server certificate, and server private key in the same file and pass it as certificateKeyFile.
Add the root certificate to your CA. The
chain.pem
file should be this:Usually Let’s Encrypt certificates are stored in your local certificate store, thus you can use also tlsUseSystemCA. I think in Compass and mongosh it is even the default.