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

Use IP address as hostname when configured #1181

Merged
merged 3 commits into from
May 13, 2022
Merged

Use IP address as hostname when configured #1181

merged 3 commits into from
May 13, 2022

Conversation

jonatanklosko
Copy link
Member

Closes #1180.

@jonatanklosko
Copy link
Member Author

This isn't perfect, because running locally with Docker the URL will include 0.0.0.0 (which works, but it should be localhost anyway).

@jonatanklosko
Copy link
Member Author

jonatanklosko commented May 9, 2022

One option would be to support LIVEBOOK_HOST and set it to localhost in the Dockerfile. In that case, do we want --host as well? (I'd say it's not necessary)

@josevalim
Copy link
Contributor

@jonatanklosko should we convert 127.0.0.1 and 0.0.0.0 tuples to localhost?

@aseigo
Copy link
Contributor

aseigo commented May 10, 2022

This appears to work for me. Thanks @jonatanklosko !

@josevalim 0.0.0.0 isn't a synonym for localhost, though; it binds to all available IP addresses, including but not limited to localhost. So that might be dangerously misleading, as 0.0.0.0 opens livebook to the network beyond that machine but saying it is on localhost would not communicate that. So, for me, 127.0.0. => localhost makes sense, but perhaps not 0.0.0.0

(I can't comment on the Docker situation.)

@jonatanklosko
Copy link
Member Author

That's what I've been thinking, but actually 0.0.0.0 isn't a valid destination address, so technically http://0.0.0.0:8080 is invalid, browsers just decide to treat it as localhost (ref). When we bind the server to 0.0.0.0, showing localhost URL is actually fine because it's one of the valid addresses for accessing the server. It could be slightly better to show machine hostname or IP, but this wouldn't work for the Docker case. Given that we bind to 0.0.0.0 only via explicit option, I think showing just localhost for access is alright.

@aseigo
Copy link
Contributor

aseigo commented May 10, 2022

Yes, browsers redirect the address to localhost; however, in this case it is configuration for cowboy which causes it to bind to all available IP addresses, not just localhost. 0.0.0.0 is a synonym for INADDR_ANY.

For me this is a salient issue as livebook (by default, at least) exposes the local filesystem to a limited extent, even allowing the creation of local directories, and many devs often equate 0.0.0.0 with localhost (probably because browsers treat it that way on the client side ..)

Perhaps a useful compromise would be to emit a separate line on the console when 0.0.0.0 is provided as the address nothing that Livebook is listening on all available addresses, including potentially externally reachable ones?

@josevalim
Copy link
Contributor

We don't use 0.0.0.0 by default, so I am not worried about it. If someone is passing 0.0.0.0 explicitly, then I hope they know they are doing and the implications of it. So showing 0.0.0.0 on the terminal is fine.

@jonatanklosko
Copy link
Member Author

So showing 0.0.0.0 on the terminal is fine.

@josevalim did you mean localhost?

@josevalim
Copy link
Contributor

I meant 0.0.0.0. So we don't hide it and the browser redirects it anyway.

@jonatanklosko
Copy link
Member Author

I see, so we are back to the Docker question. Inside Docker we use 0.0.0.0, but for the user binding container ports it's actually just localhost, and showing 0.0.0.0 may give a wrong impression that we are exposing too much. So do we want LIVEBOOK_HOST or any other ideas?

@josevalim
Copy link
Contributor

But docker can also bind to a different port, can't it? So we can't assume we know how it is accessed. Maybe we should change the message to say "Livebook listening to address: ..."?

@jonatanklosko
Copy link
Member Author

So we can't assume we know how it is accessed

Ah right, good call!

@jonatanklosko jonatanklosko merged commit 36e48f8 into main May 13, 2022
@jonatanklosko jonatanklosko deleted the jk-ip-url branch May 13, 2022 13:22
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

Successfully merging this pull request may close these issues.

URL on command line when using livebook server --ip is incorrect
3 participants