0
0
RabbitMQdevops~7 mins

Authentication backends (LDAP, OAuth) in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
RabbitMQ needs to know who can connect and what they can do. Authentication backends like LDAP and OAuth help RabbitMQ check user identities using external systems, making access control easier and more secure.
When you want RabbitMQ to use your company’s existing user directory to manage access.
When you need to allow users to log in using their Google or GitHub accounts.
When you want to centralize user management for multiple applications including RabbitMQ.
When you want to avoid managing separate RabbitMQ user accounts manually.
When you want to improve security by using trusted external authentication services.
Config File - rabbitmq.conf
rabbitmq.conf
auth_backends.1 = rabbit_auth_backend_ldap

# LDAP backend configuration
ldap.servers.1 = ldap.example.com
ldap.user_dn_pattern = cn=${username},ou=users,dc=example,dc=com
ldap.port = 389
ldap.use_ssl = false
ldap.timeout = 5000

# OAuth 2 backend configuration
auth_backends.2 = rabbit_auth_backend_oauth2
oauth2.resource_server_url = https://oauth.example.com/introspect
oauth2.client_id = rabbitmq-client
oauth2.client_secret = secret123
oauth2.token_header = authorization

# Enable both backends
auth_backends = rabbit_auth_backend_ldap,rabbit_auth_backend_oauth2

This configuration file sets RabbitMQ to use two authentication backends: LDAP and OAuth 2.

auth_backends lists the backends RabbitMQ will try in order.

LDAP settings define the LDAP server address, how to find users, and connection details.

OAuth 2 settings specify the OAuth server URL for token introspection and client credentials.

This setup allows RabbitMQ to authenticate users either via LDAP or OAuth tokens.

Commands
Stop the RabbitMQ application to safely apply configuration changes.
Terminal
rabbitmqctl stop_app
Expected OutputExpected
Stopping RabbitMQ application...
Reset RabbitMQ node to clear current state and apply new authentication settings cleanly.
Terminal
rabbitmqctl reset
Expected OutputExpected
Resetting node rabbit@localhost ...
Start the RabbitMQ application again to load the new authentication backends.
Terminal
rabbitmqctl start_app
Expected OutputExpected
Starting RabbitMQ application...
Test authentication for user 'alice' with password 'password123' to verify LDAP backend is working.
Terminal
rabbitmqctl authenticate_user alice password123
Expected OutputExpected
Authenticating user "alice" ... succeeded
Test OAuth token authentication to verify OAuth backend is working (replace with real token).
Terminal
rabbitmqctl authenticate_user oauth_token_example
Expected OutputExpected
Authenticating user "oauth_token_example" ... succeeded
Key Concept

If you remember nothing else from this pattern, remember: RabbitMQ can check user identity using external systems like LDAP or OAuth by configuring authentication backends.

Common Mistakes
Not restarting RabbitMQ after changing authentication backends.
RabbitMQ won't apply new authentication settings until restarted, so changes have no effect.
Always stop and start the RabbitMQ application after modifying authentication configuration.
Misconfiguring LDAP user_dn_pattern or OAuth token introspection URL.
Incorrect settings cause authentication failures because RabbitMQ cannot find users or validate tokens.
Double-check LDAP DN patterns and OAuth URLs with your directory and OAuth provider documentation.
Using only one backend in auth_backends when multiple are configured.
RabbitMQ will try only the listed backends in order; missing one means users from that backend cannot authenticate.
List all desired backends in the auth_backends setting separated by commas.
Summary
Configure RabbitMQ to use LDAP and OAuth authentication backends in rabbitmq.conf.
Restart RabbitMQ application to apply the new authentication settings.
Test user authentication with rabbitmqctl to verify LDAP and OAuth backends work correctly.