appbaseio / mirage

:art: GUI for simplifying Elasticsearch Query DSL
http://opensource.appbase.io/mirage
Other
2.21k stars 125 forks source link

Chrome extension doesn't work against local unauthenticated instance #18

Closed tjrobinson closed 7 years ago

tjrobinson commented 7 years ago

I've installed the latest Chrome extension from the Chrome store.

When I connect to http://127.0.0.1:9200 or http://localhost:9200 it fails with:

Authentication Error

It looks like your app name, username, password combination doesn't match.
Check your url and appname and then connect it again.

I've added this to my elasticsearch.yml file and restarted before doing the above:

http.cors.allow-origin: "http://127.0.0.1:9200"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization
http.cors.allow-credentials: true
tjrobinson commented 7 years ago

Looking in the Chrome console I see that:

username: "127.0.0.1", password: "9200"
farhan687 commented 7 years ago

Hey @tjrobinson It looks like CORS error, your allow origin should be like this

http.cors.allow-origin: "*"

Steps: 1) Stop elasticsearch 2) update config Es config:

http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : "X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization"
http.cors.allow-methods: "OPTIONS, HEAD, GET, POST, PUT, DELETE"
http.cors.allow-credentials: true

3) start elasticsearch

4) Open console and try to make a request.

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:9200/_search', true);
xhr.withCredentials = true;
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('test:test'));
xhr.send('{"query":{"match_all":{}}}');

If it's response status is 200 then try with mirage, mirage should work after that. If you are facing any error in request post the error log over here or checkout CORS issue for elasticsearch

tjrobinson commented 7 years ago

I've done that and Mirage is still giving the same error.

Using the Chrome console I get this:

image

I think the problem is that we have no authentiction set up on our ES instances, but Mirage and your script above send credentials?

farhan687 commented 7 years ago

I just confirmed, mirage chrome extension is working fine with local connection. and yes it was my mistake in above steps.

Es config should be:

http.cors.enabled: true
http.cors.allow-origin: "/.*/"
http.cors.allow-credentials: true
http.cors.allow-headers: "Authorization, X-Requested-With, Content-Type, Content-Length"

and still if you see the issue, please provide detail of es version.

tjrobinson commented 7 years ago

Thanks. It's looking better but I'm still getting an error. I'm on Elasticsearch 2.3.4 on Windows 10 (can't upgrade currently as I need to match what we're running in production):

image

farhan687 commented 7 years ago

This is little bit confusing, I cannot see any error message in console log. Still you are getting error on UI this is strange. Can you just try disconnecting and connecting?

and can you also try on gh-pages? appbaseio.github.io/mirage

tjrobinson commented 7 years ago

I've sorted it. I was connecting to the index via the alias not the actual index name. It works if I use the index name. Not sure if that's a bug or just me doing it wrong?

GET /_cat/aliases?v

alias                  index                    filter routing.index routing.search 
empactis_local_bluesky empactis_local_blueskyv5 -      -             -              
tjrobinson commented 7 years ago

I see the same issue (and solution) with the gh-pages version and the plugin too.

farhan687 commented 7 years ago

@tjrobinson yes, so mirage is not creating anything for you. it is just an query explorer.

you can create indexes and view data using dejavu.

tjrobinson commented 7 years ago

The index and the alias exist already. I was expecting to be able to use either the alias or the index name when querying.

farhan687 commented 7 years ago

Okay, I will check it out if we can support alias also for connection.

tjrobinson commented 7 years ago

Great, thanks. Nice tools by the way, good work.

bbugh commented 6 years ago

Anyone else stuck on this, I had to add the options to the elastic config, restart, and then use 127.0.0.1 instead of localhost to be able to connect to my local instance.