Unable to reauthenticate via OIDC during Spring MongoTransactionManager transaction

XMLWordPrintableJSON

    • None
    • Java Drivers
    • Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Problem: OIDC authentication will always fail if the driver is prompted to reauthenticate by the server during any read/wirte operation while using a Spring MongoTransactionObject (e.g., when a Spring Boot application is configured with a org.springframework.data.mongodb.MongoTransactionManager bean and a read/write is executed).

      Root cause: The MessageSettings configured for the saslStart CommandMessage during OIDC authentication does not set a value for the sessionSupported property, which will default to false (CommandHelper:111). This, in combination with the fact that a ClientSession is always established by the Spring MongoTransactionManager during a transaction, results in the check on line CommandMessage:283 (during the message encoding process) to always fail, and no authentication during a transaction is ever possible. This presumably applies not only to OIDC authentication, but to any authentication method which uses a SASL handshake.

      Example logs of this occuring in a Spring Boot application are attached.

      Note: I have also tried with the latest versions of the driver and other relevant libraries and the bug is still present

      Connection string: 
      mongodb+srv://23557-fcpfalco-preprod-pl-0.tkyrb.mongodb.net/vehicleprofilepublisher-qa?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:ford-mongodb&retryWrites=true&w=majority

      Driver version: 5.2.1
      Other relevant libraries:
      Spring Boot: 3.4.5
      org.springframework.data:spring-data-mongodb:4.4.5
      org.springframework.boot:spring-boot-starter-data-mongodb:3.4.5

      Motivation

      Who is the affected end user?

      Any user who is using OIDC authentication in conjunction with Spring MongoTransactionManager

      How does this affect the end user?

      Unable to reauthenticate during transactions

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

      Will always occur when reauthentication with the server is required during a transaction

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

      Unable to perform any operation with the server

      Is this issue urgent?

      ASAP

        1. downloaded-logs-20250520-123043.txt
          32 kB
        2. MongoOIDCConfiguration.java
          1 kB
        3. VehicleProfilePublishRepository.java
          0.3 kB

            Assignee:
            Valentin Kavalenka
            Reporter:
            Collin Baldwin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: