Skip to content

MongoDB authentication to different DB than used no longer works in spring boot 3.1 #35567

Closed

Description

@bpfoster

After upgrading from Spring Boot 3.0 to 3.1 today, MongoDB authentication via the autoconfiguration is broken.

If you configure both a database to use, and a separate database to authenticate against, the authentication database is ignored, and authentication is attempted against the to-be-used database.

In versions past, and the intended behavior is, that specifying the authentication database allows authenticating as the user to that DB and then switching over to the configured database for normal operations.

Perhaps the PropertiesMongoConnectionDetails should append the authSource option to the connection string if authenticationDatabse is present?

Activity

  1. added this to the 3.1.x milestone on May 19, 2023
  2. modified the milestones: 3.1.x, 3.1.1 on May 31, 2023
  3. ps-tunnelsoft commented on Jun 7, 2023

    @ps-tunnelsoft

    @scottfrederick can you have a look at a similar issue of spring-boot-docker-compose MongoDB autoconfiguration?

    The StringBuilder in class MongoDockerComposeConnectionDetailsFactory is also missing the authSource option. But I am not sure, where to take this value from.

    MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD are used to create a root user by default in admin database and not MONGO_INITDB_DATABASE.

  4. scottfrederick commented on Jun 7, 2023

    @scottfrederick
    Contributor

    @ps-tunnelsoft From reading the documentation for the official MongoDB image, I think you're right.

    MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD
    These variables, used in conjunction, create a new user and set that user's password. This user is created in the admin authentication database

    We might need to set the authentication database to the value admin if the username and password environment variables are configured. Can you create a new issue so we can investigate further?

  5. added a commit that references this issue on Jul 23, 2026
    a02eb48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions