AccessDeniedError while trying connect to remote RabbitMQ server

771 views
Skip to first unread message

Анна Костромина

unread,
Oct 13, 2017, 8:40:22 AM10/13/17
to rabbitmq-users

I'am trying to connect two hosts with RabbitMQ & python pika.


Here is worker:

#!/usr/bin/env python
import pika, time
NEW_TASK_HOST_IP
= '192.168.0.2'
credentials
= pika.PlainCredentials('login-to-remote', 'pass')
connection
= pika.BlockingConnection(
                    pika
.ConnectionParameters(host=NEW_TASK_HOST_IP))
channel
= connection.channel()

channel
.queue_declare(queue='task_queue', durable=True)
print(' [*] Waiting for messages. To exit press CTRL+C')

def callback(ch, method, properties, body):
    ch
.basic_ack(delivery_tag = method.delivery_tag)

channel
.basic_qos(prefetch_count=1)
channel
.basic_consume(callback,
                      queue
='task_queue')

And here is new task:

#!/usr/bin/env python
import pika, sys
WORKER_IP
= '192.168.0.3'
credentials
= pika.PlainCredentials('login-to-remote', 'pass')
connection
= pika.BlockingConnection(pika.ConnectionParameters(
        host
=WORKER_IP, socket_timeout=300, credentials=credentials))
channel
= connection.channel()

channel
.queue_declare(queue='task_queue', durable=True)

message
= ' '.join(sys.argv[1:]) or "Hello World!"
channel
.basic_publish(exchange='',
                      routing_key
='task_queue',
                      body
=message,
                      properties
=pika.BasicProperties(
                         delivery_mode
= 2, # make message persistent
                     
))
print(" [x] Sent %r" % message)
connection
.close()


I've created two users on both hosts with command:

sudo rabbitmqctl add_user login-to-remote pass

And when i trying to run anything i've got:

Traceback (most recent call last):
 
File "worker.py", line 5, in <module>
    connection
= pika.BlockingConnection(pika.ConnectionParameters(host=NEW_TASK_HOST_IP, socket_timeout=300, credentials=credentials))
 
File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 374, in __init__
   
self._process_io_for_connection_setup()
 
File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 414, in _process_io_for_connection_setup
   
self._open_error_result.is_ready)
 
File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 466, in _flush_output
   
raise maybe_exception
pika
.exceptions.ProbableAccessDeniedError: (-1, "error(104, 'Connection reset by peer')")

I've checked the connection between host with iperf for both udp and tcp in both directions:
iperf -s -p 5672
iperf
-p 5672 -c 192.168.0.2

So the traffic goes.

I'am completely stack, what can be a problem?


Michael Klishin

unread,
Oct 16, 2017, 3:46:26 PM10/16/17
to rabbitm...@googlegroups.com
See server logs. They will likely contain an entry saying that access to vhost "/" is denied for user "".

Creating a user alone is not sufficient. You must grant to permissions in all vhosts it will need to connect to
as well:


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Michael Klishin

unread,
Oct 16, 2017, 3:47:56 PM10/16/17
to rabbitm...@googlegroups.com
Accidentally hit Send too early.

…for user "/".

See https://www.rabbitmq.com/man/rabbitmqctl.1.man.html (the `set_permissions' command).

I will expand the docs at http://www.rabbitmq.com/access-control.html to clarify this.

To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages