MongoDB X.509 authentication needs a subject-to-user mapping review

MongoDB supports X.509 certificate authentication for clients and for internal authentication between members of replica sets and sharded clusters. The feature is useful when a workload should authenticate with a certificate instead of a shared password. It also moves several familiar identity questions into certificate and directory configuration, where they are easier to miss during a routine database review.

The database does not accept "a valid certificate" as a complete identity by default. A client presents a certificate during TLS, and MongoDB authenticates an external user derived from the certificate subject. That user exists in the $external authentication database. Authorization still comes from roles assigned to that user. If any certificate from the same trusted authority can map to a privileged user, certificate validation has replaced a password without reducing entitlement.

The trust chain is only the first check

The client must trust the server certificate, and the server must trust the authority that issued client certificates. Hostname verification protects the client from connecting to an impostor. Revocation or short certificate lifetimes limit the value of a stolen key. None of those checks proves that the certificate was issued to the correct application identity.

A private certificate authority can issue a certificate for any subject it accepts. If the registration process lets a team choose an arbitrary subject or common name, that team can request the identity of another application. The CA's issuance policy, approval workflow, and subject naming rules are therefore part of the database authorization model.

A certificate's Subject Alternative Name is not a substitute for the subject mapping unless the deployed MongoDB version and driver use it for that purpose. Record the exact subject format and test it with the actual driver. Do not invent a mapping from an email address, Kubernetes service name, or workload label without documentation and a test.

The $external user carries the roles

MongoDB documents X.509 users as users in the $external database. The external identity is authentication context; the roles attached to that user still decide which databases, collections, and actions are available. A certificate for a reporting workload should not receive root or clusterAdmin because the certificate is stored in a managed secret.

Role review should follow the certificate to the workload that owns it. Which process uses the private key? Which team can read it? Which deployment definitions attach the certificate? Which role grants can the workload perform? Does the workload need to write to the database, or only read from a set of collections? Are administrative operations performed by a different identity?

The external user should be inventoried with a human owner and a certificate fingerprint or serial, not only a subject string. If the certificate rotates every 30 days, the identity may remain stable while the key material changes. If the subject changes on every rotation, role assignments can drift or break. Decide which identifier is stable and how the database user is reconciled.

Client and internal authentication are different risks

X.509 is also used between MongoDB members. A member certificate that can authenticate as a client user could have consequences beyond cluster transport. The documentation notes that a client presenting a member certificate can attempt MONGODB-X509 authentication as a user in $external. Separate certificate authorities and subject conventions for members and clients when the deployment supports that separation.

Internal membership credentials should be scoped to cluster services, not made available to application pods or general CI identities. Store member keys on the database nodes and protect them with file permissions and host controls. Audit certificate issuance and renewal, and keep a break-glass process that does not depend on one expired member certificate.

Operational tests

Test a valid client certificate with the expected subject and role. Test a certificate with the correct CA but an unexpected subject. Test an expired certificate, a certificate for the wrong hostname, and a key without the client authentication usage if the deployment expects one. Record the result at the database layer, not only at the TLS terminator.

Review logs for authentication successes and failures without logging keys or full certificate contents. Confirm that the driver sends authSource=$external, uses TLS, and references the intended certificate and CA files. Do not disable certificate verification to solve a hostname mismatch. Fix the service name or certificate instead.

What good looks like

The database team should be able to answer which CA may issue client identities, which subjects map to which $external users, which roles those users have, and which workloads possess the private keys. Certificate issuance, rotation, revocation, and database role changes should have an owner and a test. A workload certificate should expire on a schedule that the workload owner can meet.

X.509 authentication can be stronger than a shared password, particularly when keys stay on the workload and issuance is controlled. It is not a complete authorization design. The certificate proves possession of a key within a trust chain. The database role decides what that key can do.

References