Skip to content

Fix OP_MSG auth_source handling#275

Merged
comtihon merged 1 commit into
comtihon:masterfrom
haoxianhan:fix/op-msg-auth-source-regression
Mar 25, 2026
Merged

Fix OP_MSG auth_source handling#275
comtihon merged 1 commit into
comtihon:masterfrom
haoxianhan:fix/op-msg-auth-source-regression

Conversation

@haoxianhan

Copy link
Copy Markdown
Contributor

Summary

Fix OP_MSG authentication when auth_source differs from database.

The auth request already carried the correct database, but the worker sent OP_MSG commands using the connection default database instead. This caused auth failures when auth_source and database were different.

Add regression coverage for both cases and run it in the MongoDB 8 CI job.

Testing

  • rebar3 ct --suite=test/op_msg_auth_source_SUITE.erl

@haoxianhan

Copy link
Copy Markdown
Contributor Author

A minimal repro

docker run -d --name mongo-auth-repro \
  -e MONGO_INITDB_ROOT_USERNAME=admin \
  -e MONGO_INITDB_ROOT_PASSWORD=admin \
  -p 37118:27017 \
  mongo:8.2.5

pre-fix revision (3e9e372):

  mc_worker_api:connect([
    {database, <<"admin">>},
    {auth_source, <<"admin">>},
    {login, <<"admin">>},
    {password, <<"admin">>},
    {host, "localhost"},
    {port, 37118},
    {use_legacy_protocol, false}
  ]).

work fine, returns:

  {ok, Connection}

but changing only the database field to <<"test">>:

  mc_worker_api:connect([
    {database, <<"test">>},
    {auth_source, <<"admin">>},
    {login, <<"admin">>},
    {password, <<"admin">>},
    {host, "localhost"},
    {port, 37118},
    {use_legacy_protocol, false}
  ]).

fails with:

 {'EXIT',
   {<<"Can't pass authentication">>,
    [{mc_auth_logic,scram_sha_1_auth,4,
      [{file,".../mc_auth_logic.erl"},{line,61}]},
     {mc_worker_api,connect,1,
      [{file,".../mc_worker_api.erl"},{line,73}]} ...

With this PR (2694607), database = <<"test">>, auth_source = <<"admin">> returns:

  {ok, Connection}

@comtihon comtihon merged commit 1d93d26 into comtihon:master Mar 25, 2026
14 checks passed
@comtihon

Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants