openhab-distro
openhab-distro copied to clipboard
Wrong URL Provided in rest/sitemaps/events/subscribe behind a reverse proxy
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
Isn't that Eclipse SmatHome specific instead of a openHab distribution one?
Am 31.03.2017 8:46 nachm. schrieb "Brett Jenkins" <[email protected]
:
Hi,
I've got an issue where a call to /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
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openhab/openhab-distro/issues/442, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMffktEP9NW9StzFprd-0JGmcKTFeuHks5rrUoDgaJpZM4MwBW- .
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.
I agree, it should be a relative path. I can change that.
+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
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> ?
The URL is generated in the basicui. It's not a problem of the rest addon.
Basic UI is just using the URL returned by the subscription request. Basic UI is just concatenating the arguments like sitemap and page id.
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
After applying above workaround, the uis keeps in sync when I toggle switches on my phone and laptop.
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.
If $host isn't the right value in your setup, you could try hardcoding it to the external dns name.
@brosander I use a haproxy and not the nginx here. The host header is correctly set in the request header.
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.
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?
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
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)]
💃
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