esl / MongooseIM

MongooseIM is Erlang Solutions' robust, scalable and efficient XMPP server, aimed at large installations. Specifically designed for enterprise purposes, it is fault-tolerant and can utilise the resources of multiple clustered machines.
Other
1.64k stars 422 forks source link

SWAGGER APi's stopped working in 2.0.0 release #1101

Closed vickydhas closed 7 years ago

vickydhas commented 7 years ago

MongooseIM version: 2.0.0 Installed from: GitHub Erlang/OTP version: 18

Describe the issue.

https://github.com/esl/MongooseIM/issues/1055

GET Request send with this URL. Request : http://ec2-111-222-333-444.ap-southeast-1.compute.amazonaws.com:8088/api/users/ec2-111-222-333-444.ap-southeast-1.compute.amazonaws.com

vickydhas commented 7 years ago

I checked this and its working on the local machine IP but not on the AWS IP or ec2.aws...com address.

Double checked that the port 8088, 8089 are open and also the 80,8080 as well.

Previously these settings were working for the AWS IP added instead of localhost/10.211.55.9 , now it have stopped after the mongoose rel folder upgrade.

%% MongooseIM HTTP API it's important to start it on localhost %% or some private interface only (not accessible from the outside) %% At least start it on different port which will be hidden behind firewall

{ {8088, "10.211.55.9"} , ejabberd_cowboy, [ {num_acceptors, 10}, {max_connections, 1024}, {modules, [ {"10.211.55.9", "/api", mongoose_api_admin, []} ]} ]},

Can help me please to check this issue.

vickydhas commented 7 years ago

Hello Team,

Can you please guide over this as this is working only in local machine IP and now on the AWS hosted chat server. I have also tried reinstalling the AWS and configure the security groups for the ports required. this setup worked well in Old Beta 2.0.0 but not the official release.

Any guidance is much appreciated.

michalwski commented 7 years ago

This API is not protected by any authentication at this moment. Because of that it's not safe to enable it on any publicly available interface. If you have f.e a dedicated interface to which only your other services can connect you can use this one. Try to find the IP address of the interface on the machine you run MongooseIM. Usually it's done by ifconfig. Use the IP address for your interface f.e 10.152.1.12.

In the config file you just need to replace "127.0.0.1" with the chosen IP.

vickydhas commented 7 years ago

Hello Michal,

I have tried replacing this as mentioned earlier as well and just to inform this is working properly in the Local IP environment, but as soon as I replace the AWS instance private IP or host ec2.aws.....com address the API doesn't work.

Testing through the REST Chrome client that the response block shows the Cowboy server found but the "Response empty" error is always returned. Even tried this using the curl command but no success over that.

Appreciate if you can give guidance why this is happening in the official 2.0.0 release as this same setup to give the private AWS IP was working absolutely fine in the beta 2.0.0 version.

Thanks for your guidance in advance.

michalwski commented 7 years ago

Are you sure your XMPP host (as set in the ejabberd.cfg) file is: ec2-111-222-333-444.ap-southeast-1.compute.amazonaws.com?

vickydhas commented 7 years ago

Yes the xmpp host that i set in ejabberd cfg file the same IP ec2... was not working in beta as it required proper IP address due to DNS issue given as error in ejabberd logs.

Then the same settings stopped after the upgrade of 2.0.0 was done. The settings worked in for AWS hosted chat in previous beta version.

I have also tried the inbound settings changes, port opening, and reinstall chat server on another instance but same issue.

-- Sent from my iPhone6+

michalwski commented 7 years ago

Is it possible for you to capture the TCP traffic between the client and server? I'd like to see what is exactly returned by MongooseIM.

vickydhas commented 7 years ago

how you want me to do that. I mean what exact way would be comfortable as its AWS instance so not much I can gather.

michalwski commented 7 years ago

You have many options, here are 2 suggested by me:

  1. Use tcpdump tool on the AWS instance and produce output which is compatible with Wireshark
  2. Try run the curl command with option -v. This will enable verbosity, and paste here the whole command and the output.
