#12191 Not able to consume rabbitmq messages through openscanhub user
Closed: Fixed 6 months ago by svashisht. Opened 6 months ago by svashisht.

Describe what you would like us to do:


This is a follow up on https://pagure.io/fedora-infra/ansible/pull-request/2244#request_diff

I am trying to follow examples from the official documentation, but I am getting below exception:

>>> from fedora_messaging import api, config
>>> api.consume(lambda message: print(message))                                                                       
Consuming raised an unexpected error, please report a bug:
Traceback (most recent call last):                                                                                    
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 913, in errback
    self._startRunCallbacks(fail)                                                                                     
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 981, in _startRunCallbacks
    self._runCallbacks()                                                                                              
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1075, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1946, in _gotResultInlineCallbacks 
    _inlineCallbacks(r, gen, status, context)         
--- <exception caught here> ---                       
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1996, in _inlineCallbacks     
    result = context.run(                                                                                             
  File "/usr/lib/python3.12/site-packages/twisted/python/failure.py", line 519, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))                                                                
  File "/usr/lib/python3.12/site-packages/fedora_messaging/api.py", line 166, in _twisted_consume_wrapper
    consumers = yield twisted_consume(callback, bindings=bindings, queues=queues)
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1996, in _inlineCallbacks          
    result = context.run(                             
  File "/usr/lib/python3.12/site-packages/twisted/python/failure.py", line 519, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))                                                                
  File "/usr/lib/python3.12/site-packages/fedora_messaging/twisted/factory.py", line 296, in consume
    queue_name = yield protocol.declare_queue(queue)
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1996, in _inlineCallbacks
    result = context.run(
  File "/usr/lib/python3.12/site-packages/twisted/python/failure.py", line 519, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))                                                                
  File "/usr/lib/python3.12/site-packages/fedora_messaging/twisted/protocol.py", line 322, in declare_queue
    names = yield self.declare_queues([queue])        
  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 1996, in _inlineCallbacks       
    result = context.run(                     
  File "/usr/lib/python3.12/site-packages/twisted/python/failure.py", line 519, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))                                                                
  File "/usr/lib/python3.12/site-packages/fedora_messaging/twisted/protocol.py", line 307, in declare_queues
    raise BadDeclaration("queue", args, e)
fedora_messaging.exceptions.BadDeclaration: Unable to declare the queue object ({'queue': '', 'durable': False, 'auto_delete': True, 'exclusive': True, 'arguments': {}, 'passive': False}) because (403, "ACCESS_REFUSED - access to queue 
'amq.gen-Nb_cDOUeJkUy4W57AqJuqw' in vhost '/pubsub' refused for user 'openscanhub.stg'")

Which means I do not have privilleges to consume messages. What needs to be done to fix this?

When do you need this to be done by? (YYYY/MM/DD)


asap


Metadata Update from @zlopez:
- Issue priority set to: Waiting on Assignee (was: Needs Review)
- Issue tagged with: Needs investigation, low-gain, ops

6 months ago

@abompard Do you know what could be the issue here?

And this is the output from CLI:

sh-5.1$ fedora-messaging --conf /etc/fedora-messaging/fedora-messaging-config.toml consume --callback="fedora_messaging.example:printer"
[fedora_messaging.cli INFO] Starting consumer with fedora_messaging.example:printer callback
[fedora_messaging.twisted.service INFO] Authenticating with server using x509 (certfile: /etc/pki/rabbitmq/cert/fedora-messaging-openscanhub.crt, keyfile: /etc/pki/rabbitmq/key/fedora-messaging-openscanhub.key)
[pika.channel WARNING] Received remote Channel.Close (403): "ACCESS_REFUSED - access to queue 'amq.gen-vNfPYgNcMeAenskPjg60_A' in vhost '/pubsub' refused for user 'openscanhub.stg'" on <Channel number=2 OPEN conn=<pika.adapters.twisted_connection._TwistedConnectionAdapter object at 0x7fd2b520feb0>>
[fedora_messaging.cli ERROR] Unable to declare the queue object on the AMQP broker. The broker responded with (403, "ACCESS_REFUSED - access to queue 'amq.gen-vNfPYgNcMeAenskPjg60_A' in vhost '/pubsub' refused for user 'openscanhub.stg'"). Check permissions for your user.
[fedora_messaging.twisted.protocol INFO] Waiting for 0 consumer(s) to finish processing before halting
[fedora_messaging.twisted.protocol INFO] Finished canceling 0 consumers
[fedora_messaging.twisted.protocol INFO] Disconnect requested, but AMQP connection already gone

If you want to consume messages, you need to declare a queue with the rabbit/queue role. The rabbit/user role is not enough. Then, your queue name must be or start with the name of your user (openscanhub{{env_suffix}}). Other queue names, including autogenerated names (those that start with amq.gen-) are not allowed.

@svashisht Were you able to solve the issue?

@svashisht Were you able to solve the issue?

Yes, I had to declare a queue in the playbook.

Metadata Update from @svashisht:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

6 months ago

Log in to comment on this ticket.

Metadata
Boards 1
ops Status: Backlog