getcanoe / canoed

Daemon for the Canoe Nano wallet, written in Nodejs
https://getcanoe.io
15 stars 7 forks source link

error: Error: Connection refused: Not authorized #6

Open benzntech opened 5 years ago

benzntech commented 5 years ago

Error when initialising the canoed

[error: Error: Connection refused: Not authorized
    at MqttClient._handleConnack (/root/canoed/node_modules/mqtt/lib/client.js:893:15)
    at MqttClient._handlePacket (/root/canoed/node_modules/mqtt/lib/client.js:329:12)
    at work (/root/canoed/node_modules/mqtt/lib/client.js:271:12)
    at Writable.writable._write (/root/canoed/node_modules/mqtt/lib/client.js:281:5)
    at doWrite (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Writable.write (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Socket.ondata (_stream_readable.js:693:20)
    at Socket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12) ](url)

Here is terminal Script

root@acvd:~/canoed# canoed
info: Connected to Postgres
info: Connecting to Redis ...
info: Http server started on port 8180
info: Connected to Redis
error: Error: Connection refused: Not authorized
    at MqttClient._handleConnack (/root/canoed/node_modules/mqtt/lib/client.js:893:15)
    at MqttClient._handlePacket (/root/canoed/node_modules/mqtt/lib/client.js:329:12)
    at work (/root/canoed/node_modules/mqtt/lib/client.js:271:12)
    at Writable.writable._write (/root/canoed/node_modules/mqtt/lib/client.js:281:5)
    at doWrite (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Writable.write (/root/canoed/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Socket.ondata (_stream_readable.js:693:20)
    at Socket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)
info: Calling exit...
info: Cleaning up...
gokr commented 5 years ago

Seems canoed may not be configured with proper user/password to connect o VerneMQ, did you follow the wiki page? https://github.com/getcanoe/canoed/wiki/Setting-up-a-canoed-backend

benzntech commented 5 years ago

Yes Followed the same Wiki to configure. But used different Password in canoed.config

And then wiki say plugins.vmq_passwd = off we use auth via postgres diversity plugin, not passwd.

jfbloom22 commented 5 years ago

I followed the wiki, and ran into the same error.

jfbloom22 commented 5 years ago

More info:

$ ./canoed --initialize
info: Connected to Postgres
debug: Initializing database ...
debug: Creating account: ["canoed","canoed","cando02","[{\"pattern\":\"#\"}]","[{\"pattern\":\"#\"}]"]
debug: Created account: ["canoed","canoed","cando02","[{\"pattern\":\"#\"}]","[{\"pattern\":\"#\"}]"]
debug: Initialization done.
info: Cleaning up...
info: Connected to Redis
error: Error: Connection refused: Not authorized
at MqttClient._handleConnack (/home/canoed/canoed/node_modules/mqtt/lib/client.js:893:15)

vmq_quth_acl table was created properly as best I can tell:

canoe=# SELECT * FROM vmq_auth_acl;
 mountpoint | client_id | username |                           password                           |    publish_acl    |   subscribe_acl   
------------+-----------+----------+--------------------------------------------------------------+-------------------+-------------------
            | canoed    | canoed   | $2a$06$m9xw/VqPl3iPLenl4h2GAeB5wWup3vK2vqhZtGXWMr66KVlR3BBye | [{"pattern":"#"}] | [{"pattern":"#"}]

any suggestions?

jfbloom22 commented 5 years ago

20 nano bounty for helping me figure this out. 💰

More troubleshooting: Ubuntu 18.04.2 LTS The versions for everything else were defined in the wiki or in package.json, but: postgresql-9.6 vernemq_1.3.1-1 "mqtt": "2.17.0"

I dropped the vmc_auth_acl table and created it again manually with hard coded values:

WITH x AS (
    SELECT
        ''::text AS mountpoint,
           'canoed'::text AS client_id,
           'canoed'::text AS username,
           'canoe01'::text AS password,
           gen_salt('bf')::text AS salt,
           '[{"pattern": "a/b/c"}, {"pattern": "c/b/#"}]'::json AS publish_acl,
           '[{"pattern": "a/b/c"}, {"pattern": "c/b/#"}]'::json AS subscribe_acl
    ) 
INSERT INTO vmq_auth_acl (mountpoint, client_id, username, password, publish_acl, subscribe_acl)
    SELECT 
        x.mountpoint,
        x.client_id,
        x.username,
        crypt(x.password, x.salt),
        publish_acl,
        subscribe_acl
    FROM x;

Initialization goes well and I can see the table like before:

 mountpoint | client_id | username |                           password                           |                 publish_acl                  |                subscribe_acl                 
------------+-----------+----------+--------------------------------------------------------------+----------------------------------------------+----------------------------------------------
            | canoed    | canoed   | $2a$06$ix91F9z7EZ0H9MnNp6/Wber3k0vpTF3vz0X4yLrMiSaIamiT7Fr6a | [{"pattern": "a/b/c"}, {"pattern": "c/b/#"}] | [{"pattern": "a/b/c"}, {"pattern": "c/b/#"}]

Then I created my own little test node file with:

var config = {
  mqtt: {
    url: 'tcp://localhost',
    options: {
      clientId: 'canoed',
      username: 'canoed',
      password: 'canoe01'
    },
  }
}

function connectMQTT () {
  winston.info('Connecting to MQTT server...')
  mqttClient = mqtt.connect(config.mqtt.url, config.mqtt.options)
  mqttClient.on('connect', function () {
    winston.info('Connected to MQTT server')
  })
}
connectMQTT();

This gives me the same error as before:

Error: Connection refused: Not authorized
    at MqttClient._handleConnack (/home/canoed/canoed/node_modules/mqtt/lib/client.js:893:15)
    at MqttClient._handlePacket (/home/canoed/canoed/node_modules/mqtt/lib/client.js:329:12)
    at work (/home/canoed/canoed/node_modules/mqtt/lib/client.js:271:12)
    at Writable.writable._write (/home/canoed/canoed/node_modules/mqtt/lib/client.js:281:5)
    at doWrite (/home/canoed/canoed/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/canoed/canoed/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Writable.write (/home/canoed/canoed/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Socket.ondata (_stream_readable.js:639:20)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)

VerneMQ log:

2019-05-01 12:18:02.141 [warning] <0.356.0>@vmq_diversity_worker_wrapper:handle_info:163 Could not connect to postgresql due to invalid_password

Any ideas about what I am doing wrong here?

jfbloom22 commented 5 years ago

AHA! I figured it out. I had mistakenly put in the wrong password into the verneMQ config. I put the password for the postgres user rather than the canoed user. Now the Canoed service is talking to my Nano Node.