I’m deploying a MongoDB ReplicaSet using the MongoDB Community Operator v0.13.0 (Helm chart). I want to enforce mutual TLS so that clients must present a valid certificate signed by my CA. Based off MongoDB documentation, setting allowConnectionsWithoutCertificates to false and setting mode to requireTLS should restrict connection to only clients that present valid certificates. But I'm trying to set allowConnectionsWithoutCertificates: false inside the CR, but MongoDB is defaulting to true. My CR looks like this (simplified):
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
name: mongodb
namespace: mongodb
spec:
members: 3
type: ReplicaSet
version: "7.0.7"
security:
tls:
enabled: true
certificateKeySecretRef:
name: mongodb-server-tls
caConfigMapRef:
name: mongodb-ca
additionalMongodConfig:
net:
tls:
mode: requireTLS
allowConnectionsWithoutCertificates: false
I've tried to reinstall MongoDB numerous times with allowConnectionsWithoutCertificates set to false, but it's still defaulting to true. At some point I thought it's a bug in the MongoDB Operator I was using (v0.12.0), so I upgraded to v0.13.0 but still got same error. Here is what I'm getting when I connect to the database and run db.adminCommand({getCmdLineOpts: 1}):
port: 27017,
tls: {
CAFile: '/var/lib/tls/ca/longhash.pem',
allowConnectionsWithoutCertificates: true,
certificateKeyFile: '/var/lib/tls/server/longhash.pem',
mode: 'requireTLS'
}
Operator Information
Kubernetes-mongodb-operator version 0.13.0 Mongodb community version 7.0.7 kubernetes version 1.33.2
certificateKeyFilemust be both, a client and a server certificate or you must create a client certificate and specify it atnet.tls.clusterFile.allowConnectionsWithoutCertificates: truein your config. And I don't fully understand what you mean by "I want to enforce mutual TLS". In general an invalid certificate can be used only to encrypt your connection via TLS/SSL. But it is the server certificate which initiates the TLS/SSL encryption. Thus, a client certificate which is not used for client authentication is actually not used for anything.allowConnectionsWithoutCertificates: truenegates mutual TLS by allowing connection without the need for client and server to provide certificate. With "allowConnectionsWithoutCertificates" being set to true, I only need to add tls=true in the connection URI, and the connection is allowed, if that makes sense.