vickydhas commented 7 years ago

Following is the output I am getting after hitting the curl command.

`Note: Unnecessary use of -X or --request, GET is already inferred.

GET /api/users/ec2-51-251-251-211.ap-southeast-1.compute.amazonaws.com HTTP/1.1

Host: ec2-51-251-251-211.ap-southeast-1.compute.amazonaws.com:8088

User-Agent: curl/7.49.1

Accept: application/json

< HTTP/1.1 404 Not Found

< server: Cowboy

< date: Mon, 12 Dec 2016 14:22:51 GMT

< content-length: 0

<

Dev-MacBook-Pro:~ developer$`

vickydhas commented 7 years ago

I have changed the IP address for confidentiality purpose rest all details are exact as given by curl output.

michalwski commented 7 years ago

From this output I can see that:

  1. Curl connected successfully to your endpoint.
  2. The request was processed by MongooseIM
  3. The response is 404 meaning the PATH (/api/users/ec2-51-251-251-211.ap-southeast-1.compute.amazonaws.com) you provided is not valid. There maybe several reasons. Some of the modules implementing the functionality are not enalbed, the HOST ec2-51-251-251-211.ap-southeast-1.compute.amazonaws.com doesn't match what's in the ejabberd.cfg file.

Could you please share with us your ejabberd.cfg file?

vickydhas commented 7 years ago

Okay as I see the same setup working fine earlier on beta means the second option for mismatch host name may not be issue. As IP like 172.x.x.x worked when placed in cowboy location and host name as ec2.252.c.aws.com.

Since ec2 address was not working when put same at cowboy location where 8088 port is mentioned.

Now left with modules not enabled how can we trace to help get the issue. Which all modules are required for this. Do you want me to deploy old beta rel abc figure out to give more info. -- Sent from my iPhone6+

michalwski commented 7 years ago

Did you have a chance to read carefully this part of the doc: http://mongooseim.readthedocs.io/en/2.0.0/http-api/http-administration-api-documentation/? Required modules are described there.

vickydhas commented 7 years ago

Yes we followed these docs and also all this setup of commands was fine the get users call and post to add new users call was also checked.

In our earlier dscussion where you mentioned us to use usersname instead of user to make API was tested and working.

It's just stopped after new upgrade. -- Sent from my iPhone6+

michalwski commented 7 years ago

Are you sure the module names you have right now in ejabberd.cfg are exactly the same as described in the docs? I remember they changed between beta and final release.

michalwski commented 7 years ago

There is one more thing worth checking in your ejabberd.cfg file:

In the original config there is:

      {modules, [
          {"localhost", "/api", mongoose_api_admin, []}
      ]}

Did you change localhost to your AWS domain? Alternatively you can change it to _ so that works with any host.

      {modules, [
          {"_", "/api", mongoose_api_admin, []}
      ]}
vickydhas commented 7 years ago

Attached my ejabberd cfg file with IP address modified for security.

....ejabberd file shared....

michalwski commented 7 years ago

Thanks! Modules looks correct. What's wrong it the HTTP host. Please change this:

{"171.31.11.111", "/api", mongoose_api_admin, []}

to f.e

{"_", "/api", mongoose_api_admin, []}
vickydhas commented 7 years ago

Hello Michal,

Whats F.e ??? But great thanks this setup worked and i can get the users and commands working.

{ {8088, "171.31.11.111"} , ejabberd_cowboy, [ {num_acceptors, 10}, {maxconnections, 1024}, {modules, [ {"", "/api", mongoose_api_admin, []} ]} ]},

The "_" that you mentioned if I place an IP there will have issues.

vickydhas commented 7 years ago

I am glad you helped :) -- Sent from my iPhone6+

michalwski commented 7 years ago

F.e stands for "For example"

If you had an IP instead of _ you would need to send your HTTP request to the IP and not to the host and the other way around. _ is an wildcard meaning that the HTTP host is irrelevant and the request will be processed anyway.

vickydhas commented 7 years ago

Thanks for info sharing. Great help man :) -- Sent from my iPhone6+