ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Unknown
    • None
    • Component/s: Authentication
    • None
    • Not Needed

      Summary

      With MONGODB-OIDC and a custom callback, the driver can fail authentication on a new connection when its cached token has expired:

      1. All pooled connections were closed after sitting idle, so a request opens a new socket.
      2. The driver sends saslStart with the cached token, which has expired. The server rejects it (code 18).
      3. The driver calls our callback and gets a valid fresh token.
      4. The driver sends saslStart again on the same socket, which the server has closed. This fails with EndOfStreamException and then MongoAuthenticationException.

      The error occurs every time this sequence happens. Sometimes the driver fetches a new token before the first saslStart, and then there's no error. We don't know whether the driver ignores the expiry we return (12h, for a 24h token) or the Entra token's expiry is wrong. Either way, the cached token is expired when it's used.

      MongoDB keeps the connection open after a failed saslStart, and the driver's same-connection retry relies on that. Azure Cosmos DB for MongoDB (vCore) closes it.

      Driver: MongoDB.Driver 3.12.0.

      Reproduction: Program.cs talks to the cluster over the wire protocol, without the driver. Each scenario uses a fresh connection.

      Scenario Steps Result Reproduces?
      A Valid saslStart, then valid saslStart again Both ok=1 No (control)
      B Invalid saslStart, then valid saslStart First ok=0; second fails because the server closed the connection (EOF) Yes

      Motivation

      Who is the affected end user?

      Anyone using MONGODB-OIDC with a custom callback (for example Azure managed identity) against a server that closes the connection after a rejected saslStart. We see it on Azure Cosmos DB for MongoDB vCore.

      How does this affect the end user?

      The request that opened the connection fails with an authentication error.

      How likely is it that this problem or use case will occur?

      It's on the main path for long-running services. It happens whenever a new connection is opened after the cached token has expired, for example after an idle period.

      If the problem does occur, what are the consequences and how severe are they?

      A failed request and an error in the logs.

      Is this issue urgent?

      No

      Is this ticket required by a downstream team?

      Don't know

      Is this ticket only for tests?

      No

      Acceptance Criteria

      When a saslStart using a cached OIDC token is rejected and the server closes the connection, authentication still succeeds using the fresh token from the callback, with no error shown to the caller.

        1. Program.cs
          5 kB
          Elon Mallin (EXT)

            Assignee:
            Unassigned
            Reporter:
            Elon Mallin (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: