Why do I get “no access to this vhost” when trying to start the RabbitMQ?

Shai Ben-Zvi
2021-08-31 06:28

Subject

Why do I see “no access to this vhost” error when trying to start the RabbitMQ?

Description

The RabbitMQ is one of the micro-services which is being used by Xray.
It is holding and managing all the messages of Xray in queues, which includes events, indexing, persists and analyzing messages.

The RabbitMQ queues, user permissions, policies, and connections are being managed by logical group of entities called ‘virtual hosts’.
When the server runs its first startup, it verifies if the database is uninitialized or has been deleted. A fresh database will start with the following resources:

  • A virtual host named / (a slash)

  • The default user has a full access to the / virtual host:
    Username: guest
    Password: guest
     

Additional information can be found in this external documentation page of RabbitMQ.
In case the startup fails, the following error will be displayed on the Xray server logs:

[2019/07/18 12:54:07 EDT] [EROR] (jfrog.com/xray/internal/xqueue/connector.connectToRabbitMQ:183) Error connecting to rabbit message queue check mq settings. Error: Exception (403) Reason: “no access to this vhost”

And on the RabbitMQ log, we will observe the following:

[error] <0.830.0> Error on AMQP connection <0.830.0> (127.0.0.1:54910 -> 127.0.0.1:5672, vhost: 'none', user: 'guest', state: opening), channel 0:
{handshake_error, opening, {amqp_error, internal_error, "access to vhost '/' refused for user 'guest': vhost '/' is down", 'connection.open'}}

Cause:

The error “no access to the vhost” on the RabbitMQ, may happen in case the user which runs the RabbitMQ doesn’t have any permissions configured for the vhost used (“/” by default), or in case RabbitMQ wasn’t shut down correctly (for example in case we ran out of disk space).

This can be tested by executing the following command:

$ curl –user guest:guest http://rabbitmq:15672/api/vhosts

Resolution

Before executing the following steps we recommend to contact JFrog Support, since the following steps may return the RabbitMQ node to its virgin state by removing all data from the management database, such as configured users and vhosts and all the persistent messages.

$ rabbitmqctl stop_app

$ rabbitmqctl reset

$ rabbitmqctl status

$ service rabbitmq-server stop

$ service rabbitmq-server start

$ rabbitmq-plugins enable rabbitmq_management

$ service rabbitmq-server restart

$ curl –user guest:guest http://rabbitmq:15672/api/vhosts