This guide covers a variety of topics related to credentials and passwords used by the internal authentication backend. If a different authentication backend is used, most material in this guide will not be applicable.
RabbitMQ supports multiple authentication mechanisms. Some of them use username/password pairs. These credential pairs are then handed over to authentication backends that perform authentication. One of the backends, known as internal or built-in, uses internal RabbitMQ data store to store user credentials. When a new user is added using rabbitmqctl, the user's password is combined with a salt value and hashed.
RabbitMQ can be configured to use different password hashing functions:
SHA-256 is used by default. More algorithms can be provided by plugins.
It is possible to change what algorithm is used via RabbitMQ configuration file, for example, to use SHA-512:
password_hashing_module = rabbit_password_hashing_sha512
Out of the box, the following hashing modules are provided:
Updated hashing algorithm will be applied to newly created users or when password is changed using rabbitmqctl.
When upgrading from a pre-3.6 version to RabbitMQ 3.6.1 or later, all existing users are marked as using the legacy password hashing function, therefore they will be able to authenticate. No upgrade steps are required.
When importing definitions exported from versions earlier than 3.6.0 into a 3.6.1 or later release, existing user records will use MD5 for password hashing. In order to migrate them to a more secure algorithm, use rabbitmqctl or definition import with an updated hash to update their passwords.
RabbitMQ supports credential validators. The validator only has an effect on the internal authentication backend and kicks in when a new user is added or password of an existing user is changed.
Validators are modules that implement a validation function. To use a validator, it is necessary to specify it and its additional settings in the config file.
There are three credential validators available out of the box:
The following example demonstrates how rabbit_credential_validator_min_password_length is used:
credential_validator.validation_backend = rabbit_credential_validator_min_password_length credential_validator.min_length = 30
The following example demonstrates how rabbit_credential_validator_password_regexp is used:
credential_validator.validation_backend = rabbit_credential_validator_password_regexp credential_validator.regexp = ^[a-bA-Z0-9$]{20,100}
Credential validators have limitations that have to do both with the config file grammar and shell interpretation of certain characters when credentials are specified on the command line.
New style configuration format uses # as the comment character. This means that validation rules cannot use # in regular expression values. Leading and trailing spaces in values will also be stripped by the config file parser.
Also note that when passwords are used with CLI tools commands that manage users, shell escaping of certain characters must be taken into account.
Every credential validator is a module that implements a single function behaviour, rabbit_credential_validator. Plugins therefore can provide more implementations.
Credential validators can also validate usernames or apply any other logic (e.g. make sure that provided username and password are not identical).
Internal authentication backend allows for users without a password or with a blank one (assuming credential validator also allows it). Such users are only meant to be used with passwordless authentication mechanisms such as authentication using x509 certificates.
In order to create a passwordless user, create one with any password that passes validation and clear the password using rabbitmqctl's clear_password command:
rabbitmqctl add_user passwordless-user "pa$$wordless" rabbitmqctl clear_password passwordless-user # don't forget to grant the user virtual host access permissions using set_permissions # ...
Starting with versions 3.6.15 and 3.7.3, authentication attempts that use a blank password will be unconditionally rejected by the internal authentication backend with a distinctive error message in the server log. Connections that authenticate using x509 certificates or use an external service for authentication (e.g. LDAP) can use blank passwords.
It is possible to authenticate connections using x509 certificates and avoid using passwords entirely. The authentication process then will rely on TLS peer certificate chain validation.
To do so:
Sometimes it is necessary to compute a user's password hash for updating via the HTTP API or to generate a definitions file to import.
rabbitmqctl hash_password foobarbaz # Output: # Will hash password foobarbaz # 27cx5+wEi8R8uwTeTr3hk5azuV3yYxxAtwPPhCyrbdsxVhqq
curl -4su guest:guest -X GET localhost:15672/api/auth/hash_password/foobarbaz # Output: # {"ok":"TBybOvomyVw6BqBU/fHCEpVhDO7fLdQ4kxZDUpt6hagCxV8I"}
If you have questions about the contents of this guide or any other topic related to RabbitMQ, don't hesitate to ask them using GitHub Discussions or our community Discord server.
If you'd like to contribute an improvement to the site, its source is available on GitHub. Simply fork the repository and submit a pull request. Thank you!