Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Channel closed by server: 403 (ACCESS-REFUSED) #407

Closed
JefferyHus opened this issue Mar 12, 2018 · 11 comments
Closed

Error: Channel closed by server: 403 (ACCESS-REFUSED) #407

JefferyHus opened this issue Mar 12, 2018 · 11 comments

Comments

@JefferyHus
Copy link

JefferyHus commented Mar 12, 2018

I am consuming an API and they are using RMQ cloud server now, I asked them many times to check the permission, they always reply by you don't know how to use rmq library, I would love to know if my code has anything to do with this issue:

#!/usr/bin/env node

var amqp = require('amqplib')

amqp.connect('amqp://username:password@host:port/vhost').then(function(conn) {
  return conn.createChannel().then(function(ch) {
    var q = '_1077_';
    var msg = '0';

    var ok = ch.assertQueue(q, {durable: true});

    return ok.then(function(_qok) {
      // NB: `sentToQueue` and `publish` both return a boolean
      // indicating whether it's OK to send again straight away, or
      // (when `false`) that you should wait for the event `'drain'`
      // to fire before writing again. We're just doing the one write,
      // so we'll ignore it.
      ch.sendToQueue(q, Buffer.from(msg));
      console.log(" [x] Sent '%s'", msg);
      return ch.close();
    });
  }).finally(function() { conn.close(); });
}).catch(console.warn);

I debugged the connection and channel object, the connection is opened which means the username and password works fine, but once i try to assertQueue I get the rejection error.

Please correct me if im wrong, I believe this is strongly coming from their end and not the code I use.

@cressie176
Copy link
Collaborator

cressie176 commented Mar 12, 2018

The 403 (ACCESS-REFUSED) could be for a number of reasons. When I test locally using a RabbitMQ 3.6.0 docker container I get the following

Test 1: Incorrect password

Fails on connect with

Handshake terminated by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile."

Test 2: No Configure Permissions

Fails on ch.assertQueue with

Operation failed: QueueDeclare; 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - access to queue 'q' in vhost '/' refused for user 'dummy'"

Test 3: No Write Permissions On Exchange

Fails on sendToQueue with

Error: Channel closed by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - access to exchange 'amq.default' in vhost '/' refused for user 'dummy'"

You can read about RabbitMQ permissions here

If you are seeing the error on assertQueue, my guess would be your user can connect to the vhost but doesn't have the "configure" permission required to declare the queue. Try using ch.checkQueue instead.

It's interesting that your error message isn't more explicit. Maybe you're using a different version of RabbitMQ or theres a server setting which limits the output for security reasons.

@cressie176
Copy link
Collaborator

cressie176 commented Mar 12, 2018

I am consuming an API and they are using RMQ cloud server now, I asked them many times to check the permission, they always reply by you don't know how to use rmq library

When I read stuff like this I can help but get annoyed. It doesn't help you or the company / client you are working for. We can't be experts on everything. There are two approaches I usually take when dealing with a response like this. One is to use a technique called Non Violent Communication. It goes something like...

I understand that you are busy, and probably fed up with dealing with what to you may seem like a basic query, however when you respond without offering any constructive advice I feel frustrated as it simple delays resolving the issue. Would you be willing to arrange a time when we can debug this together over the phone.

With the NVC approach if they respond with a negative, tell them how you feel, but without implying any form of judgement, and request another action that they might take which will resolve your issue (e.g. send me the error logs, pass by your desk, speak to your supervisor to get the issue escalated, etc, etc)

Another approach is called High Ground Manoeuvre, where you make the problem more general, effectively taking the moral high ground.

Thank you for your response, however simply replying that I don't know the rmq library does not help resolve the issue. We all need assistance from time to time, and when we do it's for the benefit of the company that we support each other where possible. Would you be willing to arrange a time when we can debug this together over the phone.

The advantage of the High Ground Maneuver is that any further attempt to belittle you makes the other person look petty and at risk of discipline should you have to escalate.

Good luck.

@JefferyHus
Copy link
Author

I have used PHp, NodeJS and both had same error, I created my own RMQ cloud server and tested the same code, and it worked, I was able to send messages and set an exchange and consume, I show them the logs and all and offered my help, but they refuse, that's what pushes me to be anxious now.
Thanks for your reply, happy (y)
Best wishes :)

@JefferyHus
Copy link
Author

I have used ch.checkQueue it drops a warning with an exception, so I'm sure it's their end which has no permission configuration.

@cressie176
Copy link
Collaborator

What happens if you try to publish without the assertQueue or checkQueue?

@JefferyHus
Copy link
Author

same thing I got 403, I asked them many times to check the permissions, but they just keep telling me that everything is fine. What I think (as their documentation is poor) is that they only wants a connection to be opened then you can consume the API directly, I am testing this right now if it works or no.

@JefferyHus
Copy link
Author

seems like I got it to work but using PHP library, converted same code to NodeJS but getting 403 emmm, I think I need more time to investigate this library and make sure things are fine.

@cressie176
Copy link
Collaborator

That's interesting. I suspect it's your connection string, maybe you have an additional @ character somewhere and the username / password are being incorrectly parsed

@cressie176
Copy link
Collaborator

cressie176 commented Mar 17, 2018

See #269 and #159

@JefferyHus
Copy link
Author

I don't really think so, because when I check the connection object and channel object they both seem to have results, which means my connection has been made correctly, after reading PHP library src code and comparing it to nodejs, it's a bit different , in PHP you send no queue to the channel function nor a channel ID, it's automated. Im still figuring out other things.

@Lightning101
Copy link

Lightning101 commented Jun 20, 2019

image

Set this permission for the user and it was ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants