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

Wrong URL Provided in rest/sitemaps/events/subscribe behind a reverse proxy #442

Open
brettjenkins opened this issue Mar 31, 2017 · 17 comments

Comments

@brettjenkins
Copy link

brettjenkins commented Mar 31, 2017

Hi,

I've got an issue where a call to http://reverseproxy.proxy.com/rest/sitemaps/events/subscribe responds with
{"status":"CREATED","context":{"headers":{"Location":["http://machineip:8080/rest/sitemaps/events/2cd43474-995f-4f14-bb9f-2ff04911fcdb"]},"committingOutputStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false},"entityAnnotations":[],"entityStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false}}}

Which breaks my event streaming. Everything else on the page is working fine however, it's just the response from this URL. Can this be changed to be relative - or alternatively give us the option to override it through a setting?

Thanks

@maggu2810
Copy link
Contributor

maggu2810 commented Apr 1, 2017 via email

@W6HBR
Copy link

W6HBR commented Dec 17, 2017

I have what I believe to be a related problem.

When running behind a reverse proxy, BasicUI page displays and controls all just fine, but the bottom of the page always displays "Offline: waiting for connection to become available".

I'm not familiar with the internals of OpenHAB/Eclipse, but it looks like this is a event messaging issue like the OP.

@lolodomo
Copy link
Contributor

I agree, it should be a relative path. I can change that.

@dhde
Copy link

dhde commented Jan 5, 2018

+1
Same problem for me. Whould be nice if you can change ist to a relative path 👍
The URL seems to be generated in the basicui

@lolodomo
Copy link
Contributor

lolodomo commented Jan 7, 2018

I have a doubt because absolute URLs are used in all the sitemap REST API. Why should it be a relative path only for one particular API ?

@brettyj : can you check using REST documentation UI what URLs you get in the result when using GET /sitemaps and GET /sitemaps/<sitemap_name> ?

@dhde
Copy link

dhde commented Jan 7, 2018

The URL is generated in the basicui. It's not a problem of the rest addon.

@lolodomo
Copy link
Contributor

lolodomo commented Jan 7, 2018

Basic UI is just using the URL returned by the subscription request. Basic UI is just concatenating the arguments like sitemap and page id.

@brosander
Copy link

I've found a workaround as long as you aren't manipulating paths (need to serve openhab from /)

If you set the Host header to the host the client requested, the basic UI will use that as the prefix. [1][2]

e.g. (Nginx)

proxy_set_header Host       $host;

NOTE: The scheme will also have to match for this to construct compatible urls. (If your external service is https, be sure you're talking to openhab internally over https.)

[1] https://github.com/eclipse/smarthome/blob/master/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapResource.java#L116
[2] https://www.ibm.com/support/knowledgecenter/en/SS7JFU_8.5.5/com.ibm.websphere.express.doc/ae/twbs_jaxrs_contextobjects_uri.html

@brosander
Copy link

After applying above workaround, the uis keeps in sync when I toggle switches on my phone and laptop.

@dhde
Copy link

dhde commented Jan 8, 2018

A POST request on https://full-domain/rest/sitemaps/events/subscribe
gives this json:
{"status":"CREATED","context":{"headers":{"Location":["https://10.1.3.2/rest/sitemaps/events/89c1e173-9ab5-44ae-a00f-481962068010"]},"committingOutputStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false},"entityAnnotations":[],"entityStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false}}}

Here the IP 10.1.3.2 is from the running docker container and not from the host with the reverse proxy.

@brosander
Copy link

If $host isn't the right value in your setup, you could try hardcoding it to the external dns name.

@dhde
Copy link

dhde commented Jan 9, 2018

@brosander I use a haproxy and not the nginx here. The host header is correctly set in the request header.

@W6HBR
Copy link

W6HBR commented Jan 9, 2018

I'm using OpenHAB behind an IIS reverse proxy (IIS providing AUTH).

I'm getting the same results as @dhde .

Using my external host name in the request: https://www.MY-DOMAIN.com:444/rest/sitemaps/

I get the OpenHAB ip/port in the return JSON.

[{"name":"home","label":"OmniPro Control","link":"http://192.168.1.25:8080/rest/sitemaps/home","homepage":{"link":"http://192.168.1.25:8080/rest/sitemaps/home/home","leaf":false,"widgets":[]}},{"name":"_default","label":"Home","link":"http://192.168.1.25:8080/rest/sitemaps/_default","homepage":{"link":"http://192.168.1.25:8080/rest/sitemaps/_default/_default","leaf":false,"widgets":[]}}]

I know this can be rewritten in IIS, I just need to figure out how now.

@W6HBR
Copy link

W6HBR commented Jan 9, 2018

Looks like I need to find another solution. Seems that IIS only rewrites the ip/port in the headers and within specified tags (form, frame, img, etc.). It does not appear that you can rewrite ip/port that is embedded in the result data like the returned JSON.

Is there a setting in OpenHAB that lets me set a host name globally?

@dhde
Copy link

dhde commented Jan 17, 2018

it seems a problem in
smarthome/bundles/io/org.eclipse.smarthome.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/SitemapResource.java

the problem must be here:
uriInfo.getBaseUriBuilder().path(PATH_SITEMAPS).path(SEGMENT_EVENTS).path(subscriptionId).build();

same problem with some sugestion here:
https://stackoverflow.com/questions/46227321/jax-rs-injected-uriinfo-returning-localhost-for-rest-requests-in-reverse-proxy

@dhde
Copy link

dhde commented Feb 7, 2018

In the haproxy seems a wrong X-Forwarded-For header is set.
The following fixed it for me:
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
💃

@begleysm
Copy link

If anyone comes here looking to work around this issue and is using an Apache2 Reverse Proxy Server, this Tutorial I found (but did not write) helped me.

https://community.openhab.org/t/apache2-reverse-proxy-with-ldap-authentication-https-and-url-path-prefix/25867

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

7 participants