Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

[sandstorm] Mobile and Descktop clients can't connect to Sandstorm RC grain

Open jadeqwang opened this issue 11 years ago • 81 comments

Right now, I can't seem to figure out how to get my local RC client on my Mac to connect to my Sandstorm RC grain. Probably because it isn't possible yet.

@Sing-Li ?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

jadeqwang avatar Nov 07 '15 03:11 jadeqwang

Did you try this?

image

engelgabriel avatar Nov 09 '15 21:11 engelgabriel

Hey @engelgabriel, that gets me to the prompt to enter a host URL, but I'm not sure what to put into the "host URL."

For instance, I tried using a Share link that would ordinarily be able to open that instance in a new browser window, but I get the error "Not a valid instance url." I also try using the webkey (which is how Sandstorm connects to things like mobile apps). Same error.

I think there's some plumbing underneath that needs to get looked at.

jadeqwang avatar Nov 10 '15 03:11 jadeqwang

It checks for a specific http header, to make sure it is a RC server. Maybe Sandstorm is removing this unknown header?

engelgabriel avatar Nov 10 '15 04:11 engelgabriel

We will change from a custom header to a /info rest api

engelgabriel avatar Nov 25 '15 17:11 engelgabriel

relates to https://github.com/RocketChat/Rocket.Chat.Cordova/issues/26

engelgabriel avatar Nov 25 '15 17:11 engelgabriel

So is it currently impossible/infeasible to connect the apps to a RC grain on Sandstorm? Any idea on when this might be doable?

nathanielhourt avatar Jan 13 '16 20:01 nathanielhourt

We just need a fixed URL to connect to, we have already removed the dependency on custom http headers

engelgabriel avatar Jan 13 '16 20:01 engelgabriel

@jparyani - can you please describe the magic involved ? You are the only known human living today who had successfully integrated a mobile app into Sandstorm (quoting @kentonv )

Sing-Li avatar Jan 13 '16 21:01 Sing-Li

By "fixed URL" do you mean a URL that doesn't change, or that something needs to be fixed before it'll work? :)

I've already tried pointing the server to the underlying subdomain SS creates for the grain, but that just hands back Unauthorized errors.

nathanielhourt avatar Jan 13 '16 21:01 nathanielhourt

@nathanhourt The subdomains that Sandstorm creates are ephemeral (they only last as long as your web browser is open to that tab), and as you saw, they check for a cookie that is only given to the client that created that session.

Sandstorm requires api access to go through a webkey (see https://docs.sandstorm.io/en/latest/developing/http-apis/#about-webkeys). Further up on that page, it shows you how to add an offer template to your app, which is our recommended way of displaying to users how to set this up. If you don't add an offer template, users can still generate a webkey manually through the Sandstorm UI by clicking the key icon.

The one thing that Rocket.Chat mobile apps will probably have to change is to handle how authorization with webkeys works. An example webkey is https://alpha-api.sandstorm.io#49Np9sqkYV4g_FpOQk1p0j1yJlvoHrZm9SVhQt7H2-9. The part after the # is a bearer token that needs to be sent as an authorization header. For example, a curl statement accessing the webkey above would look like:

curl -H "Authorization: Bearer 49Np9sqkYV4g_FpOQk1p0j1yJlvoHrZm9SVhQt7H2-9" https://alpha-
api.sandstorm.io

jparyani avatar Jan 13 '16 21:01 jparyani

@jparyani the mobile app doesn't use any APIs, it is just a webview :) We just need access to the webapp itself without the sandstrom "wrapper". Is that possible in any way?

engelgabriel avatar Jan 13 '16 21:01 engelgabriel

In theory your "API" could just serve up regular web content. There are a couple quirks, though.

Sandstorm generally does not want apps hosting web content at a fixed URL for security reasons: Our sandboxing, and our added CSRF defense, depend on randomized per-session hostnames. APIs, however, obviously must have a fixed location, so we have the API endpoint for that. But, since we don't want regular web browsers rendering HTML content from our API endpoint (since it would defeat our sandboxing), we require the Authorization: bearer header (which web browsers never send for a normal browsing context) and we serve the content with headers like Content-Security-Policy and Content-Disposition to try to convince browsers that they absolutely should not render HTML from this endpoint. We also drop all cookies.

Now, if you have a mobile app that is just a webview locked to the rocket.chat server, then arguably it's OK for you to bypass Sandstorm's sandboxing -- or more accurately, it is your app's responsibility to implement any sandbox, not Sandstorm's, because your app is not hosted by Sandstorm. Crucially, though, your app's webview should not be rendering any other sites and should not be sharing a cookie jar with the user's main web browser.

In this scenario, what your app can perhaps do is fetch web content directly from the API endpoint and pass it to the WebView with the following modifications:

  • Add the appropriate Authorization header to all requests, as described above.
  • Strip off the Content-Security-Policy and Content-Disposition headers before passing along to the webview.
  • Do NOT allow the WebView or any nested iframe to browse to any third-party host, unless you are confident you've mitigated the CSRF risks somehow. It's probably better to open the user's regular web browser instead.

Despite the long explanation, I think the above should be easy to implement? I suggest triggering all this specifically when the user enters a webkey as the host -- i.e. a URL that contains a # character as described above.

kentonv avatar Jan 14 '16 00:01 kentonv

Hi ! I'm also interested ! ;)

memento avatar Feb 03 '16 22:02 memento

I propose a hackathon of the Sandtorm and Rocket.Chat teams to get this working :)

engelgabriel avatar Feb 03 '16 22:02 engelgabriel

...and I'm offering the reward cookies ;)

memento avatar Feb 03 '16 22:02 memento

+1 for this!

jonathandey avatar Feb 05 '16 10:02 jonathandey

Is anyone on the Rocket.Chat side working on this? How can we help?

kentonv avatar Feb 16 '16 23:02 kentonv

How can we get the API endpoint? The user is expected to type that URL on the desktop/mobile client login form?

engelgabriel avatar Feb 17 '16 03:02 engelgabriel

Found this:

image

image

engelgabriel avatar Feb 17 '16 04:02 engelgabriel

OK, so:

https://api.oasis.sandstorm.io#R75AxS08WI_MLEks27sn0kyDOGEVqVPjN97KWudxA8H

should result on a request like this:

curl -i https://api.oasis.sandstorm.io -H "Authorization: Bearer R75AxS08WI_MLEks27sn0kyDOGEVqVPjN97KWudxA8H"

that gave me our index html indeed...

engelgabriel avatar Feb 17 '16 04:02 engelgabriel