Skip to content

Add X509 certificate authentication support#268

Open
houst0n wants to merge 1 commit into
comtihon:masterfrom
houst0n:feature/x509-authentication
Open

Add X509 certificate authentication support#268
houst0n wants to merge 1 commit into
comtihon:masterfrom
houst0n:feature/x509-authentication

Conversation

@houst0n

@houst0n houst0n commented Jan 10, 2026

Copy link
Copy Markdown

This commit adds support for MongoDB X509 client certificate authentication:

  • Add x509_auth/2,3 functions to mc_auth_logic.erl for X509 authentication
  • Update mc_worker_api:connect/1 to support {auth_mechanism, 'MONGODB-X509'}
  • Fix mongo_protocol.erl to respect database field from op_msg_command (required for $external database used by X509 auth)
  • Add scripts/setup_mongodb8_x509.sh for setting up MongoDB with X509 auth
  • Add x509_auth_SUITE.erl with tests for:
    • Successful X509 authentication
    • X509 auth with explicit subject
    • Rejection of invalid certificates
    • Database operations with X509 auth
    • Failure when SSL is not enabled
  • Update start_mongo_auth.sh to create testuser in admin database
  • Update rebar3 for Erlang 28 compatibility

Usage example:
{ok, Conn} = mc_worker_api:connect([ {host, "localhost"}, {port, 27022}, {ssl, true}, {ssl_opts, [ {certfile, "/path/to/client.pem"}, {keyfile, "/path/to/client.key"}, {cacertfile, "/path/to/ca.pem"} ]}, {auth_mechanism, 'MONGODB-X509'} ]).

I'm using this for serveral weeks without issues (OTP28/Mongo7+8)

This commit adds support for MongoDB X509 client certificate authentication:

- Add x509_auth/2,3 functions to mc_auth_logic.erl for X509 authentication
- Update mc_worker_api:connect/1 to support {auth_mechanism, 'MONGODB-X509'}
- Fix mongo_protocol.erl to respect database field from op_msg_command
  (required for $external database used by X509 auth)
- Add scripts/setup_mongodb8_x509.sh for setting up MongoDB with X509 auth
- Add x509_auth_SUITE.erl with tests for:
  - Successful X509 authentication
  - X509 auth with explicit subject
  - Rejection of invalid certificates
  - Database operations with X509 auth
  - Failure when SSL is not enabled
- Update start_mongo_auth.sh to create testuser in admin database
- Update rebar3 for Erlang 28 compatibility

Usage example:
  {ok, Conn} = mc_worker_api:connect([
    {host, "localhost"},
    {port, 27022},
    {ssl, true},
    {ssl_opts, [
      {certfile, "/path/to/client.pem"},
      {keyfile, "/path/to/client.key"},
      {cacertfile, "/path/to/ca.pem"}
    ]},
    {auth_mechanism, 'MONGODB-X509'}
  ]).

I'm using this for serveral weeks without issues (OTP28/Mongo7+8)
@houst0n houst0n mentioned this pull request Jan 15, 2026
@comtihon

Copy link
Copy Markdown
Owner

Hi @houst0n thank you very much for your contribution.
Can you please fix the build? Looks like after your change in rebar it started failing.

@comtihon

Copy link
Copy Markdown
Owner

please fix the checks

@samwar

samwar commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@houst0n pinging you again to fix the checks and resolve conflicts

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.

3 participants